You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2013/01/11 00:12:37 UTC
svn commit: r1431721 [4/19] - in /uima/sandbox/uimafit/trunk:
uimafit-examples/src/main/java/org/apache/uima/fit/examples/experiment/pos/
uimafit-examples/src/main/java/org/apache/uima/fit/examples/getstarted/
uimafit-examples/src/main/java/org/apache/...
Modified: uima/sandbox/uimafit/trunk/uimafit-spring/src/test/java/org/apache/uima/fit/spring/UimaFactoryInjectionTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-spring/src/test/java/org/apache/uima/fit/spring/UimaFactoryInjectionTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-spring/src/test/java/org/apache/uima/fit/spring/UimaFactoryInjectionTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-spring/src/test/java/org/apache/uima/fit/spring/UimaFactoryInjectionTest.java Thu Jan 10 23:12:33 2013
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.uima.fit.spring;
import static org.apache.uima.fit.factory.AnalysisEngineFactory.createPrimitive;
@@ -50,77 +49,73 @@ import org.springframework.context.suppo
/**
* Test reconfiguring the UIMA framework so that an additional Spring initialization is applied
* after the UIMA initialization. This allows regular annotation-based Spring dependency injection.
- *
+ *
*/
@SuppressWarnings("deprecation")
public class UimaFactoryInjectionTest {
- @Test
- public void test() throws Exception {
- // Acquire application context
- ApplicationContext ctx = getApplicationContext();
-
- // Configure UIMA for this context
- initUimaApplicationContext(ctx);
-
- // Instantiate component
- AnalysisEngine ae = createPrimitive(MyAnalysisEngine.class);
-
- // Test that injection works
- ae.process(ae.newJCas());
- }
-
- public static class MyAnalysisEngine extends JCasAnnotator_ImplBase {
- @Autowired @Qualifier("otherBean")
- private Object injectedBean;
-
- @Override
- public void process(JCas aJCas) throws AnalysisEngineProcessException {
- assertEquals("BEAN", injectedBean);
- }
- }
-
- private ApplicationContext getApplicationContext() {
- final GenericApplicationContext ctx = new GenericApplicationContext();
- AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
- ctx.registerBeanDefinition("otherBean",
- BeanDefinitionBuilder.genericBeanDefinition(String.class)
- .addConstructorArgValue("BEAN").getBeanDefinition());
-
- ctx.registerBeanDefinition("analysisEngineFactory",
- BeanDefinitionBuilder.genericBeanDefinition(AnalysisEngineFactory_impl.class)
- .getBeanDefinition());
- ctx.registerBeanDefinition("casConsumerFactory",
- BeanDefinitionBuilder.genericBeanDefinition(CasConsumerFactory_impl.class)
- .getBeanDefinition());
- ctx.registerBeanDefinition("casInitializerFactory",
- BeanDefinitionBuilder.genericBeanDefinition(CasInitializerFactory_impl.class)
- .getBeanDefinition());
- ctx.registerBeanDefinition("collectionReaderFactory",
- BeanDefinitionBuilder.genericBeanDefinition(CollectionReaderFactory_impl.class)
- .getBeanDefinition());
- ctx.registerBeanDefinition("customResourceFactory",
- BeanDefinitionBuilder.genericBeanDefinition(CustomResourceFactory_impl.class)
- .getBeanDefinition());
- ctx.refresh();
- return ctx;
- }
-
- private static void initUimaApplicationContext(final ApplicationContext aApplicationContext)
- {
- new UIMAFramework_impl() {
- {
- CompositeResourceFactory_impl factory = (CompositeResourceFactory_impl) getResourceFactory();
- factory.registerFactory(CasConsumerDescription.class,
- aApplicationContext.getBean(CasConsumerFactory_impl.class));
- factory.registerFactory(CasInitializerDescription.class,
- aApplicationContext.getBean(CasInitializerFactory_impl.class));
- factory.registerFactory(CollectionReaderDescription.class,
- aApplicationContext.getBean(CollectionReaderFactory_impl.class));
- factory.registerFactory(ResourceCreationSpecifier.class,
- aApplicationContext.getBean(AnalysisEngineFactory_impl.class));
- factory.registerFactory(CustomResourceSpecifier.class,
- aApplicationContext.getBean(CustomResourceFactory_impl.class));
- }
- };
- }
+ @Test
+ public void test() throws Exception {
+ // Acquire application context
+ ApplicationContext ctx = getApplicationContext();
+
+ // Configure UIMA for this context
+ initUimaApplicationContext(ctx);
+
+ // Instantiate component
+ AnalysisEngine ae = createPrimitive(MyAnalysisEngine.class);
+
+ // Test that injection works
+ ae.process(ae.newJCas());
+ }
+
+ public static class MyAnalysisEngine extends JCasAnnotator_ImplBase {
+ @Autowired
+ @Qualifier("otherBean")
+ private Object injectedBean;
+
+ @Override
+ public void process(JCas aJCas) throws AnalysisEngineProcessException {
+ assertEquals("BEAN", injectedBean);
+ }
+ }
+
+ private ApplicationContext getApplicationContext() {
+ final GenericApplicationContext ctx = new GenericApplicationContext();
+ AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
+ ctx.registerBeanDefinition("otherBean",
+ BeanDefinitionBuilder.genericBeanDefinition(String.class)
+ .addConstructorArgValue("BEAN").getBeanDefinition());
+
+ ctx.registerBeanDefinition("analysisEngineFactory", BeanDefinitionBuilder
+ .genericBeanDefinition(AnalysisEngineFactory_impl.class).getBeanDefinition());
+ ctx.registerBeanDefinition("casConsumerFactory",
+ BeanDefinitionBuilder.genericBeanDefinition(CasConsumerFactory_impl.class)
+ .getBeanDefinition());
+ ctx.registerBeanDefinition("casInitializerFactory", BeanDefinitionBuilder
+ .genericBeanDefinition(CasInitializerFactory_impl.class).getBeanDefinition());
+ ctx.registerBeanDefinition("collectionReaderFactory", BeanDefinitionBuilder
+ .genericBeanDefinition(CollectionReaderFactory_impl.class).getBeanDefinition());
+ ctx.registerBeanDefinition("customResourceFactory", BeanDefinitionBuilder
+ .genericBeanDefinition(CustomResourceFactory_impl.class).getBeanDefinition());
+ ctx.refresh();
+ return ctx;
+ }
+
+ private static void initUimaApplicationContext(final ApplicationContext aApplicationContext) {
+ new UIMAFramework_impl() {
+ {
+ CompositeResourceFactory_impl factory = (CompositeResourceFactory_impl) getResourceFactory();
+ factory.registerFactory(CasConsumerDescription.class,
+ aApplicationContext.getBean(CasConsumerFactory_impl.class));
+ factory.registerFactory(CasInitializerDescription.class,
+ aApplicationContext.getBean(CasInitializerFactory_impl.class));
+ factory.registerFactory(CollectionReaderDescription.class,
+ aApplicationContext.getBean(CollectionReaderFactory_impl.class));
+ factory.registerFactory(ResourceCreationSpecifier.class,
+ aApplicationContext.getBean(AnalysisEngineFactory_impl.class));
+ factory.registerFactory(CustomResourceSpecifier.class,
+ aApplicationContext.getBean(CustomResourceFactory_impl.class));
+ }
+ };
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasAnnotator_ImplBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasAnnotator_ImplBase.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasAnnotator_ImplBase.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasAnnotator_ImplBase.java Thu Jan 10 23:12:33 2013
@@ -27,23 +27,23 @@ import org.apache.uima.resource.Resource
/**
* Base class for CAS annotators which initializes itself based on annotations.
- *
+ *
*/
public abstract class CasAnnotator_ImplBase extends
- org.apache.uima.analysis_component.CasAnnotator_ImplBase {
- private ExtendedLogger logger;
-
- public ExtendedLogger getLogger() {
- if (logger == null) {
- logger = new ExtendedLogger(getContext());
- }
- return logger;
- }
-
- @Override
- public void initialize(final UimaContext context) throws ResourceInitializationException {
- super.initialize(context);
- ConfigurationParameterInitializer.initialize(this, context);
- ExternalResourceInitializer.initialize(context, this);
- }
+ org.apache.uima.analysis_component.CasAnnotator_ImplBase {
+ private ExtendedLogger logger;
+
+ public ExtendedLogger getLogger() {
+ if (logger == null) {
+ logger = new ExtendedLogger(getContext());
+ }
+ return logger;
+ }
+
+ @Override
+ public void initialize(final UimaContext context) throws ResourceInitializationException {
+ super.initialize(context);
+ ConfigurationParameterInitializer.initialize(this, context);
+ ExternalResourceInitializer.initialize(context, this);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasCollectionReader_ImplBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasCollectionReader_ImplBase.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasCollectionReader_ImplBase.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasCollectionReader_ImplBase.java Thu Jan 10 23:12:33 2013
@@ -30,36 +30,36 @@ import org.apache.uima.resource.Resource
/**
* Base class for CAS collection readers which initializes itself based on annotations.
- *
+ *
*/
-@OperationalProperties(outputsNewCases=true)
+@OperationalProperties(outputsNewCases = true)
public abstract class CasCollectionReader_ImplBase extends CollectionReader_ImplBase {
- private ExtendedLogger logger;
-
- @Override
- public ExtendedLogger getLogger() {
- if (logger == null) {
- logger = new ExtendedLogger(getUimaContext());
- }
- return logger;
- }
-
- @Override
- // This method should not be overwritten. Overwrite initialize(UimaContext) instead.
- public final void initialize() throws ResourceInitializationException {
- ConfigurationParameterInitializer.initialize(this, getUimaContext());
- ExternalResourceInitializer.initialize(getUimaContext(), this);
- initialize(getUimaContext());
- }
+ private ExtendedLogger logger;
- /**
- * This method should be overwritten by subclasses.
- */
- public void initialize(final UimaContext context) throws ResourceInitializationException {
- // Nothing by default
- }
+ @Override
+ public ExtendedLogger getLogger() {
+ if (logger == null) {
+ logger = new ExtendedLogger(getUimaContext());
+ }
+ return logger;
+ }
- public void close() throws IOException {
- // Nothing by default
- }
+ @Override
+ // This method should not be overwritten. Overwrite initialize(UimaContext) instead.
+ public final void initialize() throws ResourceInitializationException {
+ ConfigurationParameterInitializer.initialize(this, getUimaContext());
+ ExternalResourceInitializer.initialize(getUimaContext(), this);
+ initialize(getUimaContext());
+ }
+
+ /**
+ * This method should be overwritten by subclasses.
+ */
+ public void initialize(final UimaContext context) throws ResourceInitializationException {
+ // Nothing by default
+ }
+
+ public void close() throws IOException {
+ // Nothing by default
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasConsumer_ImplBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasConsumer_ImplBase.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasConsumer_ImplBase.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasConsumer_ImplBase.java Thu Jan 10 23:12:33 2013
@@ -33,20 +33,20 @@ import org.apache.uima.resource.Resource
*/
@OperationalProperties(multipleDeploymentAllowed = false)
public abstract class CasConsumer_ImplBase extends
- org.apache.uima.analysis_component.CasAnnotator_ImplBase {
- private ExtendedLogger logger;
-
- public ExtendedLogger getLogger() {
- if (logger == null) {
- logger = new ExtendedLogger(getContext());
- }
- return logger;
- }
-
- @Override
- public void initialize(final UimaContext context) throws ResourceInitializationException {
- super.initialize(context);
- ConfigurationParameterInitializer.initialize(this, context);
- ExternalResourceInitializer.initialize(context, this);
- }
+ org.apache.uima.analysis_component.CasAnnotator_ImplBase {
+ private ExtendedLogger logger;
+
+ public ExtendedLogger getLogger() {
+ if (logger == null) {
+ logger = new ExtendedLogger(getContext());
+ }
+ return logger;
+ }
+
+ @Override
+ public void initialize(final UimaContext context) throws ResourceInitializationException {
+ super.initialize(context);
+ ConfigurationParameterInitializer.initialize(this, context);
+ ExternalResourceInitializer.initialize(context, this);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasFlowController_ImplBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasFlowController_ImplBase.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasFlowController_ImplBase.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasFlowController_ImplBase.java Thu Jan 10 23:12:33 2013
@@ -28,21 +28,21 @@ import org.apache.uima.resource.Resource
*/
public abstract class CasFlowController_ImplBase extends
- org.apache.uima.flow.CasFlowController_ImplBase {
- private ExtendedLogger logger;
-
- public ExtendedLogger getLogger() {
- if (logger == null) {
- logger = new ExtendedLogger(getContext());
- }
- return logger;
- }
-
- @Override
- public void initialize(final FlowControllerContext context)
- throws ResourceInitializationException {
- super.initialize(context);
- ConfigurationParameterInitializer.initialize(this, context);
- ExternalResourceInitializer.initialize(context, this);
- }
+ org.apache.uima.flow.CasFlowController_ImplBase {
+ private ExtendedLogger logger;
+
+ public ExtendedLogger getLogger() {
+ if (logger == null) {
+ logger = new ExtendedLogger(getContext());
+ }
+ return logger;
+ }
+
+ @Override
+ public void initialize(final FlowControllerContext context)
+ throws ResourceInitializationException {
+ super.initialize(context);
+ ConfigurationParameterInitializer.initialize(this, context);
+ ExternalResourceInitializer.initialize(context, this);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasMultiplier_ImplBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasMultiplier_ImplBase.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasMultiplier_ImplBase.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/CasMultiplier_ImplBase.java Thu Jan 10 23:12:33 2013
@@ -27,24 +27,24 @@ import org.apache.uima.resource.Resource
/**
* Base class for a CAS multiplier which initializes itself based on annotations.
- *
+ *
*/
@OperationalProperties(outputsNewCases = true)
public abstract class CasMultiplier_ImplBase extends
- org.apache.uima.analysis_component.CasMultiplier_ImplBase {
- private ExtendedLogger logger;
-
- public ExtendedLogger getLogger() {
- if (logger == null) {
- logger = new ExtendedLogger(getContext());
- }
- return logger;
- }
-
- @Override
- public void initialize(final UimaContext context) throws ResourceInitializationException {
- super.initialize(context);
- ConfigurationParameterInitializer.initialize(this, context);
- ExternalResourceInitializer.initialize(context, this);
- }
+ org.apache.uima.analysis_component.CasMultiplier_ImplBase {
+ private ExtendedLogger logger;
+
+ public ExtendedLogger getLogger() {
+ if (logger == null) {
+ logger = new ExtendedLogger(getContext());
+ }
+ return logger;
+ }
+
+ @Override
+ public void initialize(final UimaContext context) throws ResourceInitializationException {
+ super.initialize(context);
+ ConfigurationParameterInitializer.initialize(this, context);
+ ExternalResourceInitializer.initialize(context, this);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/ExternalResourceAware.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/ExternalResourceAware.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/ExternalResourceAware.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/ExternalResourceAware.java Thu Jan 10 23:12:33 2013
@@ -22,27 +22,25 @@ import org.apache.uima.fit.descriptor.Ex
import org.apache.uima.fit.factory.ExternalResourceFactory;
/**
- * Allows an external resource to use the {@link ExternalResource} annotation on member variables
- * to gain access to other external resources.
+ * Allows an external resource to use the {@link ExternalResource} annotation on member variables to
+ * gain access to other external resources.
*
*/
public interface ExternalResourceAware {
- /**
- * Get the name of the resource. This is set by {@link
- * ExternalResourceFactory#bindExternalResource(org.apache.uima.resource.ResourceCreationSpecifier,
- * String, org.apache.uima.resource.ExternalResourceDescription) bindExternalResource()} as the
- * parameter {@link ExternalResourceFactory#PARAM_RESOURCE_NAME PARAM_RESOURCE_NAME}.
- * <br/>
- * <b>It is mandatory that any resource implementing this interface declares the configuration
- * parameter {@link ExternalResourceFactory#PARAM_RESOURCE_NAME PARAM_RESOURCE_NAME}.</b>
- *
- * @return the resource name.
- */
- String getResourceName();
-
-
- /**
- * Called after the external resources have been initialized.
- */
- void afterResourcesInitialized();
+ /**
+ * Get the name of the resource. This is set by
+ * {@link ExternalResourceFactory#bindExternalResource(org.apache.uima.resource.ResourceCreationSpecifier, String, org.apache.uima.resource.ExternalResourceDescription)
+ * bindExternalResource()} as the parameter {@link ExternalResourceFactory#PARAM_RESOURCE_NAME
+ * PARAM_RESOURCE_NAME}. <br/>
+ * <b>It is mandatory that any resource implementing this interface declares the configuration
+ * parameter {@link ExternalResourceFactory#PARAM_RESOURCE_NAME PARAM_RESOURCE_NAME}.</b>
+ *
+ * @return the resource name.
+ */
+ String getResourceName();
+
+ /**
+ * Called after the external resources have been initialized.
+ */
+ void afterResourcesInitialized();
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasAnnotator_ImplBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasAnnotator_ImplBase.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasAnnotator_ImplBase.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasAnnotator_ImplBase.java Thu Jan 10 23:12:33 2013
@@ -26,23 +26,23 @@ import org.apache.uima.resource.Resource
/**
* Base class for JCas annotators which initializes itself based on annotations.
- *
+ *
*/
public abstract class JCasAnnotator_ImplBase extends
- org.apache.uima.analysis_component.JCasAnnotator_ImplBase {
- private ExtendedLogger logger;
-
- public ExtendedLogger getLogger() {
- if (logger == null) {
- logger = new ExtendedLogger(getContext());
- }
- return logger;
- }
-
- @Override
- public void initialize(final UimaContext context) throws ResourceInitializationException {
- super.initialize(context);
- ConfigurationParameterInitializer.initialize(this, context);
- ExternalResourceInitializer.initialize(context, this);
- }
+ org.apache.uima.analysis_component.JCasAnnotator_ImplBase {
+ private ExtendedLogger logger;
+
+ public ExtendedLogger getLogger() {
+ if (logger == null) {
+ logger = new ExtendedLogger(getContext());
+ }
+ return logger;
+ }
+
+ @Override
+ public void initialize(final UimaContext context) throws ResourceInitializationException {
+ super.initialize(context);
+ ConfigurationParameterInitializer.initialize(this, context);
+ ExternalResourceInitializer.initialize(context, this);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasCollectionReader_ImplBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasCollectionReader_ImplBase.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasCollectionReader_ImplBase.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasCollectionReader_ImplBase.java Thu Jan 10 23:12:33 2013
@@ -34,51 +34,50 @@ import org.apache.uima.resource.Resource
/**
* Base class for JCas collection readers which initializes itself based on annotations.
- *
+ *
*/
-@OperationalProperties(outputsNewCases=true)
+@OperationalProperties(outputsNewCases = true)
public abstract class JCasCollectionReader_ImplBase extends CollectionReader_ImplBase {
- private ExtendedLogger logger;
-
- @Override
- public ExtendedLogger getLogger() {
- if (logger == null) {
- logger = new ExtendedLogger(getUimaContext());
- }
- return logger;
- }
-
- // This method should not be overwritten. Overwrite initialize(UimaContext) instead.
- @Override
- public final void initialize() throws ResourceInitializationException {
- ConfigurationParameterInitializer.initialize(this, getUimaContext());
- ExternalResourceInitializer.initialize(getUimaContext(), this);
- initialize(getUimaContext());
- }
-
- /**
- * This method should be overwritten by subclasses.
- */
- public void initialize(final UimaContext context) throws ResourceInitializationException {
- // Nothing by default
- }
-
- // This method should not be overwritten. Overwrite getNext(JCas) instead.
- public final void getNext(final CAS cas) throws IOException, CollectionException {
- try {
- getNext(cas.getJCas());
- }
- catch (CASException e) {
- throw new CollectionException(e);
- }
- }
-
- /**
- * Subclasses should implement this method rather than {@link #getNext(CAS)}
- */
- public abstract void getNext(JCas jCas) throws IOException, CollectionException;
-
- public void close() throws IOException {
- // Do nothing per default
- }
+ private ExtendedLogger logger;
+
+ @Override
+ public ExtendedLogger getLogger() {
+ if (logger == null) {
+ logger = new ExtendedLogger(getUimaContext());
+ }
+ return logger;
+ }
+
+ // This method should not be overwritten. Overwrite initialize(UimaContext) instead.
+ @Override
+ public final void initialize() throws ResourceInitializationException {
+ ConfigurationParameterInitializer.initialize(this, getUimaContext());
+ ExternalResourceInitializer.initialize(getUimaContext(), this);
+ initialize(getUimaContext());
+ }
+
+ /**
+ * This method should be overwritten by subclasses.
+ */
+ public void initialize(final UimaContext context) throws ResourceInitializationException {
+ // Nothing by default
+ }
+
+ // This method should not be overwritten. Overwrite getNext(JCas) instead.
+ public final void getNext(final CAS cas) throws IOException, CollectionException {
+ try {
+ getNext(cas.getJCas());
+ } catch (CASException e) {
+ throw new CollectionException(e);
+ }
+ }
+
+ /**
+ * Subclasses should implement this method rather than {@link #getNext(CAS)}
+ */
+ public abstract void getNext(JCas jCas) throws IOException, CollectionException;
+
+ public void close() throws IOException {
+ // Do nothing per default
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasConsumer_ImplBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasConsumer_ImplBase.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasConsumer_ImplBase.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasConsumer_ImplBase.java Thu Jan 10 23:12:33 2013
@@ -29,24 +29,24 @@ import org.apache.uima.resource.Resource
* Base class for JCas consumers (actually a
* {@link org.apache.uima.analysis_component.JCasAnnotator_ImplBase}) which initializes itself based
* on annotations.
- *
+ *
*/
@OperationalProperties(multipleDeploymentAllowed = false)
public abstract class JCasConsumer_ImplBase extends
- org.apache.uima.analysis_component.JCasAnnotator_ImplBase {
- private ExtendedLogger logger;
-
- public ExtendedLogger getLogger() {
- if (logger == null) {
- logger = new ExtendedLogger(getContext());
- }
- return logger;
- }
-
- @Override
- public void initialize(final UimaContext context) throws ResourceInitializationException {
- super.initialize(context);
- ConfigurationParameterInitializer.initialize(this, context);
- ExternalResourceInitializer.initialize(context, this);
- }
+ org.apache.uima.analysis_component.JCasAnnotator_ImplBase {
+ private ExtendedLogger logger;
+
+ public ExtendedLogger getLogger() {
+ if (logger == null) {
+ logger = new ExtendedLogger(getContext());
+ }
+ return logger;
+ }
+
+ @Override
+ public void initialize(final UimaContext context) throws ResourceInitializationException {
+ super.initialize(context);
+ ConfigurationParameterInitializer.initialize(this, context);
+ ExternalResourceInitializer.initialize(context, this);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasFlowController_ImplBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasFlowController_ImplBase.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasFlowController_ImplBase.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasFlowController_ImplBase.java Thu Jan 10 23:12:33 2013
@@ -28,20 +28,21 @@ import org.apache.uima.resource.Resource
*/
public abstract class JCasFlowController_ImplBase extends
- org.apache.uima.flow.JCasFlowController_ImplBase {
- private ExtendedLogger logger;
-
- public ExtendedLogger getLogger() {
- if (logger == null) {
- logger = new ExtendedLogger(getContext());
- }
- return logger;
- }
-
- @Override
- public void initialize(final FlowControllerContext context) throws ResourceInitializationException {
- super.initialize(context);
- ConfigurationParameterInitializer.initialize(this, context);
- ExternalResourceInitializer.initialize(context, this);
- }
+ org.apache.uima.flow.JCasFlowController_ImplBase {
+ private ExtendedLogger logger;
+
+ public ExtendedLogger getLogger() {
+ if (logger == null) {
+ logger = new ExtendedLogger(getContext());
+ }
+ return logger;
+ }
+
+ @Override
+ public void initialize(final FlowControllerContext context)
+ throws ResourceInitializationException {
+ super.initialize(context);
+ ConfigurationParameterInitializer.initialize(this, context);
+ ExternalResourceInitializer.initialize(context, this);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasMultiplier_ImplBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasMultiplier_ImplBase.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasMultiplier_ImplBase.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/JCasMultiplier_ImplBase.java Thu Jan 10 23:12:33 2013
@@ -27,24 +27,24 @@ import org.apache.uima.resource.Resource
/**
* Base class for a JCas multiplier which initializes itself based on annotations.
- *
+ *
*/
@OperationalProperties(outputsNewCases = true)
public abstract class JCasMultiplier_ImplBase extends
- org.apache.uima.analysis_component.JCasMultiplier_ImplBase {
- private ExtendedLogger logger;
-
- public ExtendedLogger getLogger() {
- if (logger == null) {
- logger = new ExtendedLogger(getContext());
- }
- return logger;
- }
-
- @Override
- public void initialize(final UimaContext context) throws ResourceInitializationException {
- super.initialize(context);
- ConfigurationParameterInitializer.initialize(this, context);
- ExternalResourceInitializer.initialize(context, this);
- }
+ org.apache.uima.analysis_component.JCasMultiplier_ImplBase {
+ private ExtendedLogger logger;
+
+ public ExtendedLogger getLogger() {
+ if (logger == null) {
+ logger = new ExtendedLogger(getContext());
+ }
+ return logger;
+ }
+
+ @Override
+ public void initialize(final UimaContext context) throws ResourceInitializationException {
+ super.initialize(context);
+ ConfigurationParameterInitializer.initialize(this, context);
+ ExternalResourceInitializer.initialize(context, this);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/NoOpAnnotator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/NoOpAnnotator.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/NoOpAnnotator.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/NoOpAnnotator.java Thu Jan 10 23:12:33 2013
@@ -23,11 +23,11 @@ import org.apache.uima.cas.CAS;
/**
* No-operation annotator. This annotator performs no operation whatsoever.
- *
+ *
*/
public class NoOpAnnotator extends CasAnnotator_ImplBase {
- @Override
- public void process(final CAS aCAS) throws AnalysisEngineProcessException {
- // Do nothing at all
- }
+ @Override
+ public void process(final CAS aCAS) throws AnalysisEngineProcessException {
+ // Do nothing at all
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/Resource_ImplBase.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/Resource_ImplBase.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/Resource_ImplBase.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/Resource_ImplBase.java Thu Jan 10 23:12:33 2013
@@ -29,45 +29,45 @@ import org.apache.uima.resource.Resource
/**
* Base class for external resources which initializes itself based on annotations.
- *
+ *
*/
public abstract class Resource_ImplBase extends org.apache.uima.resource.Resource_ImplBase
- implements ExternalResourceAware {
+ implements ExternalResourceAware {
- private ExtendedLogger logger;
-
- @ConfigurationParameter(name=ExternalResourceFactory.PARAM_RESOURCE_NAME, mandatory=false)
- private String resourceName;
-
- @Override
- public ExtendedLogger getLogger() {
- if (logger == null) {
- logger = new ExtendedLogger(getUimaContext());
- }
- return logger;
- }
-
- @Override
- public boolean initialize(final ResourceSpecifier aSpecifier,
- final Map<String, Object> aAdditionalParams) throws ResourceInitializationException {
- if (!super.initialize(aSpecifier, aAdditionalParams)) {
- return false;
- }
-
- ConfigurationParameterInitializer.initialize(this, aSpecifier);
- // We cannot call ExternalResourceInitializer.initialize() because the
- // ResourceManager_impl has not added the resources to the context yet.
- // Resource initialization is handled by ExternalResourceInitializer.initialize()
- // when it is called on the first pipeline component.
-
- return true;
- }
-
- public String getResourceName() {
- return resourceName;
- }
-
- public void afterResourcesInitialized() {
- // Per default nothing is done here.
- }
+ private ExtendedLogger logger;
+
+ @ConfigurationParameter(name = ExternalResourceFactory.PARAM_RESOURCE_NAME, mandatory = false)
+ private String resourceName;
+
+ @Override
+ public ExtendedLogger getLogger() {
+ if (logger == null) {
+ logger = new ExtendedLogger(getUimaContext());
+ }
+ return logger;
+ }
+
+ @Override
+ public boolean initialize(final ResourceSpecifier aSpecifier,
+ final Map<String, Object> aAdditionalParams) throws ResourceInitializationException {
+ if (!super.initialize(aSpecifier, aAdditionalParams)) {
+ return false;
+ }
+
+ ConfigurationParameterInitializer.initialize(this, aSpecifier);
+ // We cannot call ExternalResourceInitializer.initialize() because the
+ // ResourceManager_impl has not added the resources to the context yet.
+ // Resource initialization is handled by ExternalResourceInitializer.initialize()
+ // when it is called on the first pipeline component.
+
+ return true;
+ }
+
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ public void afterResourcesInitialized() {
+ // Per default nothing is done here.
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/ViewCreatorAnnotator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/ViewCreatorAnnotator.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/ViewCreatorAnnotator.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/ViewCreatorAnnotator.java Thu Jan 10 23:12:33 2013
@@ -39,40 +39,38 @@ import org.apache.uima.jcas.JCas;
*/
public class ViewCreatorAnnotator extends JCasAnnotator_ImplBase {
- /**
- * The parameter name for the name of the viewed to be created by this annotator
- */
- public static final String PARAM_VIEW_NAME = ConfigurationParameterFactory
- .createConfigurationParameterName(ViewCreatorAnnotator.class, "viewName");
+ /**
+ * The parameter name for the name of the viewed to be created by this annotator
+ */
+ public static final String PARAM_VIEW_NAME = ConfigurationParameterFactory
+ .createConfigurationParameterName(ViewCreatorAnnotator.class, "viewName");
- @ConfigurationParameter(mandatory = true)
- private String viewName;
+ @ConfigurationParameter(mandatory = true)
+ private String viewName;
- @Override
- public void process(final JCas aJCas) throws AnalysisEngineProcessException {
- createViewSafely(aJCas, viewName);
- }
+ @Override
+ public void process(final JCas aJCas) throws AnalysisEngineProcessException {
+ createViewSafely(aJCas, viewName);
+ }
- /**
- * Provides a simple call that allows you to safely create a view if it has not been created
- * yet. If the view already exists, it is ok to call this method anyways without worrying about
- * checking for this yet.
- *
- * @return true if the view was created as a result of calling this method. false if the view
- * already existed.
- */
- public static JCas createViewSafely(final JCas aJCas, final String aViewName)
- throws AnalysisEngineProcessException {
- try {
- try {
- return aJCas.getView(aViewName);
- }
- catch (CASRuntimeException ce) {
- return aJCas.createView(aViewName);
- }
- }
- catch (CASException ce) {
- throw new AnalysisEngineProcessException(ce);
- }
- }
+ /**
+ * Provides a simple call that allows you to safely create a view if it has not been created yet.
+ * If the view already exists, it is ok to call this method anyways without worrying about
+ * checking for this yet.
+ *
+ * @return true if the view was created as a result of calling this method. false if the view
+ * already existed.
+ */
+ public static JCas createViewSafely(final JCas aJCas, final String aViewName)
+ throws AnalysisEngineProcessException {
+ try {
+ try {
+ return aJCas.getView(aViewName);
+ } catch (CASRuntimeException ce) {
+ return aJCas.createView(aViewName);
+ }
+ } catch (CASException ce) {
+ throw new AnalysisEngineProcessException(ce);
+ }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/ViewTextCopierAnnotator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/ViewTextCopierAnnotator.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/ViewTextCopierAnnotator.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/ViewTextCopierAnnotator.java Thu Jan 10 23:12:33 2013
@@ -39,40 +39,38 @@ import org.apache.uima.jcas.JCas;
public class ViewTextCopierAnnotator extends JCasAnnotator_ImplBase {
- /**
- * The parameter name for the name of the source view
- */
- public static final String PARAM_SOURCE_VIEW_NAME = ConfigurationParameterFactory
- .createConfigurationParameterName(ViewTextCopierAnnotator.class, "sourceViewName");
-
- @ConfigurationParameter(mandatory = true)
- private String sourceViewName;
-
- /**
- * The parameter name for the name of the destination view
- */
- public static final String PARAM_DESTINATION_VIEW_NAME = ConfigurationParameterFactory
- .createConfigurationParameterName(ViewTextCopierAnnotator.class, "destinationViewName");
-
- @ConfigurationParameter(mandatory = true)
- private String destinationViewName;
-
- @Override
- public void process(final JCas jCas) throws AnalysisEngineProcessException {
- try {
- final JCas sourceView = jCas.getView(sourceViewName);
- JCas destinationView;
- try {
- destinationView = jCas.getView(destinationViewName);
- }
- catch (CASRuntimeException ce) {
- destinationView = jCas.createView(destinationViewName);
- }
- destinationView.setDocumentText(sourceView.getDocumentText());
- }
- catch (CASException e) {
- throw new AnalysisEngineProcessException(e);
- }
- }
+ /**
+ * The parameter name for the name of the source view
+ */
+ public static final String PARAM_SOURCE_VIEW_NAME = ConfigurationParameterFactory
+ .createConfigurationParameterName(ViewTextCopierAnnotator.class, "sourceViewName");
+
+ @ConfigurationParameter(mandatory = true)
+ private String sourceViewName;
+
+ /**
+ * The parameter name for the name of the destination view
+ */
+ public static final String PARAM_DESTINATION_VIEW_NAME = ConfigurationParameterFactory
+ .createConfigurationParameterName(ViewTextCopierAnnotator.class, "destinationViewName");
+
+ @ConfigurationParameter(mandatory = true)
+ private String destinationViewName;
+
+ @Override
+ public void process(final JCas jCas) throws AnalysisEngineProcessException {
+ try {
+ final JCas sourceView = jCas.getView(sourceViewName);
+ JCas destinationView;
+ try {
+ destinationView = jCas.getView(destinationViewName);
+ } catch (CASRuntimeException ce) {
+ destinationView = jCas.createView(destinationViewName);
+ }
+ destinationView.setDocumentText(sourceView.getDocumentText());
+ } catch (CASException e) {
+ throw new AnalysisEngineProcessException(e);
+ }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/initialize/ConfigurationParameterInitializer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/initialize/ConfigurationParameterInitializer.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/initialize/ConfigurationParameterInitializer.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/main/java/org/apache/uima/fit/component/initialize/ConfigurationParameterInitializer.java Thu Jan 10 23:12:33 2013
@@ -49,436 +49,449 @@ import org.springframework.validation.Da
import org.springframework.validation.ObjectError;
/**
- * <p>Initialize an instance of a class with fields that are annotated as
- * {@link ConfigurationParameter}s from the parameter values given in a {@link UimaContext}.</p>
- *
+ * <p>
+ * Initialize an instance of a class with fields that are annotated as
+ * {@link ConfigurationParameter}s from the parameter values given in a {@link UimaContext}.
+ * </p>
+ *
*/
public final class ConfigurationParameterInitializer {
- private ConfigurationParameterInitializer() {
- // Utility class
- }
-
- /**
- * Initialize a component from an {@link UimaContext} This code can be a little confusing
- * because the configuration parameter annotations are used in two contexts: in describing the
- * component and to initialize member variables from a {@link UimaContext}. Here we are
- * performing the latter task. It is important to remember that the {@link UimaContext} passed
- * in to this method may or may not have been derived using reflection of the annotations (i.e.
- * using {@link ConfigurationParameterFactory} via e.g. a call to a AnalysisEngineFactory.create
- * method). It is just as possible for the description of the component to come directly from an
- * XML descriptor file. So, for example, just because a configuration parameter specifies a
- * default value, this does not mean that the passed in context will have a value for that
- * configuration parameter. It should be possible for a descriptor file to specify its own value
- * or to not provide one at all. If the context does not have a configuration parameter, then
- * the default value provided by the developer as specified by the defaultValue element of the
- * {@link ConfigurationParameter} will be used. See comments in the code for additional details.
- *
- * @param component the component to initialize.
- * @param context a UIMA context with configuration parameters.
- */
- public static void initialize(final Object component, final UimaContext context)
- throws ResourceInitializationException {
- MutablePropertyValues values = new MutablePropertyValues();
- List<String> mandatoryValues = new ArrayList<String>();
-
- for (Field field : ReflectionUtil.getFields(component)) { // component.getClass().getDeclaredFields())
- if (ConfigurationParameterFactory.isConfigurationParameterField(field)) {
- org.apache.uima.fit.descriptor.ConfigurationParameter annotation = field
- .getAnnotation(org.apache.uima.fit.descriptor.ConfigurationParameter.class);
-
- Object parameterValue;
- String parameterName = ConfigurationParameterFactory
- .getConfigurationParameterName(field);
-
- // Obtain either from the context - or - if the context does not provide the
- // parameter, check if there is a default value. Note there are three possibilities:
- // 1) Parameter present and set
- // 2) Parameter present and set to null (null value)
- // 3) Parameter not present (also provided as null value by UIMA)
- // Unfortunately we cannot make a difference between case 2 and 3 since UIMA does
- // not allow us to actually get a list of the parameters set in the context. We can
- // only get a list of the declared parameters. Thus we have to rely on the null
- // value.
- parameterValue = context.getConfigParameterValue(parameterName);
- if (parameterValue == null) {
- parameterValue = ConfigurationParameterFactory.getDefaultValue(field);
- }
-
- if (parameterValue != null) {
- values.addPropertyValue(field.getName(), parameterValue);
- }
-
- // TODO does this check really belong here? It seems that
- // this check is already performed by UIMA
- if (annotation.mandatory()) {
- mandatoryValues.add(field.getName());
-
-// if (parameterValue == null) {
-// final String key = ResourceInitializationException.CONFIG_SETTING_ABSENT;
-// throw new ResourceInitializationException(key,
-// new Object[] { configurationParameterName });
-// }
- }
-// else {
-// if (parameterValue == null) {
-// continue;
-// }
-// }
-// final Object fieldValue = convertValue(field, parameterValue);
-// try {
-// setParameterValue(component, field, fieldValue);
-// }
-// catch (Exception e) {
-// throw new ResourceInitializationException(e);
-// }
- }
- }
-
- DataBinder binder = new DataBinder(component) {
- @Override
- protected void checkRequiredFields(MutablePropertyValues mpvs) {
- String[] requiredFields = getRequiredFields();
- if (!ObjectUtils.isEmpty(requiredFields)) {
- Map<String, PropertyValue> propertyValues = new HashMap<String, PropertyValue>();
- PropertyValue[] pvs = mpvs.getPropertyValues();
- for (PropertyValue pv : pvs) {
- String canonicalName = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
- propertyValues.put(canonicalName, pv);
- }
- for (String field : requiredFields) {
- PropertyValue pv = propertyValues.get(field);
- boolean empty = (pv == null || pv.getValue() == null);
- // For our purposes, empty Strings or empty String arrays do not count as
- // empty. Empty is only "null".
-// if (!empty) {
-// if (pv.getValue() instanceof String) {
-// empty = !StringUtils.hasText((String) pv.getValue());
-// }
-// else if (pv.getValue() instanceof String[]) {
-// String[] values = (String[]) pv.getValue();
-// empty = (values.length == 0 || !StringUtils.hasText(values[0]));
-// }
-// }
- if (empty) {
- // Use bind error processor to create FieldError.
- getBindingErrorProcessor().processMissingFieldError(field, getInternalBindingResult());
- // Remove property from property values to bind:
- // It has already caused a field error with a rejected value.
- if (pv != null) {
- mpvs.removePropertyValue(pv);
- propertyValues.remove(field);
- }
- }
- }
- }
- }
- };
- binder.initDirectFieldAccess();
- PropertyEditorUtil.registerUimaFITEditors(binder);
- binder.setRequiredFields(mandatoryValues.toArray(new String[mandatoryValues.size()]));
- binder.bind(values);
- if (binder.getBindingResult().hasErrors()) {
- StringBuilder sb = new StringBuilder();
- sb.append("Errors initializing ["+component.getClass()+"]");
- for (ObjectError error : binder.getBindingResult().getAllErrors()) {
- if (sb.length() > 0) {
- sb.append("\n");
- }
- sb.append(error.getDefaultMessage());
- }
- throw new IllegalArgumentException(sb.toString());
- }
- }
-
- /**
- * Initialize a component from a map.
- *
- * @param component the component to initialize.
- * @param map a UIMA context with configuration parameters.
- * @see #initialize(Object, UimaContext)
- */
- public static void initialize(final Object component, final Map<String, Object> map)
- throws ResourceInitializationException {
- UimaContextAdmin context = UIMAFramework.newUimaContext(UIMAFramework.getLogger(),
- UIMAFramework.newDefaultResourceManager(), UIMAFramework.newConfigurationManager());
- ConfigurationManager cfgMgr = context.getConfigurationManager();
- cfgMgr.setSession(context.getSession());
- for (Entry<String, Object> e : map.entrySet()) {
- cfgMgr.setConfigParameterValue(context.getQualifiedContextName() + e.getKey(),
- e.getValue());
- }
- initialize(component, context);
- }
-
- /**
- * Initialize a component from a {@link CustomResourceSpecifier}.
- *
- * @param component the component to initialize.
- * @param spec a resource specifier.
- * @see #initialize(Object, UimaContext)
- */
- public static void initialize(Object component, ResourceSpecifier spec)
- throws ResourceInitializationException {
- initialize(component, ConfigurationParameterFactory.getParameterSettings(spec));
- }
-
- /**
- * Initialize a component from a {@link CustomResourceSpecifier}.
- *
- * @param component the component to initialize.
- * @param parameters a list of parameters.
- * @see #initialize(Object, UimaContext)
- */
- public static void initialize(Object component, Parameter... parameters)
- throws ResourceInitializationException {
- Map<String, Object> params = new HashMap<String, Object>();
- for (Parameter p : parameters) {
- params.put(p.getName(), p.getValue());
- }
- initialize(component, params);
- }
-
- /**
- * Initialize a component from a {@link ResourceMetaData}.
- *
- * @param component the component to initialize.
- * @param parameters a list of parameters.
- * @see #initialize(Object, UimaContext)
- */
- public static void initialize(Object component, NameValuePair... parameters)
- throws ResourceInitializationException {
- Map<String, Object> params = new HashMap<String, Object>();
- for (NameValuePair p : parameters) {
- params.put(p.getName(), p.getValue());
- }
- initialize(component, params);
- }
-
- /**
- * Initialize a component from a {@link ResourceMetaData}.
- *
- * @param component the component to initialize.
- * @param dataResource a data resource with configuration meta data.
- * @see #initialize(Object, UimaContext)
- */
- public static void initialize(Object component, DataResource dataResource)
- throws ResourceInitializationException {
- ResourceMetaData metaData = dataResource.getMetaData();
- ConfigurationParameterSettings settings = metaData.getConfigurationParameterSettings();
- initialize(component, settings.getParameterSettings());
- }
-
-// /**
-// * This method converts UIMA values to values that are appropriate for instantiating the
-// * annotated member variable. For example, if the "uima" value is a string array and the member
-// * variable is of type List<String>, then this method will return a list
-// *
-// * @param field
-// * @param uimaValue
-// * @return
-// */
-// public static Object convertValue(Field field, Object uimaValue) {
-// if (ConfigurationParameterFactory.isConfigurationParameterField(field)) {
-//
-// Object result;
-// Class<?> fieldType = field.getType();
-// Class<?> componentType = getComponentType(field);
-// Converter<?> converter = getConverter(componentType);
-//
-// // arrays
-// if (fieldType.isArray()) {
-// Object[] uimaValues = (Object[]) uimaValue;
-// result = Array.newInstance(componentType, uimaValues.length);
-// for (int index = 0; index < uimaValues.length; ++index) {
-// Array.set(result, index, converter.convert(uimaValues[index]));
-// }
-// }
-//
-// // collections
-// else if (Collection.class.isAssignableFrom(fieldType)) {
-// Collection<Object> collection;
-// if (fieldType == List.class) {
-// collection = new ArrayList<Object>();
-// }
-// else if (fieldType == Set.class) {
-// collection = new HashSet<Object>();
-// }
-// else {
-// collection = newCollection(fieldType);
-// }
-// Object[] uimaValues = (Object[]) uimaValue;
-// for (Object value : uimaValues) {
-// collection.add(converter.convert(value));
-// }
-// result = collection;
-// }
-//
-// // other
-// else {
-// result = converter.convert(uimaValue);
-// }
-// return result;
-// }
-// else {
-// throw new IllegalArgumentException("field is not annotated with annotation of type "
-// + org.uimafit.descriptor.ConfigurationParameter.class.getName());
-// }
-// }
-//
-// @SuppressWarnings("unchecked")
-// private static Collection<Object> newCollection(Class<?> cls) {
-// try {
-// return cls.asSubclass(Collection.class).newInstance();
-// }
-// catch (Exception e) {
-// throw new RuntimeException(e);
-// }
-// }
-//
-// private static Class<?> getComponentType(Field field) {
-// Class<?> fieldType = field.getType();
-// if (fieldType.isArray()) {
-// return fieldType.getComponentType();
-// }
-// else if (Collection.class.isAssignableFrom(fieldType)) {
-// ParameterizedType collectionType = (ParameterizedType) field.getGenericType();
-// return (Class<?>) collectionType.getActualTypeArguments()[0];
-// }
-// else {
-// return fieldType;
-// }
-// }
-//
-// private static void setParameterValue(Object component, Field field, Object value)
-// throws IllegalArgumentException, IllegalAccessException, SecurityException {
-//
-// boolean accessible = field.isAccessible();
-// field.setAccessible(true);
-// try {
-// field.set(component, value);
-// }
-// finally {
-// field.setAccessible(accessible);
-// }
-// }
-//
-// private ConfigurationParameterInitializer() {
-// // should not be instantiated
-// }
-//
-// @SuppressWarnings({ "rawtypes", "unchecked" })
-// private static Converter<?> getConverter(Class<?> cls) {
-// Converter<?> converter = CONVERTERS.get(cls);
-// if (converter != null) {
-// return converter;
-// }
-//
-// // Check if we have an enumeration type
-// if (Enum.class.isAssignableFrom(cls)) {
-// return new EnumConverter(cls);
-// }
-//
-// try {
-// Constructor<?> constructor = cls.getConstructor(String.class);
-// return new ConstructorConverter(constructor);
-// }
-// catch (NoSuchMethodException e) {
-// throw new IllegalArgumentException("don't know how to convert type " + cls);
-// }
-// }
-//
-// private interface Converter<T> {
-// T convert(Object aObject);
-// }
-//
-// private static class BooleanConverter implements Converter<Boolean> {
-// public Boolean convert(Object aObject) {
-// return (Boolean) aObject;
-// }
-// }
-//
-// private static class FloatConverter implements Converter<Float> {
-// public Float convert(Object aObject) {
-// return (Float) aObject;
-// }
-// }
-//
-// private static class DoubleConverter implements Converter<Float> {
-// public Float convert(Object aObject) {
-// return ((Number) aObject).floatValue();
-// }
-// }
-//
-// private static class IntegerConverter implements Converter<Integer> {
-// public Integer convert(Object aObject) {
-// return (Integer) aObject;
-// }
-// }
-//
-// private static class StringConverter implements Converter<String> {
-// public String convert(Object aObject) {
-// return String.valueOf(aObject);
-// }
-// }
-//
-// private static class PatternConverter implements Converter<Pattern> {
-// public Pattern convert(Object aObject) {
-// return Pattern.compile(aObject.toString());
-// }
-// }
-//
-// private static class ConstructorConverter implements Converter<Object> {
-// final private Constructor<?> constructor;
-//
-// public ConstructorConverter(Constructor<?> constructor) {
-// this.constructor = constructor;
-// }
-//
-// public Object convert(Object o) {
-// try {
-// return this.constructor.newInstance(o);
-// }
-// catch (Exception e) {
-// throw new RuntimeException(e);
-// }
-// }
-//
-// }
-//
-// private static class EnumConverter<T extends Enum<T>> implements Converter<Object> {
-// final private Class<T> enumClass;
-//
-// public EnumConverter(Class<T> aClass) {
-// this.enumClass = aClass;
-// }
-//
-// public T convert(Object o) {
-// try {
-// return Enum.valueOf(enumClass, o.toString());
-// }
-// catch (Exception e) {
-// throw new RuntimeException(e);
-// }
-// }
-// }
-//
-// private static class LocaleConverter implements Converter<Locale> {
-// public Locale convert(Object o) {
-// if (o == null) {
-// return Locale.getDefault();
-// }
-// else if ("".equals(o)) {
-// return Locale.getDefault();
-// }
-// if (o instanceof String) {
-// return LocaleUtil.getLocale((String) o);
-// }
-// throw new IllegalArgumentException("the value for a locale should be either null or an "
-// + "empty string to get the default locale. Otherwise, the locale should be "
-// + "specified by a single string that names a locale constant (e.g. 'US') or "
-// + "that contains hyphen delimited locale information (e.g. 'en-US').");
-// }
-// }
+ private ConfigurationParameterInitializer() {
+ // Utility class
+ }
+
+ /**
+ * Initialize a component from an {@link UimaContext} This code can be a little confusing because
+ * the configuration parameter annotations are used in two contexts: in describing the component
+ * and to initialize member variables from a {@link UimaContext}. Here we are performing the
+ * latter task. It is important to remember that the {@link UimaContext} passed in to this method
+ * may or may not have been derived using reflection of the annotations (i.e. using
+ * {@link ConfigurationParameterFactory} via e.g. a call to a AnalysisEngineFactory.create
+ * method). It is just as possible for the description of the component to come directly from an
+ * XML descriptor file. So, for example, just because a configuration parameter specifies a
+ * default value, this does not mean that the passed in context will have a value for that
+ * configuration parameter. It should be possible for a descriptor file to specify its own value
+ * or to not provide one at all. If the context does not have a configuration parameter, then the
+ * default value provided by the developer as specified by the defaultValue element of the
+ * {@link ConfigurationParameter} will be used. See comments in the code for additional details.
+ *
+ * @param component
+ * the component to initialize.
+ * @param context
+ * a UIMA context with configuration parameters.
+ */
+ public static void initialize(final Object component, final UimaContext context)
+ throws ResourceInitializationException {
+ MutablePropertyValues values = new MutablePropertyValues();
+ List<String> mandatoryValues = new ArrayList<String>();
+
+ for (Field field : ReflectionUtil.getFields(component)) { // component.getClass().getDeclaredFields())
+ if (ConfigurationParameterFactory.isConfigurationParameterField(field)) {
+ org.apache.uima.fit.descriptor.ConfigurationParameter annotation = field
+ .getAnnotation(org.apache.uima.fit.descriptor.ConfigurationParameter.class);
+
+ Object parameterValue;
+ String parameterName = ConfigurationParameterFactory.getConfigurationParameterName(field);
+
+ // Obtain either from the context - or - if the context does not provide the
+ // parameter, check if there is a default value. Note there are three possibilities:
+ // 1) Parameter present and set
+ // 2) Parameter present and set to null (null value)
+ // 3) Parameter not present (also provided as null value by UIMA)
+ // Unfortunately we cannot make a difference between case 2 and 3 since UIMA does
+ // not allow us to actually get a list of the parameters set in the context. We can
+ // only get a list of the declared parameters. Thus we have to rely on the null
+ // value.
+ parameterValue = context.getConfigParameterValue(parameterName);
+ if (parameterValue == null) {
+ parameterValue = ConfigurationParameterFactory.getDefaultValue(field);
+ }
+
+ if (parameterValue != null) {
+ values.addPropertyValue(field.getName(), parameterValue);
+ }
+
+ // TODO does this check really belong here? It seems that
+ // this check is already performed by UIMA
+ if (annotation.mandatory()) {
+ mandatoryValues.add(field.getName());
+
+ // if (parameterValue == null) {
+ // final String key = ResourceInitializationException.CONFIG_SETTING_ABSENT;
+ // throw new ResourceInitializationException(key,
+ // new Object[] { configurationParameterName });
+ // }
+ }
+ // else {
+ // if (parameterValue == null) {
+ // continue;
+ // }
+ // }
+ // final Object fieldValue = convertValue(field, parameterValue);
+ // try {
+ // setParameterValue(component, field, fieldValue);
+ // }
+ // catch (Exception e) {
+ // throw new ResourceInitializationException(e);
+ // }
+ }
+ }
+
+ DataBinder binder = new DataBinder(component) {
+ @Override
+ protected void checkRequiredFields(MutablePropertyValues mpvs) {
+ String[] requiredFields = getRequiredFields();
+ if (!ObjectUtils.isEmpty(requiredFields)) {
+ Map<String, PropertyValue> propertyValues = new HashMap<String, PropertyValue>();
+ PropertyValue[] pvs = mpvs.getPropertyValues();
+ for (PropertyValue pv : pvs) {
+ String canonicalName = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
+ propertyValues.put(canonicalName, pv);
+ }
+ for (String field : requiredFields) {
+ PropertyValue pv = propertyValues.get(field);
+ boolean empty = (pv == null || pv.getValue() == null);
+ // For our purposes, empty Strings or empty String arrays do not count as
+ // empty. Empty is only "null".
+ // if (!empty) {
+ // if (pv.getValue() instanceof String) {
+ // empty = !StringUtils.hasText((String) pv.getValue());
+ // }
+ // else if (pv.getValue() instanceof String[]) {
+ // String[] values = (String[]) pv.getValue();
+ // empty = (values.length == 0 || !StringUtils.hasText(values[0]));
+ // }
+ // }
+ if (empty) {
+ // Use bind error processor to create FieldError.
+ getBindingErrorProcessor()
+ .processMissingFieldError(field, getInternalBindingResult());
+ // Remove property from property values to bind:
+ // It has already caused a field error with a rejected value.
+ if (pv != null) {
+ mpvs.removePropertyValue(pv);
+ propertyValues.remove(field);
+ }
+ }
+ }
+ }
+ }
+ };
+ binder.initDirectFieldAccess();
+ PropertyEditorUtil.registerUimaFITEditors(binder);
+ binder.setRequiredFields(mandatoryValues.toArray(new String[mandatoryValues.size()]));
+ binder.bind(values);
+ if (binder.getBindingResult().hasErrors()) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Errors initializing [" + component.getClass() + "]");
+ for (ObjectError error : binder.getBindingResult().getAllErrors()) {
+ if (sb.length() > 0) {
+ sb.append("\n");
+ }
+ sb.append(error.getDefaultMessage());
+ }
+ throw new IllegalArgumentException(sb.toString());
+ }
+ }
+
+ /**
+ * Initialize a component from a map.
+ *
+ * @param component
+ * the component to initialize.
+ * @param map
+ * a UIMA context with configuration parameters.
+ * @see #initialize(Object, UimaContext)
+ */
+ public static void initialize(final Object component, final Map<String, Object> map)
+ throws ResourceInitializationException {
+ UimaContextAdmin context = UIMAFramework.newUimaContext(UIMAFramework.getLogger(),
+ UIMAFramework.newDefaultResourceManager(), UIMAFramework.newConfigurationManager());
+ ConfigurationManager cfgMgr = context.getConfigurationManager();
+ cfgMgr.setSession(context.getSession());
+ for (Entry<String, Object> e : map.entrySet()) {
+ cfgMgr.setConfigParameterValue(context.getQualifiedContextName() + e.getKey(), e.getValue());
+ }
+ initialize(component, context);
+ }
+
+ /**
+ * Initialize a component from a {@link CustomResourceSpecifier}.
+ *
+ * @param component
+ * the component to initialize.
+ * @param spec
+ * a resource specifier.
+ * @see #initialize(Object, UimaContext)
+ */
+ public static void initialize(Object component, ResourceSpecifier spec)
+ throws ResourceInitializationException {
+ initialize(component, ConfigurationParameterFactory.getParameterSettings(spec));
+ }
+
+ /**
+ * Initialize a component from a {@link CustomResourceSpecifier}.
+ *
+ * @param component
+ * the component to initialize.
+ * @param parameters
+ * a list of parameters.
+ * @see #initialize(Object, UimaContext)
+ */
+ public static void initialize(Object component, Parameter... parameters)
+ throws ResourceInitializationException {
+ Map<String, Object> params = new HashMap<String, Object>();
+ for (Parameter p : parameters) {
+ params.put(p.getName(), p.getValue());
+ }
+ initialize(component, params);
+ }
+
+ /**
+ * Initialize a component from a {@link ResourceMetaData}.
+ *
+ * @param component
+ * the component to initialize.
+ * @param parameters
+ * a list of parameters.
+ * @see #initialize(Object, UimaContext)
+ */
+ public static void initialize(Object component, NameValuePair... parameters)
+ throws ResourceInitializationException {
+ Map<String, Object> params = new HashMap<String, Object>();
+ for (NameValuePair p : parameters) {
+ params.put(p.getName(), p.getValue());
+ }
+ initialize(component, params);
+ }
+
+ /**
+ * Initialize a component from a {@link ResourceMetaData}.
+ *
+ * @param component
+ * the component to initialize.
+ * @param dataResource
+ * a data resource with configuration meta data.
+ * @see #initialize(Object, UimaContext)
+ */
+ public static void initialize(Object component, DataResource dataResource)
+ throws ResourceInitializationException {
+ ResourceMetaData metaData = dataResource.getMetaData();
+ ConfigurationParameterSettings settings = metaData.getConfigurationParameterSettings();
+ initialize(component, settings.getParameterSettings());
+ }
+
+ // /**
+ // * This method converts UIMA values to values that are appropriate for instantiating the
+ // * annotated member variable. For example, if the "uima" value is a string array and the member
+ // * variable is of type List<String>, then this method will return a list
+ // *
+ // * @param field
+ // * @param uimaValue
+ // * @return
+ // */
+ // public static Object convertValue(Field field, Object uimaValue) {
+ // if (ConfigurationParameterFactory.isConfigurationParameterField(field)) {
+ //
+ // Object result;
+ // Class<?> fieldType = field.getType();
+ // Class<?> componentType = getComponentType(field);
+ // Converter<?> converter = getConverter(componentType);
+ //
+ // // arrays
+ // if (fieldType.isArray()) {
+ // Object[] uimaValues = (Object[]) uimaValue;
+ // result = Array.newInstance(componentType, uimaValues.length);
+ // for (int index = 0; index < uimaValues.length; ++index) {
+ // Array.set(result, index, converter.convert(uimaValues[index]));
+ // }
+ // }
+ //
+ // // collections
+ // else if (Collection.class.isAssignableFrom(fieldType)) {
+ // Collection<Object> collection;
+ // if (fieldType == List.class) {
+ // collection = new ArrayList<Object>();
+ // }
+ // else if (fieldType == Set.class) {
+ // collection = new HashSet<Object>();
+ // }
+ // else {
+ // collection = newCollection(fieldType);
+ // }
+ // Object[] uimaValues = (Object[]) uimaValue;
+ // for (Object value : uimaValues) {
+ // collection.add(converter.convert(value));
+ // }
+ // result = collection;
+ // }
+ //
+ // // other
+ // else {
+ // result = converter.convert(uimaValue);
+ // }
+ // return result;
+ // }
+ // else {
+ // throw new IllegalArgumentException("field is not annotated with annotation of type "
+ // + org.uimafit.descriptor.ConfigurationParameter.class.getName());
+ // }
+ // }
+ //
+ // @SuppressWarnings("unchecked")
+ // private static Collection<Object> newCollection(Class<?> cls) {
+ // try {
+ // return cls.asSubclass(Collection.class).newInstance();
+ // }
+ // catch (Exception e) {
+ // throw new RuntimeException(e);
+ // }
+ // }
+ //
+ // private static Class<?> getComponentType(Field field) {
+ // Class<?> fieldType = field.getType();
+ // if (fieldType.isArray()) {
+ // return fieldType.getComponentType();
+ // }
+ // else if (Collection.class.isAssignableFrom(fieldType)) {
+ // ParameterizedType collectionType = (ParameterizedType) field.getGenericType();
+ // return (Class<?>) collectionType.getActualTypeArguments()[0];
+ // }
+ // else {
+ // return fieldType;
+ // }
+ // }
+ //
+ // private static void setParameterValue(Object component, Field field, Object value)
+ // throws IllegalArgumentException, IllegalAccessException, SecurityException {
+ //
+ // boolean accessible = field.isAccessible();
+ // field.setAccessible(true);
+ // try {
+ // field.set(component, value);
+ // }
+ // finally {
+ // field.setAccessible(accessible);
+ // }
+ // }
+ //
+ // private ConfigurationParameterInitializer() {
+ // // should not be instantiated
+ // }
+ //
+ // @SuppressWarnings({ "rawtypes", "unchecked" })
+ // private static Converter<?> getConverter(Class<?> cls) {
+ // Converter<?> converter = CONVERTERS.get(cls);
+ // if (converter != null) {
+ // return converter;
+ // }
+ //
+ // // Check if we have an enumeration type
+ // if (Enum.class.isAssignableFrom(cls)) {
+ // return new EnumConverter(cls);
+ // }
+ //
+ // try {
+ // Constructor<?> constructor = cls.getConstructor(String.class);
+ // return new ConstructorConverter(constructor);
+ // }
+ // catch (NoSuchMethodException e) {
+ // throw new IllegalArgumentException("don't know how to convert type " + cls);
+ // }
+ // }
+ //
+ // private interface Converter<T> {
+ // T convert(Object aObject);
+ // }
+ //
+ // private static class BooleanConverter implements Converter<Boolean> {
+ // public Boolean convert(Object aObject) {
+ // return (Boolean) aObject;
+ // }
+ // }
+ //
+ // private static class FloatConverter implements Converter<Float> {
+ // public Float convert(Object aObject) {
+ // return (Float) aObject;
+ // }
+ // }
+ //
+ // private static class DoubleConverter implements Converter<Float> {
+ // public Float convert(Object aObject) {
+ // return ((Number) aObject).floatValue();
+ // }
+ // }
+ //
+ // private static class IntegerConverter implements Converter<Integer> {
+ // public Integer convert(Object aObject) {
+ // return (Integer) aObject;
+ // }
+ // }
+ //
+ // private static class StringConverter implements Converter<String> {
+ // public String convert(Object aObject) {
+ // return String.valueOf(aObject);
+ // }
+ // }
+ //
+ // private static class PatternConverter implements Converter<Pattern> {
+ // public Pattern convert(Object aObject) {
+ // return Pattern.compile(aObject.toString());
+ // }
+ // }
+ //
+ // private static class ConstructorConverter implements Converter<Object> {
+ // final private Constructor<?> constructor;
+ //
+ // public ConstructorConverter(Constructor<?> constructor) {
+ // this.constructor = constructor;
+ // }
+ //
+ // public Object convert(Object o) {
+ // try {
+ // return this.constructor.newInstance(o);
+ // }
+ // catch (Exception e) {
+ // throw new RuntimeException(e);
+ // }
+ // }
+ //
+ // }
+ //
+ // private static class EnumConverter<T extends Enum<T>> implements Converter<Object> {
+ // final private Class<T> enumClass;
+ //
+ // public EnumConverter(Class<T> aClass) {
+ // this.enumClass = aClass;
+ // }
+ //
+ // public T convert(Object o) {
+ // try {
+ // return Enum.valueOf(enumClass, o.toString());
+ // }
+ // catch (Exception e) {
+ // throw new RuntimeException(e);
+ // }
+ // }
+ // }
+ //
+ // private static class LocaleConverter implements Converter<Locale> {
+ // public Locale convert(Object o) {
+ // if (o == null) {
+ // return Locale.getDefault();
+ // }
+ // else if ("".equals(o)) {
+ // return Locale.getDefault();
+ // }
+ // if (o instanceof String) {
+ // return LocaleUtil.getLocale((String) o);
+ // }
+ // throw new IllegalArgumentException("the value for a locale should be either null or an "
+ // + "empty string to get the default locale. Otherwise, the locale should be "
+ // + "specified by a single string that names a locale constant (e.g. 'US') or "
+ // + "that contains hyphen delimited locale information (e.g. 'en-US').");
+ // }
+ // }
}