Author: tommaso
Date: Sun Sep 4 10:38:06 2011
New Revision: 1164988
URL: http://svn.apache.org/viewvc?rev=1164988&view=rev
Log:
[CLEREZZA-629] - changes to uima module to make it possible to deploy custom
UIMA pipelines with custom classloading avoiding OSGi issues with
Class.forName() methods
Added:
incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumerActivator.java
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMABundleActivator.java
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtilsBundleActivator.java
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/AnalysisComponentsClassLoaderRepository.java
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/ClerezzaUIMAExtensionClassLoader.java
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/ResourceByteReader.java
Modified:
incubator/clerezza/trunk/parent/uima/ (props changed)
incubator/clerezza/trunk/parent/uima/pom.xml
incubator/clerezza/trunk/parent/uima/uima.casconsumer/pom.xml
incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ao/AOMappingStrategy.java
incubator/clerezza/trunk/parent/uima/uima.concept-tagging/ (props changed)
incubator/clerezza/trunk/parent/uima/uima.concept-tagging/pom.xml
incubator/clerezza/trunk/parent/uima/uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMARemoteResourceTaggerService.java
incubator/clerezza/trunk/parent/uima/uima.metadata-generator/ (props
changed)
incubator/clerezza/trunk/parent/uima/uima.metadata-generator/pom.xml
incubator/clerezza/trunk/parent/uima/uima.ontologies/ (props changed)
incubator/clerezza/trunk/parent/uima/uima.utils/pom.xml
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/AEProvider.java
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/ExternalServicesFacade.java
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutorFactory.java
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java
incubator/clerezza/trunk/parent/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAExecutorTest.java
Propchange: incubator/clerezza/trunk/parent/uima/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Sep 4 10:38:06 2011
@@ -1 +1,5 @@
*.iml
+
+.project
+
+.settings
Modified: incubator/clerezza/trunk/parent/uima/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/pom.xml?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/uima/pom.xml (original)
+++ incubator/clerezza/trunk/parent/uima/pom.xml Sun Sep 4 10:38:06 2011
@@ -6,19 +6,22 @@
<version>0.1-incubating-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Clerezza - Apache UIMA extension module</name>
- <description>Apache UIMA extension modules enable usage of UIMA for enhanced
metadata extraction inside Clerezza
- </description>
+ <description>Apache UIMA extension modules enable usage of UIMA for enhanced
metadata extraction inside Clerezza</description>
<parent>
<groupId>org.apache.clerezza</groupId>
<artifactId>parent</artifactId>
<version>0.2-incubating-SNAPSHOT</version>
</parent>
+ <properties>
+ <uima.version>2.3.1</uima.version>
+ </properties>
<modules>
<module>uima.ontologies</module>
+ <module>uima.ontologies.ao</module>
<module>uima.utils</module>
+ <module>uima.casconsumer</module>
<module>uima.metadata-generator</module>
<module>uima.concept-tagging</module>
- <module>uima.casconsumer</module>
</modules>
<dependencies>
<dependency>
@@ -31,13 +34,18 @@
<dependencies>
<dependency>
<groupId>org.apache.uima</groupId>
- <artifactId>uimaj-ep-runtime</artifactId>
- <version>2.3.1</version>
+ <artifactId>uimaj-core</artifactId>
+ <version>${uima.version}</version>
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimaj-component-test-util</artifactId>
- <version>2.3.1</version>
+ <version>${uima.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-document-annotation</artifactId>
+ <version>${uima.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
@@ -48,6 +56,10 @@
<artifactId>maven-pladoc-plugin.core</artifactId>
<version>0.3-incubating-SNAPSHOT</version>
</plugin>
+ <plugin>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>maven-paxexam-plugin</artifactId>
+ </plugin>
</plugins>
</build>
</project>
Modified: incubator/clerezza/trunk/parent/uima/uima.casconsumer/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.casconsumer/pom.xml?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/uima/uima.casconsumer/pom.xml (original)
+++ incubator/clerezza/trunk/parent/uima/uima.casconsumer/pom.xml Sun Sep 4
10:38:06 2011
@@ -19,18 +19,14 @@
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
- <artifactId>uima.ontologies</artifactId>
- <version>${project.version}</version>
- <scope>runtime</scope>
+ <artifactId>uima.ontologies.ao</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
- <artifactId>uima.ontologies.ao</artifactId>
+ <artifactId>uima.ontologies</artifactId>
<version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.uima</groupId>
- <artifactId>uimaj-ep-runtime</artifactId>
+ <scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
@@ -50,5 +46,25 @@
<artifactId>rdf.simple.storage</artifactId>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ </dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>org.slf4j.*;resolution:=optional,*</Import-Package>
+
<Export-Package>org.apache.clerezza.uima.casconsumer.*;version=0.1.0</Export-Package>
+
<Bundle-Activator>org.apache.clerezza.uima.casconsumer.ClerezzaCASConsumerActivator</Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
Added:
incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumerActivator.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumerActivator.java?rev=1164988&view=auto
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumerActivator.java
(added)
+++
incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ClerezzaCASConsumerActivator.java
Sun Sep 4 10:38:06 2011
@@ -0,0 +1,32 @@
+/*
+ * 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.casconsumer;
+
+import
org.apache.clerezza.uima.utils.cl.AnalysisComponentsClassLoaderRepository;
+import org.apache.clerezza.uima.utils.UIMABundleActivator;
+
+/**
+ * {@link UIMABundleActivator} to register {@link ClerezzaCASConsumer}
component
+ */
+public class ClerezzaCASConsumerActivator extends UIMABundleActivator {
+ @Override
+ protected void classRegistered() {
+
AnalysisComponentsClassLoaderRepository.registerComponent(ClerezzaCASConsumer.class);
+ }
+}
Modified:
incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ao/AOMappingStrategy.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ao/AOMappingStrategy.java?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ao/AOMappingStrategy.java
(original)
+++
incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ao/AOMappingStrategy.java
Sun Sep 4 10:38:06 2011
@@ -165,7 +165,6 @@ public class AOMappingStrategy implement
* Given a documents text and a start and end offsets it returns an RDF
value for the equivalent string literal. Annotations
* have a convenience method for doing this but this method takes advantage
of getting the text for the given document view once.
*
- * @param valueFactory used to create the RDF literal
* @param documentText from which to extract the span of text
* @param start offset into the document text where the span starts
if less than 0 will use zero instead
* @param end offset into the document text where the span ends. if
the end goes beyond the length of the document text it is limited to the length
Propchange: incubator/clerezza/trunk/parent/uima/uima.concept-tagging/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Sep 4 10:38:06 2011
@@ -1 +1,9 @@
target
+
+*.iml
+
+.classpath
+
+.project
+
+.settings
Modified: incubator/clerezza/trunk/parent/uima/uima.concept-tagging/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.concept-tagging/pom.xml?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/uima/uima.concept-tagging/pom.xml (original)
+++ incubator/clerezza/trunk/parent/uima/uima.concept-tagging/pom.xml Sun Sep
4 10:38:06 2011
@@ -18,6 +18,10 @@
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
<artifactId>uima.utils</artifactId>
<version>0.1-incubating-SNAPSHOT</version>
</dependency>
@@ -31,15 +35,6 @@
<version>0.1-incubating-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
- <dependency>
- <groupId>org.apache.uima</groupId>
- <artifactId>uimaj-ep-runtime</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.uima</groupId>
- <artifactId>AlchemyAPIAnnotator-osgi</artifactId>
- <version>2.3.1-SNAPSHOT</version>
- </dependency>
</dependencies>
<build>
<plugins>
@@ -49,7 +44,7 @@
<extensions>true</extensions>
<configuration>
<instructions>
- <Import-Package>org.slf4j.*;resolution:=optional,*</Import-Package>
+
<Import-Package>javax.ws.rs.*;org.osgi.service.component.*;org.apache.uima.*;org.apache.clerezza.*</Import-Package>
<Export-Package>org.apache.clerezza.uima.concept.*</Export-Package>
</instructions>
</configuration>
Modified:
incubator/clerezza/trunk/parent/uima/uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMARemoteResourceTaggerService.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMARemoteResourceTaggerService.java?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMARemoteResourceTaggerService.java
(original)
+++
incubator/clerezza/trunk/parent/uima/uima.concept-tagging/src/main/java/org/apache/clerezza/uima/concept/UIMARemoteResourceTaggerService.java
Sun Sep 4 10:38:06 2011
@@ -26,6 +26,7 @@ import org.apache.clerezza.uima.utils.UI
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
+import org.apache.uima.util.XMLInputSource;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
@@ -42,7 +43,7 @@ import java.util.Map;
@Path("/resourcetagger")
public class UIMARemoteResourceTaggerService {
- private static final String PATH = "META-INF/AggregateResourceTaggerAE.xml";
+ private static final String PATH = "/META-INF/AggregateResourceTaggerAE.xml";
private static final String OUTPUTGRAPH = "outputgraph";
private static final String ALCHEMYKEY = "alchemykey";
@@ -54,12 +55,12 @@ 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(getClass().getClassLoader());
+ UIMAExecutor executor =
UIMAExecutorFactory.getInstance().createUIMAExecutor();
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put(OUTPUTGRAPH, uri);
parameters.put(ALCHEMYKEY, key);
try {
- executor.analyzeDocument(uri, PATH, parameters);
+ executor.analyzeDocument(uri, new
XMLInputSource(getClass().getResource(PATH)), parameters);
} catch (Exception e) {
throw new WebApplicationException(Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity(new
StringBuilder("Failed UIMA execution on URI ").
Propchange: incubator/clerezza/trunk/parent/uima/uima.metadata-generator/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Sep 4 10:38:06 2011
@@ -2,3 +2,5 @@
target
.classpath
.project
+
+*.iml
Modified: incubator/clerezza/trunk/parent/uima/uima.metadata-generator/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.metadata-generator/pom.xml?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/uima/uima.metadata-generator/pom.xml
(original)
+++ incubator/clerezza/trunk/parent/uima/uima.metadata-generator/pom.xml Sun
Sep 4 10:38:06 2011
@@ -22,16 +22,6 @@
<version>0.1-incubating-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>org.apache.uima</groupId>
- <artifactId>AlchemyAPIAnnotator-osgi</artifactId>
- <version>2.3.1-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.uima</groupId>
- <artifactId>OpenCalaisAnnotator-osgi</artifactId>
- <version>2.3.1-SNAPSHOT</version>
- </dependency>
- <dependency>
<groupId>org.apache.clerezza</groupId>
<artifactId>uima.ontologies</artifactId>
<version>0.1-incubating-SNAPSHOT</version>
@@ -73,15 +63,9 @@
<version>0.9</version>
</dependency>
<dependency>
- <groupId>org.apache.tika</groupId>
- <artifactId>tika-bundle</artifactId>
- <version>0.9</version>
- <scope>runtime</scope>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.apache.uima</groupId>
- <artifactId>uimaj-ep-runtime</artifactId>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-compress</artifactId>
+ <version>1.1</version>
</dependency>
</dependencies>
<build>
@@ -93,7 +77,7 @@
<configuration>
<instructions>
<Export-Package>org.apache.clerezza.uima.metadatagenerator.*</Export-Package>
-
<Import-Package>org.apache.tika.*;resolution:=optional,*</Import-Package>
+
<Import-Package>org.slf4j.*;com.drew.*;com.sun.syndication.*;de.l3s.*;resolution:=optional,org.apache.uima.*;org.apache.tika.*;org.apache.clerezza.*;javax.ws.rs.*</Import-Package>
<Embed-Dependency>tika-bundle</Embed-Dependency>
</instructions>
</configuration>
Propchange: incubator/clerezza/trunk/parent/uima/uima.ontologies/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Sep 4 10:38:06 2011
@@ -1 +1,9 @@
target
+
+*.iml
+
+.project
+
+.classpath
+
+.settings
Modified: incubator/clerezza/trunk/parent/uima/uima.utils/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/pom.xml?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/uima/uima.utils/pom.xml (original)
+++ incubator/clerezza/trunk/parent/uima/uima.utils/pom.xml Sun Sep 4 10:38:06
2011
@@ -1,5 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.clerezza</groupId>
<artifactId>uima.utils</artifactId>
@@ -20,13 +20,13 @@
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
- <artifactId>AlchemyAPIAnnotator-osgi</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <artifactId>AlchemyAPIAnnotator</artifactId>
+ <version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
- <artifactId>OpenCalaisAnnotator-osgi</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <artifactId>OpenCalaisAnnotator</artifactId>
+ <version>2.3.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
@@ -35,6 +35,12 @@
<scope>runtime</scope>
</dependency>
<dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.8.3</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.1</version>
@@ -53,7 +59,21 @@
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
- <artifactId>uimaj-ep-runtime</artifactId>
+ <artifactId>uimaj-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-document-annotation</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.uima</groupId>
+ <artifactId>uimaj-component-test-util</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
</dependency>
</dependencies>
<build>
@@ -64,8 +84,9 @@
<extensions>true</extensions>
<configuration>
<instructions>
- <Import-Package>org.slf4j.*;resolution:=optional,*</Import-Package>
- <Export-Package>org.apache.clerezza.uima.utils.*</Export-Package>
+
<Export-Package>org.apache.clerezza.uima.utils.*;version=0.1.0,org.apache.uima.*;version=2.3.0</Export-Package>
+ <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
+
<Bundle-Activator>org.apache.clerezza.uima.utils.UIMAUtilsBundleActivator</Bundle-Activator>
</instructions>
</configuration>
</plugin>
Modified:
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/AEProvider.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/AEProvider.java?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/AEProvider.java
(original)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/AEProvider.java
Sun Sep 4 10:38:06 2011
@@ -18,29 +18,36 @@
*/
package org.apache.clerezza.uima.utils;
+import org.apache.clerezza.uima.utils.cl.ClerezzaUIMAExtensionClassLoader;
+import
org.apache.clerezza.uima.utils.cl.AnalysisComponentsClassLoaderRepository;
import org.apache.uima.UIMAFramework;
import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.analysis_engine.AnalysisEngineDescription;
import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceManager;
import org.apache.uima.resource.ResourceSpecifier;
import org.apache.uima.util.XMLInputSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Map;
+import java.util.*;
/**
* provide the {@link AnalysisEngine} using the default descriptor or using a
custom descriptor (absolute)
* path
*/
public class AEProvider {
+ private final static Logger log = LoggerFactory.getLogger(AEProvider.class);
private static String defaultXMLPath;
- private ClassLoader delegateClassloader;
+ private static Map<XMLInputSource, AnalysisEngine> registeredAEs;
public AEProvider() {
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) {
@@ -48,11 +55,6 @@ public class AEProvider {
return this;
}
- public AEProvider withDelegateClassloader(ClassLoader classLoader) {
- delegateClassloader = classLoader;
- return this;
- }
-
/**
* get an Analysis Engine using the default path (specified in constructor)
*
@@ -73,7 +75,7 @@ public class AEProvider {
*
*/
public AnalysisEngine getAE(String filePath) throws
ResourceInitializationException {
- AnalysisEngine ae = null;
+ AnalysisEngine ae;
// get Resource Specifier from XML file
try {
URL url = createURLFromPath(filePath);
@@ -89,12 +91,15 @@ public class AEProvider {
}
private URL createURLFromPath(String filePath) throws MalformedURLException {
- URL url;
// try classpath
- if (delegateClassloader != null)
- url = delegateClassloader.getResource(filePath);
- else
- url = getClass().getResource(filePath);
+ URL url = getClass().getResource(filePath);
+ if (url == null) {
+ for (ClassLoader c :
AnalysisComponentsClassLoaderRepository.getComponents()) {
+ url = c.getResource(filePath);
+ if (url != null)
+ break;
+ }
+ }
// else try file
if (url == null) {
@@ -107,26 +112,54 @@ public class AEProvider {
return url;
}
- public AnalysisEngine getAE(String filePath, Map<String, Object>
parameterSettings) throws ResourceInitializationException {
- AnalysisEngine ae;
- // get Resource Specifier from XML file
+ public AnalysisEngine getAEFromSource(XMLInputSource xmlInputSource,
Map<String, Object> parameterSettings) throws ResourceInitializationException {
+ AnalysisEngine ae = null;
try {
- URL url = createURLFromPath(filePath);
- XMLInputSource in = new XMLInputSource(url);
-
- // eventually add/override descriptor's configuration parameters
- AnalysisEngineDescription desc =
UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
- for (String parameter : parameterSettings.keySet()) {
- if
(desc.getAnalysisEngineMetaData().getConfigurationParameterSettings().getParameterValue(parameter)
!= null)
-
desc.getAnalysisEngineMetaData().getConfigurationParameterSettings().setParameterValue(parameter,
parameterSettings.get(parameter));
+ AnalysisEngine cachedAE = registeredAEs.get(xmlInputSource);
+ if (cachedAE != null) {
+ cachedAE.reconfigure();
+ return cachedAE;
+ } else {
+ // eventually add/override descriptor's configuration parameters
+ AnalysisEngineDescription desc =
UIMAFramework.getXMLParser().parseAnalysisEngineDescription(xmlInputSource);
+ for (String parameter : parameterSettings.keySet()) {
+ if
(desc.getAnalysisEngineMetaData().getConfigurationParameterSettings().getParameterValue(parameter)
!= null)
+
desc.getAnalysisEngineMetaData().getConfigurationParameterSettings().setParameterValue(parameter,
parameterSettings.get(parameter));
+ }
+
+ // create AE here
+ try {
+ ae = UIMAFramework.produceAnalysisEngine(desc);
+ } catch (Exception e) {
+ // do nothing
+ }
+ if (ae == null) {
+ try {
+ ResourceManager rm = UIMAFramework.newDefaultResourceManager();
+ rm.setExtensionClassPath(new
ClerezzaUIMAExtensionClassLoader(getClass().getClassLoader()), "*", true);
+ ae = UIMAFramework.produceAnalysisEngine(desc, rm, null);
+ } catch (Exception e) {
+ // do nothing
+ }
+ }
+
+
+ if (ae == null) {
+ throw new AEInstantiationException();
+ } else {
+ registeredAEs.put(xmlInputSource, ae);
+ }
}
-
- // create AE here
- ae = UIMAFramework.produceAnalysisEngine(desc);
} catch (Exception e) {
throw new ResourceInitializationException(e);
}
return ae;
}
+
+ private static class AEInstantiationException extends Exception {
+ public AEInstantiationException() {
+ super();
+ }
+ }
}
\ No newline at end of file
Modified:
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/ExternalServicesFacade.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/ExternalServicesFacade.java?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/ExternalServicesFacade.java
(original)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/ExternalServicesFacade.java
Sun Sep 4 10:38:06 2011
@@ -25,7 +25,9 @@ import org.apache.uima.alchemy.ts.keywor
import org.apache.uima.alchemy.ts.language.LanguageFS;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.jcas.JCas;
+import org.apache.uima.util.XMLInputSource;
+import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -50,7 +52,9 @@ public class ExternalServicesFacade impl
try {
// analyze the document
- JCas jcas = uimaExecutor.analyzeDocument(document,
"/TextKeywordExtractionAEDescriptor.xml", getParameterSetting());
+ URL resourceURL =
getClass().getResource("/META-INF/TextKeywordExtractionAEDescriptor.xml");
+ XMLInputSource xmlInputSource = new XMLInputSource(resourceURL);
+ JCas jcas = uimaExecutor.analyzeDocument(document, xmlInputSource,
getParameterSetting());
// get AlchemyAPI keywords extracted using UIMA
keywords.addAll(UIMAUtils.getAllFSofType(KeywordFS.type, jcas));
@@ -69,7 +73,9 @@ public class ExternalServicesFacade impl
try {
// analyze the document
- JCas jcas =uimaExecutor.analyzeDocument(document,
"/TextLanguageDetectionAEDescriptor.xml", getParameterSetting());
+ URL resourceURL =
getClass().getResource("/META-INF/TextLanguageDetectionAEDescriptor.xml");
+ XMLInputSource xmlInputSource = new XMLInputSource(resourceURL);
+ JCas jcas = uimaExecutor.analyzeDocument(document, xmlInputSource,
getParameterSetting());
// extract language Feature Structure using AlchemyAPI Annotator
languageFS = UIMAUtils.getSingletonFeatureStructure(LanguageFS.type,
jcas);
@@ -88,7 +94,9 @@ public class ExternalServicesFacade impl
try {
// analyze the document
- JCas jcas = uimaExecutor.analyzeDocument(document,
"/OpenCalaisAnnotator.xml", getParameterSetting());
+ URL resourceURL =
getClass().getResource("/META-INF/OpenCalaisAnnotator.xml");
+ XMLInputSource xmlInputSource = new XMLInputSource(resourceURL);
+ JCas jcas = uimaExecutor.analyzeDocument(document, xmlInputSource,
getParameterSetting());
// extract entities using OpenCalaisAnnotator
calaisAnnotations.addAll(UIMAUtils.getAllAnnotationsOfType(org.apache.uima.calais.BaseType.type,
jcas));
@@ -104,7 +112,9 @@ public class ExternalServicesFacade impl
try {
// analyze the document
- JCas jcas = uimaExecutor.analyzeDocument(document,
"/TextCategorizationAEDescriptor.xml", getParameterSetting());
+ URL resourceURL =
getClass().getResource("/META-INF/TextCategorizationAEDescriptor.xml");
+ XMLInputSource xmlInputSource = new XMLInputSource(resourceURL);
+ JCas jcas = uimaExecutor.analyzeDocument(document, xmlInputSource,
getParameterSetting());
// extract category Feature Structure using AlchemyAPI Annotator
categoryFS = UIMAUtils.getSingletonFeatureStructure(Category.type, jcas);
@@ -122,7 +132,9 @@ public class ExternalServicesFacade impl
try {
// analyze the document
- JCas jcas = uimaExecutor.analyzeDocument(document,
"/TextConceptTaggingAEDescriptor.xml", getParameterSetting());
+ URL resourceURL =
getClass().getResource("/META-INF/TextConceptTaggingAEDescriptor.xml");
+ XMLInputSource xmlInputSource = new XMLInputSource(resourceURL);
+ JCas jcas = uimaExecutor.analyzeDocument(document, xmlInputSource,
getParameterSetting());
// get AlchemyAPI concepts extracted using UIMA
concepts.addAll(UIMAUtils.getAllFSofType(ConceptFS.type, jcas));
Added:
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMABundleActivator.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMABundleActivator.java?rev=1164988&view=auto
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMABundleActivator.java
(added)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMABundleActivator.java
Sun Sep 4 10:38:06 2011
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * {@link BundleActivator} to enable automatic registration of Annotator
classes to load from UIMA utils
+ */
+public abstract class UIMABundleActivator implements BundleActivator {
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ classRegistered();
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ // do nothing
+ }
+
+ protected abstract void classRegistered();
+}
Modified:
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java
(original)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutor.java
Sun Sep 4 10:38:06 2011
@@ -22,6 +22,7 @@ import org.apache.uima.analysis_engine.A
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.XMLInputSource;
import java.util.Map;
@@ -62,13 +63,13 @@ public class UIMAExecutor {
* analyze a text document specifying a different Analysis Engine descriptor
path and specific Analysis Engine parameter settings
*
* @param doc
- * @param xmlPath
+ * @param xmlInputSource
* @param aeParameterSettings
* @throws AnalysisEngineProcessException,
* ResourceInitializationException
*/
- public JCas analyzeDocument(String doc, String xmlPath, Map<String, Object>
aeParameterSettings) throws AnalysisEngineProcessException,
ResourceInitializationException {
- AnalysisEngine engine = aeProvider.getAE(xmlPath, aeParameterSettings);
+ public JCas analyzeDocument(String doc, XMLInputSource xmlInputSource,
Map<String, Object> aeParameterSettings) throws AnalysisEngineProcessException,
ResourceInitializationException {
+ AnalysisEngine engine = aeProvider.getAEFromSource(xmlInputSource,
aeParameterSettings);
return executeAE(engine, doc);
}
Modified:
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutorFactory.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutorFactory.java?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutorFactory.java
(original)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAExecutorFactory.java
Sun Sep 4 10:38:06 2011
@@ -39,18 +39,8 @@ public class UIMAExecutorFactory {
return new UIMAExecutor(aeProvider);
}
- public UIMAExecutor createUIMAExecutor(ClassLoader classLoader) {
- AEProvider aeProvider = new
AEProvider().withDelegateClassloader(classLoader);
- return new UIMAExecutor(aeProvider);
- }
-
public UIMAExecutor createUIMAExecutor(String defaultXMLPath) {
AEProvider aeProvider = new
AEProvider().withDefaultDescriptor(defaultXMLPath);
return new UIMAExecutor(aeProvider);
}
-
- public UIMAExecutor createUIMAExecutor(ClassLoader classLoader, String
defaultXMLPath) {
- AEProvider aeProvider = new
AEProvider().withDefaultDescriptor(defaultXMLPath).withDelegateClassloader(classLoader);
- return new UIMAExecutor(aeProvider);
- }
}
Modified:
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java
(original)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java
Sun Sep 4 10:38:06 2011
@@ -23,6 +23,9 @@ import org.apache.clerezza.rdf.utils.Gra
import org.apache.clerezza.uima.ontologies.ENTITY;
import
org.apache.clerezza.uima.utils.exception.FeatureStructureNotFoundException;
import
org.apache.clerezza.uima.utils.exception.NotSingletonFeatureStructureException;
+import
org.apache.uima.alchemy.annotator.TextRankedNamedEntityExtractionAnnotator;
+import org.apache.uima.analysis_component.AnalysisComponent;
+import org.apache.uima.annotator.calais.OpenCalaisAnnotator;
import org.apache.uima.cas.*;
import org.apache.uima.cas.text.AnnotationIndex;
import org.apache.uima.jcas.JCas;
@@ -31,7 +34,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.locks.Lock;
/**
Added:
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtilsBundleActivator.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtilsBundleActivator.java?rev=1164988&view=auto
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtilsBundleActivator.java
(added)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtilsBundleActivator.java
Sun Sep 4 10:38:06 2011
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import
org.apache.clerezza.uima.utils.cl.AnalysisComponentsClassLoaderRepository;
+import
org.apache.uima.alchemy.annotator.TextRankedNamedEntityExtractionAnnotator;
+import org.apache.uima.annotator.calais.OpenCalaisAnnotator;
+
+/**
+ * {@link UIMABundleActivator} for UIMA utils project
+ */
+public class UIMAUtilsBundleActivator extends UIMABundleActivator {
+ @Override
+ protected void classRegistered() {
+
AnalysisComponentsClassLoaderRepository.registerComponent(TextRankedNamedEntityExtractionAnnotator.class);
+
AnalysisComponentsClassLoaderRepository.registerComponent(OpenCalaisAnnotator.class);
+ }
+}
Added:
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/AnalysisComponentsClassLoaderRepository.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/AnalysisComponentsClassLoaderRepository.java?rev=1164988&view=auto
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/AnalysisComponentsClassLoaderRepository.java
(added)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/AnalysisComponentsClassLoaderRepository.java
Sun Sep 4 10:38:06 2011
@@ -0,0 +1,45 @@
+/*
+ * 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 org.apache.uima.analysis_component.AnalysisComponent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Repository for UIMA {@link AnalysisComponent}s' {@link ClassLoader}s
+ */
+public class AnalysisComponentsClassLoaderRepository {
+ private final static Logger log =
LoggerFactory.getLogger(AnalysisComponentsClassLoaderRepository.class);
+
+ private final static Set<ClassLoader> registeredComponents = new
HashSet<ClassLoader>();
+
+ public static <C extends AnalysisComponent> void registerComponent(Class<C>
component) {
+ log.info(new StringBuilder("Component
").append(component.getName()).append(" registered").toString());
+ registeredComponents.add(component.getClassLoader());
+ }
+
+ public static Collection<ClassLoader> getComponents() {
+ return registeredComponents;
+ }
+}
Added:
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/ClerezzaUIMAExtensionClassLoader.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/ClerezzaUIMAExtensionClassLoader.java?rev=1164988&view=auto
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/ClerezzaUIMAExtensionClassLoader.java
(added)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/ClerezzaUIMAExtensionClassLoader.java
Sun Sep 4 10:38:06 2011
@@ -0,0 +1,84 @@
+/*
+ * 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.io.IOException;
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * An extension {@link ClassLoader} to be used as UIMA extension CL within a
+ * {@link org.apache.uima.resource.ResourceManager}. This delegates class
loading to
+ * multiple (underlying) classloaders
+ */
+public class ClerezzaUIMAExtensionClassLoader extends ClassLoader {
+
+ private static final String CLASS = ".class";
+ private static final char POINT = '.';
+ private static final char SLASH = '/';
+
+ private final Collection<ClassLoader> delegateClassLoaders;
+ private final ResourceByteReader byteReader;
+
+ public ClerezzaUIMAExtensionClassLoader(ClassLoader parent) {
+ super(parent);
+ this.delegateClassLoaders =
AnalysisComponentsClassLoaderRepository.getComponents();
+ this.byteReader = new ResourceByteReader();
+ }
+
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
+ String path = new StringBuilder(name.replace(POINT,
SLASH)).append(CLASS).toString();
+ URL url = findResource(path);
+ if (url == null) {
+ throw new ClassNotFoundException(name);
+ }
+ ByteBuffer byteCode;
+ try {
+ byteCode = byteReader.loadResource(url);
+ } catch (IOException e) {
+ throw new ClassNotFoundException(name, e);
+ }
+ return defineClass(name, byteCode, null);
+ }
+
+ protected URL findResource(String name) {
+ URL resource = null;
+ for (ClassLoader delegate : delegateClassLoaders) {
+ resource = delegate.getResource(name);
+ if (resource != null)
+ break;
+ }
+ return resource;
+ }
+
+ protected Enumeration<URL> findResources(String name) throws IOException {
+ Vector<URL> vector = new Vector<URL>();
+ for (ClassLoader delegate : delegateClassLoaders) {
+ Enumeration<URL> enumeration = delegate.getResources(name);
+ while (enumeration.hasMoreElements()) {
+ vector.add(enumeration.nextElement());
+ }
+ }
+ return vector.elements();
+ }
+
+}
\ No newline at end of file
Added:
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/ResourceByteReader.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/ResourceByteReader.java?rev=1164988&view=auto
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/ResourceByteReader.java
(added)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/cl/ResourceByteReader.java
Sun Sep 4 10:38:06 2011
@@ -0,0 +1,64 @@
+/*
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.ByteBuffer;
+
+/**
+ * Reads bytes from an {@link URL} to a {@link ByteBuffer}
+ */
+public class ResourceByteReader {
+
+ public ByteBuffer loadResource(URL url) throws IOException {
+ InputStream stream = null;
+ try {
+ stream = url.openStream();
+ int initialCapacity = Math.min(0x40000, stream.available() + 1);
+ if (initialCapacity <= 2)
+ initialCapacity = 0x10000;
+ else
+ initialCapacity = Math.max(initialCapacity, 0x200);
+ ByteBuffer buffer = ByteBuffer.allocate(initialCapacity);
+ while (true) {
+ if (!buffer.hasRemaining()) {
+ buffer = expandBuffer(buffer);
+ }
+ int len = stream.read(buffer.array(), buffer.position(),
buffer.remaining());
+ if (len <= 0)
+ break;
+ buffer.position(buffer.position() + len);
+ }
+ buffer.flip();
+ return buffer;
+ } finally {
+ if (stream != null) stream.close();
+ }
+ }
+
+ private ByteBuffer expandBuffer(ByteBuffer buffer) {
+ ByteBuffer greaterBuffer = ByteBuffer.allocate(2 * buffer.capacity());
+ buffer.flip();
+ greaterBuffer.put(buffer);
+ buffer = greaterBuffer;
+ return buffer;
+ }
+}
Modified:
incubator/clerezza/trunk/parent/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAExecutorTest.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAExecutorTest.java?rev=1164988&r1=1164987&r2=1164988&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAExecutorTest.java
(original)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAExecutorTest.java
Sun Sep 4 10:38:06 2011
@@ -39,16 +39,6 @@ public class UIMAExecutorTest {
}
@Test
- public void testCLConstructor() {
- try {
- UIMAExecutor uimaExecutor =
UIMAExecutorFactory.getInstance().createUIMAExecutor(this.getClass().getClassLoader());
- assertTrue(uimaExecutor != null);
- } catch (Throwable e) {
- fail(e.getLocalizedMessage());
- }
- }
-
- @Test
public void testPathConstructor() {
try {
UIMAExecutor uimaExecutor =
UIMAExecutorFactory.getInstance().createUIMAExecutor("/META-INF/ExtServicesAE.xml");
@@ -58,14 +48,4 @@ public class UIMAExecutorTest {
}
}
- @Test
- public void testPathCLConstructor() {
- try {
- UIMAExecutor uimaExecutor =
UIMAExecutorFactory.getInstance().createUIMAExecutor(this.getClass().getClassLoader(),
- "/META-INF/ExtServicesAE.xml");
- assertTrue(uimaExecutor != null);
- } catch (Throwable e) {
- fail(e.getLocalizedMessage());
- }
- }
}