Commit aa9f7ea0 authored by Constantin Jucovschi's avatar Constantin Jucovschi
Browse files

version 0.0.6

parent 30d97973
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
...@@ -4,3 +4,5 @@ bin/ ...@@ -4,3 +4,5 @@ bin/
*.log *.log
felix-cache felix-cache
.metadata .metadata
*.versionsBackup
.settings
\ No newline at end of file
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
...@@ -17,91 +17,80 @@ ...@@ -17,91 +17,80 @@
<packaging>bundle</packaging> <packaging>bundle</packaging>
<artifactId>deepamehta</artifactId> <artifactId>deepamehta-base</artifactId>
<version>${sally4.version}</version>
<parent> <parent>
<groupId>info.kwarc.sally4</groupId> <groupId>info.kwarc.sally4</groupId>
<artifactId>sally4</artifactId> <artifactId>sally4</artifactId>
<version>1.0</version> <version>0.0.6</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<properties>
<bundle.private-package>info.kwarc.sally4.deepamehta.impl*</bundle.private-package>
<bundle.export-package>info.kwarc.sally4.deepamehta*;libs*</bundle.export-package>
<bundle.activator>info.kwarc.sally4.deepamehta.DeepaPlugin</bundle.activator>
</properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.1</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.felix</groupId> <groupId>de.deepamehta</groupId>
<artifactId>org.apache.felix.ipojo.annotations</artifactId> <artifactId>deepamehta-core</artifactId>
<version>1.11.2</version> <!-- <version>4.3</version> -->
<version>4.4-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.camel</groupId> <groupId>info.kwarc.sally4</groupId>
<artifactId>camel-core</artifactId> <artifactId>sally4-utils</artifactId>
<version>${camel.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>info.kwarc.sally4</groupId> <groupId>info.kwarc.sally4</groupId>
<artifactId>sally4-utils</artifactId> <artifactId>office-base</artifactId>
<version>${sally4.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>info.kwarc.sally4</groupId> <groupId>info.kwarc.sally4</groupId>
<artifactId>sally4-docmanager</artifactId> <artifactId>sally4-docmanager</artifactId>
<version>${sally4.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>info.kwarc.sally4.comm</groupId> <groupId>info.kwarc.sally4.comm</groupId>
<artifactId>comm-annotation</artifactId> <artifactId>comm-annotation</artifactId>
<version>${sally4.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>info.kwarc.sally4</groupId> <groupId>info.kwarc.sally4.comm</groupId>
<artifactId>sally4-servlet</artifactId> <artifactId>comm-deepa</artifactId>
<version>${sally4.version}</version> <version>${project.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<!-- BND Maven Plugin Configuration -->
<plugin> <plugin>
<groupId>org.apache.felix</groupId> <groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId> <artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions> <extensions>true</extensions>
<configuration> <configuration>
<instructions> <instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Private-Package>info.kwarc.sally4.deepamehta.impl*</Private-Package> <Private-Package>${bundle.private-package}</Private-Package>
<Export-Package>info.kwarc.sally4.deepamehta*;libs*</Export-Package> <Import-Package>${bundle.import-package}</Import-Package>
<Export-Package>${bundle.export-package}</Export-Package>
<Bundle-Activator>${bundle.activator}</Bundle-Activator>
</instructions> </instructions>
</configuration> </configuration>
</plugin> </plugin>
<!-- iPOJO Maven Plugin Configuration : nothing to do -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-ipojo-plugin</artifactId>
<version>1.11.2</version>
<executions>
<execution>
<goals>
<goal>ipojo-bundle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>
package info.kwarc.sally4.deepamehta; package info.kwarc.sally4.deepamehta;
public interface DeepaMehta { public interface DeepaMehta {
final public static String clientQueue= "clientQueue";
} }
package info.kwarc.sally4.deepamehta;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.deepamehta.core.osgi.PluginActivator;
@Component
@Instantiate
public class DeepaPlugin extends PluginActivator {
Logger log;
public DeepaPlugin() {
log = LoggerFactory.getLogger(getClass());
}
}
package info.kwarc.sally4.deepamehta.factories; package info.kwarc.sally4.deepamehta.factories;
import info.kwarc.sally4.docmanager.SallyDoc; import info.kwarc.sally4.deepamehta.DeepaMehta;
import info.kwarc.sally4.deepamehta.impl.DeepaMehtaInstance;
import info.kwarc.sally4.registration.SallyClient;
import info.kwarc.sally4.util.InstanceCreator;
import java.util.Dictionary;
import java.util.Hashtable;
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.ConfigurationException; import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.Factory; import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.InstanceStateListener;
import org.apache.felix.ipojo.MissingHandlerException; import org.apache.felix.ipojo.MissingHandlerException;
import org.apache.felix.ipojo.UnacceptableConfiguration; import org.apache.felix.ipojo.UnacceptableConfiguration;
import org.apache.felix.ipojo.annotations.Bind; import org.apache.felix.ipojo.annotations.Bind;
import org.apache.felix.ipojo.annotations.Component; import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate; import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Requires; import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Unbind;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@Component @Component
@Instantiate @Instantiate
public class DeepaMehtaFactory { public class DeepaMehtaFactory {
@Requires(filter="(factory.name=info.kwarc.sally4.deepamehta.impl.DeepaMehtaInstance)") @Requires(filter="(factory.name="+DeepaMehtaInstance.factoryid+")")
Factory deepaFactory; Factory deepaFactory;
Logger log; Logger log;
...@@ -31,52 +28,13 @@ public class DeepaMehtaFactory { ...@@ -31,52 +28,13 @@ public class DeepaMehtaFactory {
log = LoggerFactory.getLogger(getClass()); log = LoggerFactory.getLogger(getClass());
} }
final String[] req = {"select", "theo"}; @Bind(aggregate=true)
void addDoc(SallyClient doc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
void addDoc(SallyDoc doc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException { if (doc.supports("deepa")) {
if (!doc.supports("deepa")) { InstanceCreator.init(deepaFactory).setInstanceName("Deepa "+doc.getDocQueue())
.setDynamicRequirement(DeepaMehta.clientQueue, SallyClient.clientQueue, doc.getDocQueue())
.create();
return; return;
} }
createInstance(deepaFactory, "Deepa ", doc.getDocQueue());
}
void createInstance(Factory factory, String name, String docQueue) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
Dictionary<String, Object> configuration = new Hashtable<String, Object>();
Dictionary<String, Object> filters = new Hashtable<String, Object>();
filters.put("docQueue", "(docQueue="+docQueue+")");
configuration.put("requires.filters", filters);
configuration.put("instance.name", name+" for doc:"+docQueue);
ComponentInstance inst = factory.createComponentInstance(configuration);
inst.addInstanceStateListener(new InstanceStateListener() {
@Override
public void stateChanged(ComponentInstance arg0, int arg1) {
if (arg1 == ComponentInstance.INVALID) {
arg0.dispose();
}
}
});
}
public static <T> boolean contains( final T[] array, final T v ) {
for ( final T e : array )
if ( e == v || v != null && v.equals( e ) )
return true;
return false;
}
@Bind(aggregate=true)
void newSallyDoc(SallyDoc newDoc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
addDoc(newDoc);
}
@Unbind(aggregate=true)
void removeSallyDoc(SallyDoc newDoc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
//removeDoc(newDoc);
} }
} }
package info.kwarc.sally4.deepamehta.impl; package info.kwarc.sally4.deepamehta.impl;
import info.kwarc.sally.comm.annotation.GetSelectionResponse;
import info.kwarc.sally.comm.annotation.NavigateTo; import info.kwarc.sally.comm.annotation.NavigateTo;
import info.kwarc.sally4.core.CamelContextProvider; import info.kwarc.sally.comm.deepa.CreateNode;
import info.kwarc.sally4.deepamehta.Annotator;
import info.kwarc.sally4.deepamehta.DeepaMehta; import info.kwarc.sally4.deepamehta.DeepaMehta;
import info.kwarc.sally4.docmanager.IActionAcceptor; import info.kwarc.sally4.docmanager.IActionAcceptor;
import info.kwarc.sally4.docmanager.SallyDoc; import info.kwarc.sally4.docmanager.SallyMenuItem;
import info.kwarc.sally4.marshalling.CommUtils; import info.kwarc.sally4.officebase.DocumentAnnotator;
import info.kwarc.sally4.predicates.BodyHasType; import info.kwarc.sally4.registration.SallyClient;
import info.kwarc.sally4.predicates.XMLMessageNamespace; import info.kwarc.sally4.util.AsyncAcceptor;
import info.kwarc.sally4.processors.TypedCallback; import info.kwarc.sally4.util.EventHandler;
import info.kwarc.sally4.util.EventListenerList;
import org.apache.camel.CamelContext; import java.util.List;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext; import org.apache.felix.ipojo.annotations.Bind;
import org.apache.camel.spi.DataFormat;
import org.apache.felix.ipojo.annotations.Component; import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Invalidate; import org.apache.felix.ipojo.annotations.Invalidate;
import org.apache.felix.ipojo.annotations.Provides; import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires; import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Unbind;
import org.apache.felix.ipojo.annotations.Validate; import org.apache.felix.ipojo.annotations.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.deepamehta.core.Topic;
import de.deepamehta.core.service.DeepaMehtaService;
@Component @Component(name=DeepaMehtaInstance .factoryid)
@Provides(specifications=DeepaMehta.class) @Provides(specifications=DeepaMehta.class)
public class DeepaMehtaInstance extends RouteBuilder implements DeepaMehta, TypedCallback<IActionAcceptor>{ public class DeepaMehtaInstance implements DeepaMehta {
final public static String factoryid = "info.kwarc.sally4.deepamehta.impl.DeepaMehtaInstance";
@Requires(id="docQueue", filter="(filterThatWillNeverSucceed=1)")
SallyDoc deepaRoute;
@Requires Logger log;
Annotator [] annotators;
EventListenerList events = new EventListenerList();
@Requires(id=DeepaMehta.clientQueue, filter="(filterThatWillNeverSucceed=1)")
SallyClient deepaRoute;
@Requires @Requires
CamelContextProvider camelContextProvider; DeepaMehtaService dms;
public DeepaMehtaInstance() {
log = LoggerFactory.getLogger(getClass());
}
EventHandler<IActionAcceptor<NavigateTo>> navigateTo = new EventHandler<IActionAcceptor<NavigateTo>>() {
@Override
public void run(IActionAcceptor<NavigateTo> evtData) {
}
};
String uuidProperty = "info.kwarc.sally4.generic.uuid";
CamelContext context;
@Validate @Validate
void doStart() throws Exception { void doStart() throws Exception {
log.info(">>>>Starting DeepaInstance"); events.addEventHandler(deepaRoute.addMessageHandler(NavigateTo.class, navigateTo));
deepaRoute.addMessageHandler(this);
context = new DefaultCamelContext();
context.addComponent("activemq", camelContextProvider.getComponent("activemq"));
context.addComponent("alex", deepaRoute.getAlexComponent());
context.addRoutes(this);
context.start();
} }
@Invalidate @Invalidate
void doStop() throws Exception { void doStop() throws Exception {
context.stop(); events.suspendAll();
} }
public DeepaMehtaInstance() { @Bind(aggregate=true, optional=true)
} void bindAnnotator(final DocumentAnnotator annotator) {
@Override
public void configure() throws Exception {
DataFormat annotation = CommUtils.getDataFormat("annotation", getClass().getClassLoader());
from("direct:getMessage")
.to("log:DeepaMehtaInstance")
.choice()
.when(new XMLMessageNamespace("annotation"))
.unmarshal(annotation)
.choice()
.when(new BodyHasType(NavigateTo.class))
.bean(method(this, "doProcess"))
.otherwise()
.stop()
.endChoice();
}
public void doProcess(NavigateTo navRequest) { events.addEventHandler(annotator.getSelectionCallbacks(new EventHandler<AsyncAcceptor<GetSelectionResponse,SallyMenuItem>>() {
for (Annotator a : annotators) {
a.navigateTo(navRequest.getId()); @Override
} public void run(final AsyncAcceptor<GetSelectionResponse, SallyMenuItem> evtData) {
log.info("Got selection response");
final String id = evtData.getEventData().getId().get(0);
final List<Topic> ts = dms.searchTopics(id, null);
final SallyClient droute = deepaRoute;
if (ts.size()==0) {
evtData.doAccept(new SallyMenuItem("DeepaMehta", "Create a new node") {
@Override
public void run() {
CreateNode newNode = new CreateNode();
newNode.setId(id);
newNode.setTitle("");
newNode.setType("info.kwarc.sally4.annotation.instance");
droute.sendEvent(newNode);
annotator.persist(id);
}
});
} else {
evtData.doAccept(new SallyMenuItem("DeepaMehta", "Navigate to this node") {
@Override
public void run() {
info.kwarc.sally.comm.deepa.NavigateTo deepaNavigate = new info.kwarc.sally.comm.deepa.NavigateTo();
String id =Long.toString(ts.get(0).getId() - 1);
deepaNavigate.setId(id);
droute.sendEvent(deepaNavigate);
}
});
}
}
}));
} }
@Override @Unbind(aggregate=true, optional=true)
public boolean run(IActionAcceptor obj) { void unbindAnnotator(DocumentAnnotator annotator) {
log.info("Deepa Received Message");
getContext().createProducerTemplate().send("direct:getMessage", obj.cloneExchange());
return true;
} }
} }
package info.kwarc.sally4.deepamehta.impl;
import info.kwarc.sally.comm.annotation.GetSelectionResponse;
import info.kwarc.sally4.docmanager.SallyMenuItem;
import info.kwarc.sally4.officebase.DocumentAnnotator;
import info.kwarc.sally4.util.AsyncAcceptor;
import info.kwarc.sally4.util.EventHandler;
import info.kwarc.sally4.util.EventListenerList;
import java.util.List;
import org.apache.felix.ipojo.annotations.Bind;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Invalidate;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.deepamehta.core.RelatedTopic;
import de.deepamehta.core.Topic;
import de.deepamehta.core.service.DeepaMehtaService;
@Component
@Instantiate
public class DefinitionLookup {
EventListenerList events = new EventListenerList();
@Requires
DeepaMehtaService dms;
final String defAssociation = "info.kwarc.sally4.generic.definition";
Logger log;
public DefinitionLookup() {
log = LoggerFactory.getLogger(getClass());
}
@Validate
void start() {
}
@Invalidate
void stop() {
events.suspendAll();
}
@Bind(aggregate=true, optional=true)
void bindAnnotator(final DocumentAnnotator annotator) {
events.addEventHandler(annotator.getSelectionCallbacks(new EventHandler<AsyncAcceptor<GetSelectionResponse,SallyMenuItem>>() {
@Override
public void run(
AsyncAcceptor<GetSelectionResponse, SallyMenuItem> evtData) {
final String id = evtData.getEventData().getId().get(0);
final List<Topic> ts = dms.searchTopics(id, null);