You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by to...@apache.org on 2012/12/30 16:46:40 UTC
svn commit: r1426954 - in /incubator/clerezza/trunk/uima:
uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/
uima.metadata-generator/src/main/java/org/apache/clerezza/uima/metadatagenerator/
uima.metadata-generator/src/test/java/org/a...
Author: tommaso
Date: Sun Dec 30 15:46:40 2012
New Revision: 1426954
URL: http://svn.apache.org/viewvc?rev=1426954&view=rev
Log:
[CLEREZZA-695] - extracting services and components as needed (removing static calls)
Added:
incubator/clerezza/trunk/uima/uima.samples/src/main/java/org/apache/clerezza/uima/samples/services/OpenNLPService.java (with props)
incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/InMemoryUIMAExecutor.java
- copied, changed from r1426328, incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java
incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/CachingUIMAResourcesClassLoaderRepository.java
- copied, changed from r1426328, incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/UIMAResourcesClassLoaderRepository.java
incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/UIMAClassLoaderRepository.java (with props)
incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/InMemoryUIMAExecutorTest.java (contents, props changed)
- copied, changed from r1426328, incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAExecutorTest.java
Removed:
incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java
incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutorFactory.java
incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/UIMAResourcesClassLoaderRepository.java
incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAExecutorTest.java
Modified:
incubator/clerezza/trunk/uima/uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMARemoteResourceTaggerService.java
incubator/clerezza/trunk/uima/uima.metadata-generator/src/main/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGenerator.java
incubator/clerezza/trunk/uima/uima.metadata-generator/src/test/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGeneratorTest.java
incubator/clerezza/trunk/uima/uima.samples/pom.xml
incubator/clerezza/trunk/uima/uima.samples/src/main/java/org/apache/clerezza/uima/samples/services/OpenNLPNERAOService.java
incubator/clerezza/trunk/uima/uima.samples/src/test/java/org/apache/clerezza/uima/samples/services/OpenNLPNERAOServiceTest.java
incubator/clerezza/trunk/uima/uima.utils/pom.xml
incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/AEProvider.java
incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/ExternalServicesFacade.java
incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMABundleActivator.java
incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/AEProviderTest.java
Modified: incubator/clerezza/trunk/uima/uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMARemoteResourceTaggerService.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMARemoteResourceTaggerService.java?rev=1426954&r1=1426953&r2=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMARemoteResourceTaggerService.java (original)
+++ incubator/clerezza/trunk/uima/uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMARemoteResourceTaggerService.java Sun Dec 30 15:46:40 2012
@@ -21,10 +21,10 @@ package org.apache.clerezza.uima.concept
import org.apache.clerezza.rdf.core.Graph;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.access.TcManager;
-import org.apache.clerezza.uima.utils.UIMAExecutor;
-import org.apache.clerezza.uima.utils.UIMAExecutorFactory;
+import org.apache.clerezza.uima.utils.InMemoryUIMAExecutor;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.uima.util.XMLInputSource;
@@ -47,6 +47,9 @@ public class UIMARemoteResourceTaggerSer
private static final String OUTPUTGRAPH = "outputgraph";
private static final String ALCHEMYKEY = "alchemykey";
+ @Reference
+ private InMemoryUIMAExecutor executor;
+
@GET
@Path("tag")
@Produces("application/rdf+xml")
@@ -55,7 +58,6 @@ public class UIMARemoteResourceTaggerSer
throw new WebApplicationException(Response.status(
Response.Status.BAD_REQUEST).entity(new StringBuilder("No URI specified").toString()).build());
- UIMAExecutor executor = UIMAExecutorFactory.getInstance().createUIMAExecutor();
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put(OUTPUTGRAPH, uri);
parameters.put(ALCHEMYKEY, key);
Modified: incubator/clerezza/trunk/uima/uima.metadata-generator/src/main/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGenerator.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.metadata-generator/src/main/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGenerator.java?rev=1426954&r1=1426953&r2=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.metadata-generator/src/main/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGenerator.java (original)
+++ incubator/clerezza/trunk/uima/uima.metadata-generator/src/main/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGenerator.java Sun Dec 30 15:46:40 2012
@@ -34,7 +34,10 @@ import org.apache.clerezza.uima.metadata
import org.apache.clerezza.uima.utils.ExternalServicesFacade;
import org.apache.clerezza.uima.utils.UIMAServicesFacade;
import org.apache.clerezza.uima.utils.UIMAUtils;
+import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.uima.UIMAException;
import org.apache.uima.cas.FeatureStructure;
@@ -51,18 +54,19 @@ public class UIMABaseMetadataGenerator i
private final static Logger log = LoggerFactory.getLogger(UIMABaseMetadataGenerator.class);
+ @Reference
private UIMAServicesFacade facade;
private Set<MediaTypeTextExtractor> textExtractors;
- public UIMABaseMetadataGenerator() {
- this.facade = new ExternalServicesFacade();
- this.textExtractors = new HashSet<MediaTypeTextExtractor>();
+ @Activate
+ protected void activte() throws Exception {
+ initializeExtractors();
}
- public UIMABaseMetadataGenerator(ExternalServicesFacade facade) {
- this.facade = facade;
- this.textExtractors = new TreeSet<MediaTypeTextExtractor>();
+ @Deactivate
+ protected void deactivte() throws Exception {
+ textExtractors = null;
}
public void generate(GraphNode node, byte[] data, MediaType mediaType) {
@@ -93,7 +97,8 @@ public class UIMABaseMetadataGenerator i
/* initialize text extractors sorted set */
private void initializeExtractors() {
- this.textExtractors.add(new PlainTextExtractor());
+ textExtractors = new HashSet<MediaTypeTextExtractor>();
+ textExtractors.add(new PlainTextExtractor());
}
private String getTextToAnalyze(byte[] data, MediaType mediaType) throws UnsupportedMediaTypeException {
Modified: incubator/clerezza/trunk/uima/uima.metadata-generator/src/test/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGeneratorTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.metadata-generator/src/test/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGeneratorTest.java?rev=1426954&r1=1426953&r2=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.metadata-generator/src/test/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGeneratorTest.java (original)
+++ incubator/clerezza/trunk/uima/uima.metadata-generator/src/test/java/org/apache/clerezza/uima/metadatagenerator/UIMABaseMetadataGeneratorTest.java Sun Dec 30 15:46:40 2012
@@ -23,6 +23,7 @@ import org.apache.clerezza.rdf.core.UriR
import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.clerezza.rdf.utils.GraphNode;
import org.apache.clerezza.uima.utils.ExternalServicesFacade;
+import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -38,6 +39,14 @@ public class UIMABaseMetadataGeneratorTe
public static final String YOUR_ALCHEMYAPI_KEY_HERE = "...";
public static final String YOUR_OPENCALAIS_LICENSEID_HERE = "...";
+ private UIMABaseMetadataGenerator baseMetadataGenerator;
+
+ @Before
+ public void setUp() throws Exception {
+ baseMetadataGenerator = new UIMABaseMetadataGenerator();
+ baseMetadataGenerator.activte();
+ }
+
@Test
public void testConstructor() throws Exception {
new UIMABaseMetadataGenerator();
@@ -45,7 +54,6 @@ public class UIMABaseMetadataGeneratorTe
@Test
public void testGenerateMethodWithUnsupportedMediaType() throws Exception {
- UIMABaseMetadataGenerator baseMetadataGenerator = new UIMABaseMetadataGenerator();
String textToAnalyze = TEXT_TO_ANALYZE;
MGraph mGraph = new SimpleMGraph();
GraphNode node = new GraphNode(new UriRef("test"), mGraph);
@@ -61,7 +69,6 @@ public class UIMABaseMetadataGeneratorTe
parameterSettings.put("apikey", YOUR_ALCHEMYAPI_KEY_HERE);
parameterSettings.put("licenseID", YOUR_OPENCALAIS_LICENSEID_HERE);
externalServicesFacade.setParameterSetting(parameterSettings);
- UIMABaseMetadataGenerator baseMetadataGenerator = new UIMABaseMetadataGenerator(externalServicesFacade);
String textToAnalyze = TEXT_TO_ANALYZE;
MGraph mGraph = new SimpleMGraph();
GraphNode node = new GraphNode(new UriRef("test"), mGraph);
Modified: incubator/clerezza/trunk/uima/uima.samples/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.samples/pom.xml?rev=1426954&r1=1426953&r2=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.samples/pom.xml (original)
+++ incubator/clerezza/trunk/uima/uima.samples/pom.xml Sun Dec 30 15:46:40 2012
@@ -64,6 +64,10 @@
<scope>runtime</scope>
</dependency>
<dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>jaxrs.utils</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-tools</artifactId>
<version>1.5.1-incubating</version>
@@ -75,6 +79,26 @@
<version>4.8.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-default</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
Modified: incubator/clerezza/trunk/uima/uima.samples/src/main/java/org/apache/clerezza/uima/samples/services/OpenNLPNERAOService.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.samples/src/main/java/org/apache/clerezza/uima/samples/services/OpenNLPNERAOService.java?rev=1426954&r1=1426953&r2=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.samples/src/main/java/org/apache/clerezza/uima/samples/services/OpenNLPNERAOService.java (original)
+++ incubator/clerezza/trunk/uima/uima.samples/src/main/java/org/apache/clerezza/uima/samples/services/OpenNLPNERAOService.java Sun Dec 30 15:46:40 2012
@@ -21,11 +21,11 @@ package org.apache.clerezza.uima.samples
import org.apache.clerezza.rdf.core.Graph;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.access.TcManager;
-import org.apache.clerezza.uima.utils.UIMAExecutor;
-import org.apache.clerezza.uima.utils.UIMAExecutorFactory;
+import org.apache.clerezza.uima.utils.InMemoryUIMAExecutor;
import org.apache.commons.io.IOUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.uima.util.XMLInputSource;
@@ -41,14 +41,17 @@ import java.util.Map;
* from the text of a given URI
*/
@Component
-@Service(Object.class)
+@Service(OpenNLPService.class)
@Property(name = "javax.ws.rs", boolValue = true)
@Path("/uima")
-public class OpenNLPNERAOService {
+public class OpenNLPNERAOService implements OpenNLPService {
private static final String PATH = "/META-INF/OpenNLPPersonAOAE.xml";
private static final String OUTPUTGRAPH = "outputgraph";
+ @Reference
+ private InMemoryUIMAExecutor executor;
+
@POST
@Path("opennlp/person")
@Produces("application/rdf+xml")
@@ -57,7 +60,6 @@ public class OpenNLPNERAOService {
throw new WebApplicationException(Response.status(
Response.Status.BAD_REQUEST).entity(new StringBuilder("No URI specified").toString()).build());
- UIMAExecutor executor = UIMAExecutorFactory.getInstance().createUIMAExecutor();
Map<String, Object> parameters = new HashMap<String, Object>(1);
parameters.put(OUTPUTGRAPH, uriString);
try {
Added: incubator/clerezza/trunk/uima/uima.samples/src/main/java/org/apache/clerezza/uima/samples/services/OpenNLPService.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.samples/src/main/java/org/apache/clerezza/uima/samples/services/OpenNLPService.java?rev=1426954&view=auto
==============================================================================
--- incubator/clerezza/trunk/uima/uima.samples/src/main/java/org/apache/clerezza/uima/samples/services/OpenNLPService.java (added)
+++ incubator/clerezza/trunk/uima/uima.samples/src/main/java/org/apache/clerezza/uima/samples/services/OpenNLPService.java Sun Dec 30 15:46:40 2012
@@ -0,0 +1,13 @@
+package org.apache.clerezza.uima.samples.services;
+
+import javax.ws.rs.FormParam;
+
+import org.apache.clerezza.rdf.core.Graph;
+
+/**
+ * Add javadoc here
+ */
+public interface OpenNLPService {
+
+ public Graph extractPersons(String uriString);
+}
Propchange: incubator/clerezza/trunk/uima/uima.samples/src/main/java/org/apache/clerezza/uima/samples/services/OpenNLPService.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/clerezza/trunk/uima/uima.samples/src/test/java/org/apache/clerezza/uima/samples/services/OpenNLPNERAOServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.samples/src/test/java/org/apache/clerezza/uima/samples/services/OpenNLPNERAOServiceTest.java?rev=1426954&r1=1426953&r2=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.samples/src/test/java/org/apache/clerezza/uima/samples/services/OpenNLPNERAOServiceTest.java (original)
+++ incubator/clerezza/trunk/uima/uima.samples/src/test/java/org/apache/clerezza/uima/samples/services/OpenNLPNERAOServiceTest.java Sun Dec 30 15:46:40 2012
@@ -19,21 +19,57 @@
package org.apache.clerezza.uima.samples.services;
import org.apache.clerezza.rdf.core.Graph;
+import org.junit.Ignore;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Inject;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.frameworks;
+import static org.ops4j.pax.exam.CoreOptions.mavenConfiguration;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.configProfile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.dsProfile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.webProfile;
+import static org.ops4j.pax.exam.junit.JUnitOptions.junitBundles;
/**
* Testcase for {@link OpenNLPNERAOService}
*/
+@Ignore
+@RunWith(JUnit4TestRunner.class)
public class OpenNLPNERAOServiceTest {
+ @Configuration
+ public static Option[] configuration() {
+ return options(
+ mavenConfiguration(),
+ dsProfile(),
+ configProfile(),
+ webProfile(),
+ junitBundles(),
+ frameworks(felix()));
+ }
+
+
+
+
+ @Inject
+ private BundleContext bundleContext;
+
@Test
public void serviceExecutionTest() throws Exception {
- OpenNLPNERAOService service = new OpenNLPNERAOService();
- Graph graph = service.extractPersons(getClass().getResource("/ner_test_page.html").toURI().toString());
- assertNotNull(graph);
- assertFalse(graph.isEmpty());
+ ServiceReference serviceReference = bundleContext.getServiceReference(OpenNLPService.class.getName());
+ assertNotNull(serviceReference);
+// OpenNLPNERAOService service = new OpenNLPNERAOService();
+// Graph graph = service.extractPersons(getClass().getResource("/ner_test_page.html").toURI().toString());
+// assertNotNull(graph);
+// assertFalse(graph.isEmpty());
}
}
Modified: incubator/clerezza/trunk/uima/uima.utils/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.utils/pom.xml?rev=1426954&r1=1426953&r2=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.utils/pom.xml (original)
+++ incubator/clerezza/trunk/uima/uima.utils/pom.xml Sun Dec 30 15:46:40 2012
@@ -92,6 +92,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.9.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
Modified: incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/AEProvider.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/AEProvider.java?rev=1426954&r1=1426953&r2=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/AEProvider.java (original)
+++ incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/AEProvider.java Sun Dec 30 15:46:40 2012
@@ -19,8 +19,10 @@
package org.apache.clerezza.uima.utils;
import org.apache.clerezza.uima.utils.cl.ClerezzaUIMAExtensionClassLoader;
-import org.apache.clerezza.uima.utils.cl.UIMAResourcesClassLoaderRepository;
+import org.apache.clerezza.uima.utils.cl.UIMAClassLoaderRepository;
+import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.uima.UIMAFramework;
import org.apache.uima.analysis_engine.AnalysisEngine;
@@ -29,6 +31,7 @@ import org.apache.uima.resource.Resource
import org.apache.uima.resource.ResourceManager;
import org.apache.uima.resource.ResourceSpecifier;
import org.apache.uima.util.XMLInputSource;
+import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,16 +53,23 @@ public class AEProvider {
private static Map<XMLInputSource, AnalysisEngine> registeredAEs;
@Reference
- private UIMAResourcesClassLoaderRepository classLoaderRepository;
+ private UIMAClassLoaderRepository classLoaderRepository;
- public AEProvider() {
- defaultXMLPath = "/META-INF/ExtServicesAE.xml"; // if no default is specified use the bundled ext services descriptor
+ @Activate
+ protected void activate(ComponentContext componentContext) throws Exception {
+ Object descriptor = componentContext.getProperties().get("serviceFacadeDescriptor");
+ if (descriptor != null) {
+ defaultXMLPath = String.valueOf(descriptor);
+ } else {
+ defaultXMLPath = "/META-INF/ExtServicesAE.xml"; // if no default is specified use the bundled ext services descriptor
+ }
registeredAEs = new HashMap<XMLInputSource, AnalysisEngine>();
}
- public AEProvider withDefaultDescriptor(String xmlDescriptorPath) {
- defaultXMLPath = xmlDescriptorPath;
- return this;
+ @Deactivate
+ protected void deactivate() throws Exception {
+ defaultXMLPath = null;
+ registeredAEs = null;
}
/**
Modified: incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/ExternalServicesFacade.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/ExternalServicesFacade.java?rev=1426954&r1=1426953&r2=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/ExternalServicesFacade.java (original)
+++ incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/ExternalServicesFacade.java Sun Dec 30 15:46:40 2012
@@ -18,6 +18,7 @@
*/
package org.apache.clerezza.uima.utils;
+import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.uima.UIMAException;
import org.apache.uima.alchemy.ts.categorization.Category;
@@ -40,14 +41,11 @@ import java.util.Map;
@Service(value = UIMAServicesFacade.class)
public class ExternalServicesFacade implements UIMAServicesFacade {
- private final UIMAExecutor uimaExecutor;
+ @Reference
+ private InMemoryUIMAExecutor uimaExecutor;
private Map<String, Object> parameterSetting = new HashMap<String, Object>();
- public ExternalServicesFacade() {
- this.uimaExecutor = UIMAExecutorFactory.getInstance().createUIMAExecutor();
- }
-
public List<FeatureStructure> getTags(String document) throws UIMAException {
List<FeatureStructure> keywords = new ArrayList<FeatureStructure>();
Copied: incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/InMemoryUIMAExecutor.java (from r1426328, incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java)
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/InMemoryUIMAExecutor.java?p2=incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/InMemoryUIMAExecutor.java&p1=incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java&r1=1426328&r2=1426954&rev=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java (original)
+++ incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/InMemoryUIMAExecutor.java Sun Dec 30 15:46:40 2012
@@ -18,6 +18,8 @@
*/
package org.apache.clerezza.uima.utils;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.jcas.JCas;
@@ -29,13 +31,11 @@ import java.util.Map;
/**
* Executes UIMA pipelines collecting results in a {@link JCas}
*/
-public class UIMAExecutor {
+@Service
+public class InMemoryUIMAExecutor {
- private final AEProvider aeProvider;
-
- public UIMAExecutor(AEProvider aeProvider) {
- this.aeProvider = aeProvider;
- }
+ @Reference
+ private AEProvider aeProvider;
/**
* analyze a text document using the default Analysis Engine
Modified: incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMABundleActivator.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMABundleActivator.java?rev=1426954&r1=1426953&r2=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMABundleActivator.java (original)
+++ incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMABundleActivator.java Sun Dec 30 15:46:40 2012
@@ -18,7 +18,7 @@
*/
package org.apache.clerezza.uima.utils;
-import org.apache.clerezza.uima.utils.cl.UIMAResourcesClassLoaderRepository;
+import org.apache.clerezza.uima.utils.cl.CachingUIMAResourcesClassLoaderRepository;
import org.apache.felix.scr.annotations.Reference;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -29,7 +29,7 @@ import org.osgi.framework.BundleContext;
public abstract class UIMABundleActivator implements BundleActivator {
@Reference
- protected UIMAResourcesClassLoaderRepository classLoaderRepository;
+ protected CachingUIMAResourcesClassLoaderRepository classLoaderRepository;
@Override
public void start(BundleContext context) throws Exception {
Copied: incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/CachingUIMAResourcesClassLoaderRepository.java (from r1426328, incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/UIMAResourcesClassLoaderRepository.java)
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/CachingUIMAResourcesClassLoaderRepository.java?p2=incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/CachingUIMAResourcesClassLoaderRepository.java&p1=incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/UIMAResourcesClassLoaderRepository.java&r1=1426328&r2=1426954&rev=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/UIMAResourcesClassLoaderRepository.java (original)
+++ incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/CachingUIMAResourcesClassLoaderRepository.java Sun Dec 30 15:46:40 2012
@@ -29,11 +29,11 @@ import java.util.HashSet;
import java.util.Set;
/**
- * Repository for UIMA {@link AnalysisComponent}s' {@link ClassLoader}s
+ * In memory cache implementation of {@link UIMAClassLoaderRepository}
*/
-@Service
-public class UIMAResourcesClassLoaderRepository {
- private final static Logger log = LoggerFactory.getLogger(UIMAResourcesClassLoaderRepository.class);
+@Service( value = UIMAClassLoaderRepository.class )
+public class CachingUIMAResourcesClassLoaderRepository implements UIMAClassLoaderRepository {
+ private final static Logger log = LoggerFactory.getLogger(CachingUIMAResourcesClassLoaderRepository.class);
private final static Set<ClassLoader> registeredComponents = new HashSet<ClassLoader>();
Added: incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/UIMAClassLoaderRepository.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/UIMAClassLoaderRepository.java?rev=1426954&view=auto
==============================================================================
--- incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/UIMAClassLoaderRepository.java (added)
+++ incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/UIMAClassLoaderRepository.java Sun Dec 30 15:46:40 2012
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.uima.utils.cl;
+
+import java.util.Collection;
+
+import org.apache.uima.analysis_component.AnalysisComponent;
+import org.apache.uima.resource.Resource;
+
+/**
+ * Repository for UIMA {@link AnalysisComponent}s' {@link ClassLoader}s
+ */
+public interface UIMAClassLoaderRepository {
+
+ public <C extends AnalysisComponent> void registerComponent(Class<C> component);
+
+ public <R extends Resource> void registerResource(Class<R> component);
+
+ public Collection<ClassLoader> getComponents();
+}
Propchange: incubator/clerezza/trunk/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/UIMAClassLoaderRepository.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/AEProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/AEProviderTest.java?rev=1426954&r1=1426953&r2=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/AEProviderTest.java (original)
+++ incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/AEProviderTest.java Sun Dec 30 15:46:40 2012
@@ -18,12 +18,18 @@
*/
package org.apache.clerezza.uima.utils;
+import java.util.Dictionary;
+import java.util.Properties;
+
import org.apache.uima.analysis_engine.AnalysisEngine;
import org.junit.Before;
import org.junit.Test;
+import org.osgi.service.component.ComponentContext;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
/**
* Testcase for {@link AEProvider}
@@ -33,8 +39,12 @@ public class AEProviderTest {
private AEProvider aeProvider;
@Before
- public void setUp() {
- this.aeProvider = new AEProvider();
+ public void setUp() throws Exception {
+ aeProvider = new AEProvider();
+ ComponentContext componentContext = mock(ComponentContext.class);
+ Dictionary dictionary = new Properties();
+ when(componentContext.getProperties()).thenReturn(dictionary);
+ aeProvider.activate(componentContext);
}
@Test
@@ -52,7 +62,7 @@ public class AEProviderTest {
@Test
public void testGetAEWithWrongPath() {
try {
- this.aeProvider.getAE("thisIsSomethingWeird");
+ aeProvider.getAE("thisIsSomethingWeird");
fail();
} catch (Throwable e) {
}
Copied: incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/InMemoryUIMAExecutorTest.java (from r1426328, incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAExecutorTest.java)
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/InMemoryUIMAExecutorTest.java?p2=incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/InMemoryUIMAExecutorTest.java&p1=incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAExecutorTest.java&r1=1426328&r2=1426954&rev=1426954&view=diff
==============================================================================
--- incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAExecutorTest.java (original)
+++ incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/InMemoryUIMAExecutorTest.java Sun Dec 30 15:46:40 2012
@@ -23,19 +23,13 @@ import org.junit.Test;
import static org.junit.Assert.assertNotNull;
/**
- * Testcase for {@link UIMAExecutor}
+ * Testcase for {@link InMemoryUIMAExecutor}
*/
-public class UIMAExecutorTest {
+public class InMemoryUIMAExecutorTest {
@Test
- public void testDefaultConstructor() throws Exception {
- UIMAExecutor uimaExecutor = UIMAExecutorFactory.getInstance().createUIMAExecutor();
- assertNotNull(uimaExecutor);
- }
-
- @Test
- public void testPathConstructor() throws Exception {
- UIMAExecutor uimaExecutor = UIMAExecutorFactory.getInstance().createUIMAExecutor("/META-INF/ExtServicesAE.xml");
+ public void testConstructor() throws Exception {
+ InMemoryUIMAExecutor uimaExecutor = new InMemoryUIMAExecutor();
assertNotNull(uimaExecutor);
}
Propchange: incubator/clerezza/trunk/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/InMemoryUIMAExecutorTest.java
------------------------------------------------------------------------------
svn:eol-style = native