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/
*.log
felix-cache
.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 @@
<packaging>bundle</packaging>
<artifactId>deepamehta</artifactId>
<version>${sally4.version}</version>
<artifactId>deepamehta-base</artifactId>
<parent>
<groupId>info.kwarc.sally4</groupId>
<artifactId>sally4</artifactId>
<version>1.0</version>
<version>0.0.6</version>
<relativePath>..</relativePath>
</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>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo.annotations</artifactId>
<version>1.11.2</version>
<groupId>de.deepamehta</groupId>
<artifactId>deepamehta-core</artifactId>
<!-- <version>4.3</version> -->
<version>4.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
<groupId>info.kwarc.sally4</groupId>
<artifactId>sally4-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>info.kwarc.sally4</groupId>
<artifactId>sally4-utils</artifactId>
<version>${sally4.version}</version>
<artifactId>office-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>info.kwarc.sally4</groupId>
<artifactId>sally4-docmanager</artifactId>
<version>${sally4.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>info.kwarc.sally4.comm</groupId>
<artifactId>comm-annotation</artifactId>
<version>${sally4.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>info.kwarc.sally4</groupId>
<artifactId>sally4-servlet</artifactId>
<version>${sally4.version}</version>
<groupId>info.kwarc.sally4.comm</groupId>
<artifactId>comm-deepa</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- BND Maven Plugin Configuration -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Private-Package>info.kwarc.sally4.deepamehta.impl*</Private-Package>
<Export-Package>info.kwarc.sally4.deepamehta*;libs*</Export-Package>
<Private-Package>${bundle.private-package}</Private-Package>
<Import-Package>${bundle.import-package}</Import-Package>
<Export-Package>${bundle.export-package}</Export-Package>
<Bundle-Activator>${bundle.activator}</Bundle-Activator>
</instructions>
</configuration>
</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>
</build>
</project>
package info.kwarc.sally4.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;
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.Factory;
import org.apache.felix.ipojo.InstanceStateListener;
import org.apache.felix.ipojo.MissingHandlerException;
import org.apache.felix.ipojo.UnacceptableConfiguration;
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.Requires;
import org.apache.felix.ipojo.annotations.Unbind;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Instantiate
public class DeepaMehtaFactory {
@Requires(filter="(factory.name=info.kwarc.sally4.deepamehta.impl.DeepaMehtaInstance)")
@Requires(filter="(factory.name="+DeepaMehtaInstance.factoryid+")")
Factory deepaFactory;
Logger log;
......@@ -31,52 +28,13 @@ public class DeepaMehtaFactory {
log = LoggerFactory.getLogger(getClass());
}
final String[] req = {"select", "theo"};
void addDoc(SallyDoc doc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
if (!doc.supports("deepa")) {
@Bind(aggregate=true)
void addDoc(SallyClient doc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
if (doc.supports("deepa")) {
InstanceCreator.init(deepaFactory).setInstanceName("Deepa "+doc.getDocQueue())
.setDynamicRequirement(DeepaMehta.clientQueue, SallyClient.clientQueue, doc.getDocQueue())
.create();
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;
import info.kwarc.sally.comm.annotation.GetSelectionResponse;
import info.kwarc.sally.comm.annotation.NavigateTo;
import info.kwarc.sally4.core.CamelContextProvider;
import info.kwarc.sally4.deepamehta.Annotator;
import info.kwarc.sally.comm.deepa.CreateNode;
import info.kwarc.sally4.deepamehta.DeepaMehta;
import info.kwarc.sally4.docmanager.IActionAcceptor;
import info.kwarc.sally4.docmanager.SallyDoc;
import info.kwarc.sally4.marshalling.CommUtils;
import info.kwarc.sally4.predicates.BodyHasType;
import info.kwarc.sally4.predicates.XMLMessageNamespace;
import info.kwarc.sally4.processors.TypedCallback;
import info.kwarc.sally4.docmanager.SallyMenuItem;
import info.kwarc.sally4.officebase.DocumentAnnotator;
import info.kwarc.sally4.registration.SallyClient;
import info.kwarc.sally4.util.AsyncAcceptor;
import info.kwarc.sally4.util.EventHandler;
import info.kwarc.sally4.util.EventListenerList;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.DataFormat;
import java.util.List;
import org.apache.felix.ipojo.annotations.Bind;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Invalidate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Unbind;
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)
public class DeepaMehtaInstance extends RouteBuilder implements DeepaMehta, TypedCallback<IActionAcceptor>{
@Requires(id="docQueue", filter="(filterThatWillNeverSucceed=1)")
SallyDoc deepaRoute;
public class DeepaMehtaInstance implements DeepaMehta {
final public static String factoryid = "info.kwarc.sally4.deepamehta.impl.DeepaMehtaInstance";
@Requires
Annotator [] annotators;
Logger log;
EventListenerList events = new EventListenerList();
@Requires(id=DeepaMehta.clientQueue, filter="(filterThatWillNeverSucceed=1)")
SallyClient deepaRoute;
@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
void doStart() throws Exception {
log.info(">>>>Starting DeepaInstance");
deepaRoute.addMessageHandler(this);
context = new DefaultCamelContext();
context.addComponent("activemq", camelContextProvider.getComponent("activemq"));
context.addComponent("alex", deepaRoute.getAlexComponent());
context.addRoutes(this);
context.start();
events.addEventHandler(deepaRoute.addMessageHandler(NavigateTo.class, navigateTo));
}
@Invalidate
void doStop() throws Exception {
context.stop();
events.suspendAll();
}
public DeepaMehtaInstance() {
}
@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();
}
@Bind(aggregate=true, optional=true)
void bindAnnotator(final DocumentAnnotator annotator) {
public void doProcess(NavigateTo navRequest) {
for (Annotator a : annotators) {
a.navigateTo(navRequest.getId());
}
events.addEventHandler(annotator.getSelectionCallbacks(new EventHandler<AsyncAcceptor<GetSelectionResponse,SallyMenuItem>>() {
@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
public boolean run(IActionAcceptor obj) {
log.info("Deepa Received Message");
getContext().createProducerTemplate().send("direct:getMessage", obj.cloneExchange());
return true;
@Unbind(aggregate=true, optional=true)
void unbindAnnotator(DocumentAnnotator annotator) {
}
}
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);
if (ts.size()==0)
return;
Topic t = dms.getTopic(ts.get(0).getId()-1, true);
for (RelatedTopic topic : t.getRelatedTopics(defAssociation, 100).getItems()) {
log.info(""+topic);
if (topic.getTypeUri().equals("dm4.webbrowser.web_resource")) {
final String webaddress = topic.getSimpleValue().toString();
evtData.doAccept(new SallyMenuItem("DeepaMehta", "Show definition ") {
@Override
public void run() {
annotator.getTheo().openNewWindow(webaddress, "Definition Lookup", null, null, 500, 500);
}
});
}
}
}
}));
}
}
{
"assoc_types":[
{
"value": "Definition",
"uri": "info.kwarc.sally4.generic.definition",
"data_type_uri": "dm4.core.text"
}
],
"topic_types": [
{
"value": "Title",
"uri": "info.kwarc.sally4.generic.title",
"data_type_uri": "dm4.core.text",
"index_mode_uris": [
"dm4.core.fulltext"
]
},
{
"value": "UUID",
"uri": "info.kwarc.sally4.generic.uuid",
"data_type_uri": "dm4.core.text",
"index_mode_uris": [
"dm4.core.fulltext"
]
},
{
"value": "Doc Annotation",
"uri": "info.kwarc.sally4.annotation.instance",
"data_type_uri": "dm4.core.composite",
"assoc_defs": [
{
"child_type_uri": "info.kwarc.sally4.generic.title",
"child_cardinality_uri": "dm4.core.one",
"assoc_type_uri": "dm4.core.composition_def"
},
{
"child_type_uri": "info.kwarc.sally4.generic.uuid",
"child_cardinality_uri": "dm4.core.one",
"assoc_type_uri": "dm4.core.composition_def"
}
],
"view_config_topics": [
{
"type_uri": "dm4.webclient.view_config",
"composite": {
"dm4.webclient.icon": "/de.deepamehta.notes/images/yellow-ball.png",
"dm4.webclient.show_in_create_menu": true
}
}
]
}
]
}
\ No newline at end of file