You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2012/12/11 23:03:15 UTC

svn commit: r1420449 [2/12] - in /uima/sandbox/trunk/uimaFIT/uimafit: ./ .settings/ src/ src/main/ src/main/assembly/ src/main/java/ src/main/java/org/ src/main/java/org/uimafit/ src/main/java/org/uimafit/component/ src/main/java/org/uimafit/component/...

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/ConfigurationParameterInitializer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/ConfigurationParameterInitializer.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/ConfigurationParameterInitializer.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/ConfigurationParameterInitializer.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,483 @@
+/*
+ Copyright 2009-2010 Regents of the University of Colorado.
+ All rights reserved.
+
+ Licensed 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.uimafit.component.initialize;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.UimaContext;
+import org.apache.uima.UimaContextAdmin;
+import org.apache.uima.resource.ConfigurationManager;
+import org.apache.uima.resource.CustomResourceSpecifier;
+import org.apache.uima.resource.DataResource;
+import org.apache.uima.resource.Parameter;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceSpecifier;
+import org.apache.uima.resource.metadata.ConfigurationParameterSettings;
+import org.apache.uima.resource.metadata.NameValuePair;
+import org.apache.uima.resource.metadata.ResourceMetaData;
+import org.springframework.beans.MutablePropertyValues;
+import org.springframework.beans.PropertyAccessorUtils;
+import org.springframework.beans.PropertyValue;
+import org.springframework.util.ObjectUtils;
+import org.springframework.validation.DataBinder;
+import org.springframework.validation.ObjectError;
+import org.uimafit.descriptor.ConfigurationParameter;
+import org.uimafit.factory.ConfigurationParameterFactory;
+import org.uimafit.propertyeditors.PropertyEditorUtil;
+import org.uimafit.util.ReflectionUtil;
+
+/**
+ * <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>
+ *
+ * @author Philip Ogren
+ */
+
+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.uimafit.descriptor.ConfigurationParameter annotation = field
+						.getAnnotation(org.uimafit.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').");
+//		}
+//	}
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/ConfigurationParameterInitializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/ExternalResourceInitializer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/ExternalResourceInitializer.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/ExternalResourceInitializer.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/ExternalResourceInitializer.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,318 @@
+/*
+ Copyright 2009-2010
+ Ubiquitous Knowledge Processing (UKP) Lab
+ Technische Universitaet Darmstadt
+ All rights reserved.
+
+ Licensed 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.uimafit.component.initialize;
+
+import static org.uimafit.factory.ExternalResourceFactory.PREFIX_SEPARATOR;
+import static org.uimafit.factory.ExternalResourceFactory.createExternalResourceDependency;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.apache.uima.UimaContext;
+import org.apache.uima.UimaContextAdmin;
+import org.apache.uima.resource.ExternalResourceDependency;
+import org.apache.uima.resource.Resource;
+import org.apache.uima.resource.ResourceAccessException;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.SharedResourceObject;
+import org.apache.uima.resource.impl.ResourceManager_impl;
+import org.uimafit.component.ExternalResourceAware;
+import org.uimafit.descriptor.ExternalResource;
+import org.uimafit.descriptor.ExternalResourceLocator;
+import org.uimafit.util.ReflectionUtil;
+
+/**
+ * Configurator class for {@link ExternalResource} annotations.
+ *
+ * @author Richard Eckart de Castilho
+ */
+public class ExternalResourceInitializer {
+	
+	private static final Object INITIALIZED = new Object();
+	private static Map<Object, Object> initializedResources = new WeakHashMap<Object, Object>();
+	
+	/**
+	 * Configure a component from the given context.
+	 *
+	 * @param <T>
+	 *            the component type.
+	 * @param context
+	 *            the UIMA context.
+	 * @param object
+	 *            the component.
+	 * @throws ResourceInitializationException
+	 *             if the external resource cannot be configured.
+	 */
+	public static <T> void initialize(UimaContext context, T object)
+			throws ResourceInitializationException {
+		configure(context, object.getClass(), object.getClass(), object,
+				getResourceDeclarations(object.getClass()));
+	}
+	
+	/**
+	 * Helper method for recursively configuring super-classes.
+	 *
+	 * @param <T>
+	 *            the component type.
+	 * @param context
+	 *            the context containing the resource bindings.
+	 * @param baseCls
+	 *            the class on which configuration started.
+	 * @param cls
+	 *            the class currently being configured.
+	 * @param object
+	 *            the object being configured.
+	 * @param dependencies
+	 *            the dependencies.
+	 * @throws ResourceInitializationException
+	 *             if required resources could not be bound.
+	 */
+	private static <T> void configure(UimaContext context, Class<?> baseCls, Class<?> cls,
+			T object, Map<String, ExternalResourceDependency> dependencies)
+			throws ResourceInitializationException {
+		if (cls.getSuperclass() != null) {
+			configure(context, baseCls, cls.getSuperclass(), object, dependencies);
+		}
+		else {
+			// Try to initialize the external resources only once, not for each step of the
+			// class hierarchy of a component.
+			initializeNestedResources(context);
+		}
+		
+		for (Field field : cls.getDeclaredFields()) {
+			if (!field.isAnnotationPresent(ExternalResource.class)) {
+				continue;
+			}
+
+			// Get the resource key. If it is a nested resource, also get the prefix.
+			String key = getKey(field);
+			if (object instanceof ExternalResourceAware) {
+				String prefix = ((ExternalResourceAware) object).getResourceName();
+				if (prefix != null) {
+					key = prefix + PREFIX_SEPARATOR + key;
+				}
+			}
+			
+			// Obtain the resource
+			Object value;
+			try {
+				value = context.getResourceObject(key);
+			}
+			catch (ResourceAccessException e) {
+				throw new ResourceInitializationException(e);
+			}
+			if (value instanceof ExternalResourceLocator) {
+				value = ((ExternalResourceLocator) value).getResource();
+			}
+
+			// Sanity checks
+			if (value == null && isMandatory(field)) {
+				throw new ResourceInitializationException(new IllegalStateException(
+						"Mandatory resource [" + key + "] is not set on [" + baseCls + "]"));
+			}
+
+			// Now record the setting and optionally apply it to the given
+			// instance.
+			if (value != null) {
+				field.setAccessible(true);
+				try {
+					field.set(object, value);
+				}
+				catch (IllegalAccessException e) {
+					throw new ResourceInitializationException(e);
+				}
+				field.setAccessible(false);
+			}
+		}		
+	}
+	
+	/**
+	 * Scan the context and initialize external resources injected into other external resources.
+	 * 
+	 * @param aContext the UIMA context.
+	 */
+	private static void initializeNestedResources(UimaContext aContext)
+			throws ResourceInitializationException {
+		List<ExternalResourceAware> awareResources = new ArrayList<ExternalResourceAware>();
+		
+		// Initialize the resources - each resource must only be initialized once. We remember
+		// if a resource has already been initialized in a weak hash map, so we automatically
+		// forget about resources that are garbage collected.
+		for (Object r : getResources(aContext)) {
+			synchronized (initializedResources) {
+				if (r instanceof ExternalResourceAware && !initializedResources.containsKey(r)) {
+					// Already mark the resource as initialized so we do not run into an 
+					// endless recursive loop when initialize() is called again.
+					initializedResources.put(r, INITIALIZED);
+					initialize(aContext, r);
+					awareResources.add((ExternalResourceAware) r);
+				}
+			}
+		}
+		
+		// Notify the resources after everything has been configured
+		for (ExternalResourceAware res : awareResources) {
+			res.afterResourcesInitialized();
+		}
+	}
+	
+	/**
+	 * Get all resources declared in the context.
+	 */
+	private static Collection<?> getResources(UimaContext aContext)
+			throws ResourceInitializationException	{
+		if (!(aContext instanceof UimaContextAdmin)) {
+			return Collections.emptyList();
+		}
+		
+		ResourceManager resMgr = ((UimaContextAdmin) aContext).getResourceManager();
+		if (!(resMgr instanceof ResourceManager_impl)) {
+			// Unfortunately there is not official way to access the list of resources. Thus we
+			// have to rely on the UIMA implementation details and access the internal resource
+			// map via reflection. If the resource manager is not derived from the default 
+			// UIMA resource manager, then we cannot really do anything here.
+			throw new IllegalStateException("Unsupported resource manager implementation ["
+					+ resMgr.getClass() + "]");
+		}
+		
+		Field resourceMapField = null;
+		try {
+			// Fetch the list of resources
+			resourceMapField = ReflectionUtil.getField(resMgr, "mResourceMap");
+			resourceMapField.setAccessible(true);			
+			@SuppressWarnings("unchecked")
+			Map<String, Object> resources = (Map<String, Object>) resourceMapField.get(resMgr);
+			
+			return resources.values();
+		}
+		catch (SecurityException e) {
+			throw new ResourceInitializationException(e);
+		}
+		catch (NoSuchFieldException e) {
+			throw new ResourceInitializationException(e);
+		}
+		catch (IllegalArgumentException e) {
+			throw new ResourceInitializationException(e);
+		}
+		catch (IllegalAccessException e) {
+			throw new ResourceInitializationException(e);
+		}
+		finally {
+			if (resourceMapField != null) {
+				resourceMapField.setAccessible(false);
+			}
+		}
+	}
+	
+	public static <T> Map<String, ExternalResourceDependency> getResourceDeclarations(Class<?> cls)
+			throws ResourceInitializationException {
+		Map<String, ExternalResourceDependency> deps = new HashMap<String, ExternalResourceDependency>();
+		getResourceDeclarations(cls, cls, deps);
+		return deps;
+	}
+
+	private static <T> void getResourceDeclarations(Class<?> baseCls, Class<?> cls,
+			Map<String, ExternalResourceDependency> dependencies)
+			throws ResourceInitializationException {
+		if (cls.getSuperclass() != null) {
+			getResourceDeclarations(baseCls, cls.getSuperclass(), dependencies);
+		}
+
+		for (Field field : cls.getDeclaredFields()) {
+			if (!field.isAnnotationPresent(ExternalResource.class)) {
+				continue;
+			}
+
+			if (dependencies.containsKey(getKey(field))) {
+				throw new ResourceInitializationException(new IllegalStateException("Key ["
+						+ getKey(field) + "] may only be used on a single field."));
+			}
+
+			dependencies.put(
+					getKey(field),
+					createExternalResourceDependency(getKey(field), getApi(field),
+							!isMandatory(field)));
+		}
+	}
+
+	/**
+	 * Determine if the field is mandatory.
+	 *
+	 * @param field
+	 *            the field to bind.
+	 * @return whether the field is mandatory.
+	 */
+	private static boolean isMandatory(Field field) {
+		return field.getAnnotation(ExternalResource.class).mandatory();
+	}
+
+	/**
+	 * Get the binding key for the specified field. If no key is set, use the field class name as
+	 * key.
+	 *
+	 * @param field
+	 *            the field to bind.
+	 * @return the binding key.
+	 */
+	private static String getKey(Field field) {
+		ExternalResource cpa = field.getAnnotation(ExternalResource.class);
+		String key = cpa.key();
+		if (key.length() == 0) {
+			key = field.getType().getName();
+		}
+		return key;
+	}
+
+	/**
+	 * Get the type of class/interface a resource has to implement to bind to the annotated field.
+	 * If no API is set, get it from the annotated field type.
+	 *
+	 * @param field
+	 *            the field to bind.
+	 * @return the API type.
+	 */
+	@SuppressWarnings({ "unchecked", "rawtypes" })
+	private static Class<? extends Resource> getApi(Field field) {
+		ExternalResource cpa = field.getAnnotation(ExternalResource.class);
+		Class<? extends Resource> api = cpa.api();
+		// If no api is specified, look at the annotated field
+		if (api == Resource.class) {
+			if (Resource.class.isAssignableFrom(field.getType())
+					|| SharedResourceObject.class.isAssignableFrom(field.getType())) {
+				// If no API is set, check if the field type is already a resource type
+				api = (Class<? extends Resource>) field.getType();
+			}
+			else {
+				// If the field does not have a resource type, assume whatever. This allows to use
+				// a resource locator without having to specify the api parameter. It also allows
+				// to directly inject Java objects - yes, I know that Object does not extend
+				// Resource - REC, 2011-03-25
+				api = (Class) Object.class;
+			}
+		}
+		return api;
+	}
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/ExternalResourceInitializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/package-info.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/package-info.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/package-info.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/package-info.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright 2010
+ * Ubiquitous Knowledge Processing (UKP) Lab
+ * Technische Universität Darmstadt
+ *
+ * Licensed 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.
+ ******************************************************************************/
+
+/**
+ * Reflection-based context and dependency injection.
+ */
+package org.uimafit.component.initialize;

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/initialize/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/package-info.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/package-info.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/package-info.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/package-info.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright 2010
+ * Ubiquitous Knowledge Processing (UKP) Lab
+ * Technische Universität Darmstadt
+ *
+ * Licensed 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.
+ ******************************************************************************/
+
+/**
+ * uimaFIT-enhanced base classes for UIMA components and some simple components.
+ */
+package org.uimafit.component;

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/CASDumpWriter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/CASDumpWriter.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/CASDumpWriter.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/CASDumpWriter.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,303 @@
+/*
+ Copyright 2009
+ Ubiquitous Knowledge Processing (UKP) Lab
+ Technische Universitaet Darmstadt
+ All rights reserved.
+
+ Licensed 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.uimafit.component.xwriter;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.springframework.util.DigestUtils;
+import org.uimafit.component.CasConsumer_ImplBase;
+import org.uimafit.descriptor.ConfigurationParameter;
+
+/**
+ * Dumps CAS content to a text file. This is useful when setting up test cases which contain a
+ * reference output to which an actually produced CAS is compared. The format produced by this
+ * component is more easily comparable than a XML or XMI format produced by {@link XWriter}.
+ *
+ * @author Richard Eckart de Castilho
+ */
+public class CASDumpWriter extends CasConsumer_ImplBase {
+	/**
+	 * Pattern inclusion prefix.
+	 */
+	public static final String INCLUDE_PREFIX = "+|";
+	/**
+	 * Pattern exclusion prefix.
+	 */
+	public static final String EXCLUDE_PREFIX = "-|";
+
+	/**
+	 * Output file. If multiple CASes as processed, their contents are concatenated into this file.
+	 * Mind that a test case using this consumer with multiple CASes requires a reader which
+	 * produced the CASes always in the same order. When this file is set to "-", the dump does to
+	 * {@link System#out} (default).
+	 */
+	public static final String PARAM_OUTPUT_FILE = "OutputFile";
+	@ConfigurationParameter(name = PARAM_OUTPUT_FILE, mandatory = true, defaultValue="-")
+	private File outFile;
+
+	/**
+	 * Whether to dump the content of the {@link CAS#getDocumentAnnotation()}.
+	 */
+	public static final String PARAM_WRITE_DOCUMENT_META_DATA = "WriteDocumentMetaData";
+	@ConfigurationParameter(name = PARAM_WRITE_DOCUMENT_META_DATA, mandatory = true, defaultValue = "true")
+	private boolean writeDocumentMetaData;
+
+	/**
+	 * Include/exclude features according to the following patterns. Mind that the patterns do not
+	 * actually match feature names but lines produced by {@link FeatureStructure#toString()}.
+	 */
+	public static final String PARAM_FEATURE_PATTERNS = "FeaturePatterns";
+	@ConfigurationParameter(name = PARAM_FEATURE_PATTERNS, mandatory = true, defaultValue = {
+			"+|.*", "-|^.*documentUri:.*$", "-|^.*collectionId:.*$", "-|^.*documentBaseUri:.*$" })
+	private String[] rawFeaturePatterns;
+	private InExPattern[] featurePatterns;
+
+	/**
+	 * Include/exclude specified UIMA types in the output.
+	 */
+	public static final String PARAM_TYPE_PATTERNS = "TypePatterns";
+	@ConfigurationParameter(name = PARAM_TYPE_PATTERNS, mandatory = true, defaultValue = { "+|.*" })
+	private String[] rawTypePatterns;
+	private InExPattern[] typePatterns;
+
+	private PrintWriter out;
+	private int iCas;
+
+	@Override
+	public void initialize(UimaContext context) throws ResourceInitializationException {
+		super.initialize(context);
+
+		try {
+			if (out == null) {
+				if ("-".equals(outFile.getName())) {
+					out = new PrintWriter(System.out);
+				}
+				else {
+					if (outFile.getParentFile() != null) {
+					outFile.getParentFile().mkdirs();
+					}
+					out = new PrintWriter(
+							new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"));
+				}
+			}
+		}
+		catch (IOException e) {
+			throw new ResourceInitializationException(e);
+		}
+
+		typePatterns = compilePatterns(rawTypePatterns);
+		featurePatterns = compilePatterns(rawFeaturePatterns);
+	}
+
+	@Override
+	public void process(CAS aCAS) throws AnalysisEngineProcessException {
+		out.println("======== CAS " + iCas + " begin ==================================");
+		out.println();
+
+		Iterator<CAS> viewIt = aCAS.getViewIterator();
+		while (viewIt.hasNext()) {
+			CAS view = viewIt.next();
+			processView(view);
+
+			if (view.getDocumentText() == null && view.getSofaDataStream() != null) {
+				processSofaData(view);
+			}
+		}
+
+		out.println("======== CAS " + iCas + " end ==================================");
+		out.println();
+		out.println();
+		out.flush();
+
+		iCas++;
+	}
+
+	@Override
+	public void collectionProcessComplete() {
+		IOUtils.closeQuietly(out);
+		out = null;
+	}
+
+	private void processDocumentMetadata(CAS aCAS) {
+		if (!writeDocumentMetaData) {
+			return;
+		}
+
+		processFeatureStructure(aCAS.getDocumentAnnotation());
+	}
+
+	private void processDocumentText(CAS aCAS) {
+		out.println();
+		out.println("CAS-Text:");
+		out.println(aCAS.getDocumentText());
+	}
+
+	private void processFeatureStructures(CAS aCAS) {
+		Set<String> typesToPrint = getTypes(aCAS);
+		FSIterator<AnnotationFS> annotationIterator = aCAS.getAnnotationIndex().iterator();
+		while (annotationIterator.hasNext()) {
+			AnnotationFS annotation = annotationIterator.next();
+			if (!typesToPrint.contains(annotation.getType().getName())) {
+				continue;
+			}
+			try {
+				out.println("[" + annotation.getCoveredText() + "]");
+			}
+			catch (IndexOutOfBoundsException e) {
+				out.println("<OFFSETS OUT OF BOUNDS>");
+			}
+			processFeatureStructure(annotation);
+		}
+	}
+
+	private void processFeatureStructure(FeatureStructure aFS) {
+		String meta = aFS.toString();
+		for (String line : meta.split("\n")) {
+			boolean print = false;
+			for (InExPattern p : featurePatterns) {
+				p.matchter.reset(line);
+				if (p.matchter.matches()) {
+					print = p.includeInOutput;
+				}
+			}
+			if (print) {
+				out.println(line);
+			}
+		}
+	}
+
+	private void processView(CAS aCAS) {
+		out.println("-------- View " + aCAS.getViewName()
+				+ " begin ----------------------------------");
+		out.println();
+
+		processDocumentMetadata(aCAS);
+		processDocumentText(aCAS);
+		processFeatureStructures(aCAS);
+
+		out.println("-------- View " + aCAS.getViewName()
+				+ " end ----------------------------------");
+		out.println();
+	}
+
+	private void processSofaData(CAS aCAS) throws AnalysisEngineProcessException {
+		out.println("Sofa data:");
+
+		//
+
+		// Mime type
+		String mimeType = aCAS.getSofaMimeType();
+		if (mimeType != null) {
+			out.println("   mime type:\t" + mimeType);
+		}
+		// Data
+		byte[] bytes = null;
+		InputStream in = null;
+		try {
+			in = aCAS.getSofaDataStream();
+			bytes = IOUtils.toByteArray(in);
+		} catch (IOException e) {
+			throw new AnalysisEngineProcessException(e);
+		}
+		finally {
+			IOUtils.closeQuietly(in);
+		}
+		if (bytes != null) {
+			// Data size
+			out.println("   size:\t" + bytes.length + " byte(s)");
+			// Hash value of the bytes
+			String hash = DigestUtils.md5DigestAsHex(bytes);
+			out.println("   hash value:\t" + hash);
+		}
+
+		out.println();
+	}
+
+	private static InExPattern[] compilePatterns(String[] aPatterns) {
+		InExPattern[] patterns = new InExPattern[aPatterns.length];
+		for (int i = 0; i < aPatterns.length; i++) {
+			if (aPatterns[i].startsWith(INCLUDE_PREFIX)) {
+				patterns[i] = new InExPattern(aPatterns[i].substring(INCLUDE_PREFIX.length()), true);
+			}
+			else if (aPatterns[i].startsWith(EXCLUDE_PREFIX)) {
+				patterns[i] = new InExPattern(aPatterns[i].substring(EXCLUDE_PREFIX.length()),
+						false);
+			}
+			else {
+				patterns[i] = new InExPattern(aPatterns[i], false);
+			}
+		}
+		return patterns;
+	}
+
+	private Set<String> getTypes(CAS cas) {
+		Set<String> types = new HashSet<String>();
+		Iterator<Type> typeIt = cas.getTypeSystem().getTypeIterator();
+		nextType: while (typeIt.hasNext()) {
+			Type type = typeIt.next();
+
+			if (type.getName().equals(cas.getDocumentAnnotation().getType().getName())) {
+				continue;
+			}
+
+			for (InExPattern p : typePatterns) {
+				p.matchter.reset(type.getName());
+				if (p.matchter.matches()) {
+					if (p.includeInOutput) {
+						types.add(type.getName());
+					}
+					else {
+						types.remove(type.getName());
+					}
+					continue nextType;
+				}
+			}
+		}
+		return types;
+	}
+
+	private static class InExPattern {
+		final boolean includeInOutput;
+		final Matcher matchter;
+
+		public InExPattern(String aPattern, boolean aInclude) {
+			includeInOutput = aInclude;
+			matchter = Pattern.compile(aPattern).matcher("");
+		}
+	}
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/CASDumpWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/IntegerFileNamer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/IntegerFileNamer.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/IntegerFileNamer.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/IntegerFileNamer.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,55 @@
+/*
+  Copyright 2010 Regents of the University of Colorado.
+ All rights reserved.
+
+ Licensed 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.uimafit.component.xwriter;
+
+import org.apache.uima.UimaContext;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.uimafit.component.initialize.ConfigurationParameterInitializer;
+import org.uimafit.descriptor.ConfigurationParameter;
+import org.uimafit.factory.ConfigurationParameterFactory;
+import org.uimafit.factory.initializable.Initializable;
+
+/**
+ * This is a very simple implementation of XWriterFileNamer that generates file names based on a
+ * prefix string and a incrementing counter.
+ * 
+ * @author Philip Ogren
+ */
+
+public class IntegerFileNamer implements XWriterFileNamer, Initializable {
+
+	/**
+	 * The parameter name for the configuration parameter that specifies a fixed prefix for all
+	 * returned file names.
+	 */
+	public static final String PARAM_PREFIX = ConfigurationParameterFactory
+			.createConfigurationParameterName(IntegerFileNamer.class, "prefix");
+	@ConfigurationParameter(description = "specify a prefix that is prepended to all returned file names", defaultValue="")
+	private String prefix;
+
+	int i = 1;
+
+	public String nameFile(JCas jCas) {
+		return prefix + i++;
+	}
+
+	public void initialize(UimaContext context) throws ResourceInitializationException {
+		ConfigurationParameterInitializer.initialize(this, context);
+	}
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/IntegerFileNamer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/XWriter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/XWriter.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/XWriter.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/XWriter.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,170 @@
+/*
+  Copyright 2010 Regents of the University of Colorado.
+ All rights reserved.
+
+ Licensed 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.uimafit.component.xwriter;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.impl.XCASSerializer;
+import org.apache.uima.cas.impl.XmiCasSerializer;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.XMLSerializer;
+import org.uimafit.component.JCasConsumer_ImplBase;
+import org.uimafit.descriptor.ConfigurationParameter;
+import org.uimafit.factory.ConfigurationParameterFactory;
+import org.uimafit.factory.initializable.InitializableFactory;
+import org.xml.sax.SAXException;
+
+/**
+ * 
+ * A simple CAS consumer that generates XCAS (XML representation of the CAS) files in the
+ * filesystem.
+ * 
+ * @author Philip Ogren
+ */
+
+public class XWriter extends JCasConsumer_ImplBase {
+
+	/**
+	 * The parameter name for the configuration parameter that specifies the output directory
+	 */
+	public static final String PARAM_OUTPUT_DIRECTORY_NAME = ConfigurationParameterFactory
+			.createConfigurationParameterName(XWriter.class, "outputDirectoryName");
+	@ConfigurationParameter(mandatory = true, description = "takes a path to directory into which output files will be written.")
+	private String outputDirectoryName;
+
+	/**
+	 * The parameter name for the configuration parameter that provides the name of the XML scheme
+	 * to use.
+	 */
+	public static final String PARAM_XML_SCHEME_NAME = ConfigurationParameterFactory
+			.createConfigurationParameterName(XWriter.class, "xmlSchemeName");
+	@ConfigurationParameter(mandatory = true, defaultValue = "XMI", description = "specifies the UIMA XML serialization scheme that should be used. "
+			+ "Valid values for this parameter are 'XMI' (default) and 'XCAS'.")
+	private String xmlSchemeName;
+
+	/**
+	 * The parameter name for the configuration parameter that specifies the name of the class that
+	 * implements the file namer
+	 */
+	public static final String PARAM_FILE_NAMER_CLASS_NAME = ConfigurationParameterFactory
+			.createConfigurationParameterName(XWriter.class, "fileNamerClassName");
+	@ConfigurationParameter(mandatory = true, description = "the class name of the XWriterFileNamer implementation to use", defaultValue = "org.uimafit.component.xwriter.IntegerFileNamer")
+	protected String fileNamerClassName;
+
+	/**
+	 * The name of the XMI XML scheme. This is a valid value for the parameter
+	 * {@value #PARAM_XML_SCHEME_NAME}
+	 */
+	public static final String XMI = "XMI";
+
+	/**
+	 * The name of the XCAS XML scheme. This is a valid value for the parameter
+	 * {@value #PARAM_XML_SCHEME_NAME}
+	 */
+	public static final String XCAS = "XCAS";
+
+	private File outputDirectory;
+
+	private boolean useXMI = true;
+
+	private XWriterFileNamer fileNamer;
+
+	@Override
+	public void initialize(UimaContext context) throws ResourceInitializationException {
+		super.initialize(context);
+
+		outputDirectory = new File(outputDirectoryName);
+		if (!outputDirectory.exists()) {
+			outputDirectory.mkdirs();
+		}
+
+		if (xmlSchemeName.equals(XMI)) {
+			useXMI = true;
+		}
+		else if (xmlSchemeName.equals(XCAS)) {
+			useXMI = false;
+		}
+		else {
+			throw new ResourceInitializationException(String.format(
+					"parameter '%1$s' must be either '%2$s' or '%3$s'.", PARAM_XML_SCHEME_NAME,
+					XMI, XCAS), null);
+		}
+
+		fileNamer = InitializableFactory
+				.create(context, fileNamerClassName, XWriterFileNamer.class);
+	}
+
+	@Override
+	public void process(JCas jcas) throws AnalysisEngineProcessException {
+		String fileName = fileNamer.nameFile(jcas);
+		try {
+			if (useXMI) {
+				writeXmi(jcas.getCas(), fileName);
+			}
+			else {
+				writeXCas(jcas.getCas(), fileName);
+			}
+		}
+		catch (IOException e) {
+			throw new AnalysisEngineProcessException(e);
+		}
+		catch (SAXException e) {
+			throw new AnalysisEngineProcessException(e);
+		}
+	}
+
+	private void writeXCas(CAS aCas, String fileName) throws IOException, SAXException {
+		File outFile = new File(outputDirectory, fileName + ".xcas");
+		FileOutputStream out = null;
+		try {
+			out = new FileOutputStream(outFile);
+			XCASSerializer ser = new XCASSerializer(aCas.getTypeSystem());
+			XMLSerializer xmlSer = new XMLSerializer(out, false);
+			ser.serialize(aCas, xmlSer.getContentHandler());
+		}
+		finally {
+			if (out != null) {
+				out.close();
+			}
+		}
+	}
+
+	private void writeXmi(CAS aCas, String id) throws IOException, SAXException {
+		File outFile = new File(outputDirectory, id + ".xmi");
+		FileOutputStream out = null;
+
+		try {
+			out = new FileOutputStream(outFile);
+			XmiCasSerializer ser = new XmiCasSerializer(aCas.getTypeSystem());
+			XMLSerializer xmlSer = new XMLSerializer(out, false);
+			ser.serialize(aCas, xmlSer.getContentHandler());
+		}
+		finally {
+			if (out != null) {
+				out.close();
+			}
+		}
+	}
+
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/XWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/XWriterFileNamer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/XWriterFileNamer.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/XWriterFileNamer.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/XWriterFileNamer.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,44 @@
+/*
+  Copyright 2010 Regents of the University of Colorado.
+ All rights reserved.
+
+ Licensed 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.uimafit.component.xwriter;
+
+import org.apache.uima.jcas.JCas;
+
+/**
+ * This interface provides {@link XWriter} with a way of getting a file name for a given jCas. If
+ * there is information in {@link JCas} that you can use to name the resulting ".xmi" or ".xcas"
+ * files, then this interface will allow you to use it. Implementation of this interface should come
+ * up with a file name to be used for the file that it is written by {@link XWriter}. Do not specify
+ * the full path and do not specify the suffix (.xmi or .xcas will be automatically appended as
+ * appropriate)
+ * 
+ * @author Philip Ogren
+ */
+public interface XWriterFileNamer {
+	/**
+	 * Get file name to be used for the file that it is written by {@link XWriter}.
+	 * 
+	 * @param jCas
+	 *            a file namer should be able to generate a name from a given JCas to be used for
+	 *            creating a file name
+	 * @return a name for the file to be used for creating a file name Do not specify the full path
+	 *         and do not specify the suffix (.xmi or .xcas will be automatically appended as
+	 *         appropriate)
+	 */
+	public String nameFile(JCas jCas);
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/component/xwriter/XWriterFileNamer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ConfigurationParameter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ConfigurationParameter.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ConfigurationParameter.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ConfigurationParameter.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,106 @@
+/*
+ Copyright 2009-2010	Regents of the University of Colorado.
+ All rights reserved.
+
+ Licensed 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.uimafit.descriptor;
+
+import java.io.File;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.net.URI;
+import java.net.URL;
+import java.util.Locale;
+import java.util.regex.Pattern;
+
+import org.uimafit.component.initialize.ConfigurationParameterInitializer;
+import org.uimafit.factory.ConfigurationParameterFactory;
+
+/**
+ * This annotation marks an analysis component member variable as a configuration parameter. The
+ * types of member variables that can use this annotation are:
+ * <ul>
+ * <li>primitive types and arrays: {@code boolean}, {@code boolean[]}, {@code int}, {@code int[]},
+ * {@code float}, {@code float[]}</li>
+ * <li>primitive object wrapper types and arrays: {@link Boolean}, {@link Boolean}{@code []},
+ * {@link Integer}, {@link Integer}{@code []}, {@link Float}, {@link Float}{@code []}</li>
+ * <li>strings and string arrays: {@link String}, {@link String}{@code []}</li>
+ * <li>enumeration types ({@link Enum})</li>
+ * <li>language/locale: {@link Locale}</li>
+ * <li>regular expression patterns: {@link Pattern}</li>
+ * <li>all other types that have a constructor that takes a string as the single argument, e.g.:
+ * {@link File}, {@link URL}, {@link URI} ...</li>
+ * </ul>
+ *
+ * @author Philip Ogren
+ * @see ConfigurationParameterInitializer
+ */
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface ConfigurationParameter {
+
+	/**
+	 * the default value for name if none is given.
+	 */
+	public static final String USE_FIELD_NAME = "org.uimafit.descriptor.ConfigurationParameter.USE_FIELD_NAME";
+
+	/**
+	 * If you do not specify a name then the default name will be given by {@link #USE_FIELD_NAME}
+	 * will be the default name. This tells ConfigurationParameterFactory to use the name of the
+	 * annotated field as the name of the configuration parameter. The exact name that is used is
+	 * determined by the method
+	 * {@link ConfigurationParameterFactory#getConfigurationParameterName(java.lang.reflect.Field)}
+	 */
+	String name() default USE_FIELD_NAME;
+
+	/**
+	 * A description for the configuration parameter
+	 */
+	String description() default "";
+
+	/**
+	 * specifies whether this configuration parameter is mandatory - i.e. the value must be provided
+	 */
+	boolean mandatory() default false;
+
+	/**
+	 * What can be the value should correspond with the type of the field that is annotated. If for
+	 * example, the field is a String, then the default value can be any string - e.g. "asdf". If
+	 * the field is a boolean, then the default value can be "true" for true or any other string for
+	 * false. If the field is an integer, then the default value can be any string that
+	 * Integer.parseInt() can successfully parse. Remember that just because the default value is a
+	 * string here that you should give an actual integer (not an integer parseable string) value
+	 * when setting the parameter via e.g. AnalysisEngineFactory.createPrimitiveDescription(). If
+	 * the field is a float, then the default value can be any string that Float.parseFloat() can
+	 * successfully parse. Remember that just because the default value is a string here that you
+	 * should give an actual float value (not a float parseable string) when setting the parameter
+	 * via e.g. AnalysisEngineFactory.createPrimitiveDescription().
+	 * <p>
+	 * If the field is multiValued, then the value should look something like this '{"value1",
+	 * "value2"}'
+	 * <p>
+	 * If you want a field to be initialized with a null value, then do not specify a default value
+	 * or specify the value given by the field {@link #NO_DEFAULT_VALUE}
+	 */
+	String[] defaultValue() default NO_DEFAULT_VALUE;
+
+	/**
+	 * Tells the ConfigurationParameterFactory that no default value has been provided
+	 */
+	public static final String NO_DEFAULT_VALUE = "org.uimafit.descriptor.ConfigurationParameter.NO_DEFAULT_VALUE";
+
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ConfigurationParameter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ExternalResource.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ExternalResource.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ExternalResource.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ExternalResource.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,58 @@
+/*
+ Copyright 2009
+ Ubiquitous Knowledge Processing (UKP) Lab
+ Technische Universitaet Darmstadt
+ All rights reserved.
+
+ Licensed 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.uimafit.descriptor;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.uima.resource.Resource;
+
+/**
+ * Mark a field as external resource.
+ * 
+ * @author Richard Eckart de Castilho
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface ExternalResource {
+	/**
+	 * The key to which external resources bind to. If no key is set, the class name of the
+	 * annotated field will be used.
+	 * 
+	 * @return the key;
+	 */
+	String key() default "";
+
+	/**
+	 * The interface that external resources need to implement. Normally this has to be the type of
+	 * the field, but if {@link ExternalResourceLocator}s are used, this should be set to
+	 * {@link ExternalResourceLocator} or to a derived interface.
+	 * 
+	 * @return the required interface.
+	 */
+	Class<? extends Resource> api() default Resource.class;
+
+	/**
+	 * Determines if this external resource is mandatory.
+	 */
+	boolean mandatory() default true;
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ExternalResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ExternalResourceLocator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ExternalResourceLocator.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ExternalResourceLocator.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ExternalResourceLocator.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,41 @@
+/*
+ Copyright 2009
+ Ubiquitous Knowledge Processing (UKP) Lab
+ Technische Universitaet Darmstadt
+ All rights reserved.
+
+ Licensed 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.uimafit.descriptor;
+
+import org.apache.uima.resource.Resource;
+
+/**
+ * Get instance of external resource. This resource implements the {@link Resource} interface and
+ * can thus be used as an external resource. However, it serves only as a proxy to get the actual
+ * shared resource. Parameters that help locating the shared resource can be passed using the
+ * regular UIMA external resources mechanism.
+ * <p>
+ * A {@link ExternalResourceLocator} can be bound to a component field of the type of resource it
+ * produces.
+ * 
+ * @see ExternalResource#api()
+ * @author Richard Eckart de Castilho
+ */
+public interface ExternalResourceLocator extends Resource {
+	/**
+	 * @return the resource
+	 */
+	public Object getResource();
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/ExternalResourceLocator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndex.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndex.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndex.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndex.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,85 @@
+/*
+ Copyright 2011
+ Ubiquitous Knowledge Processing (UKP) Lab
+ Technische Universitaet Darmstadt
+ All rights reserved.
+
+ Licensed 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.uimafit.descriptor;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.uima.jcas.cas.TOP;
+import org.apache.uima.resource.metadata.FsIndexDescription;
+import org.apache.uima.resource.metadata.FsIndexKeyDescription;
+import org.uimafit.factory.FsIndexFactory;
+
+/**
+ * @author Richard Eckart de Castilho
+ * @see FsIndexDescription
+ * @see FsIndexFactory
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface FsIndex {
+	/**
+	 * @see FsIndexDescription#KIND_SORTED
+	 */
+	public static final String KIND_SORTED = FsIndexDescription.KIND_SORTED;
+
+	/**
+	 * @see FsIndexDescription#KIND_SET
+	 */
+	public static final String KIND_SET = FsIndexDescription.KIND_SET;
+
+	/**
+	 * @see FsIndexDescription#KIND_BAG
+	 */
+	public static final String KIND_BAG = FsIndexDescription.KIND_BAG;
+
+	/**
+	 * @see FsIndexDescription#getLabel()
+	 */
+	String label();
+
+	/**
+	 * @see FsIndexDescription#getTypeName()
+	 */
+	String typeName() default NO_NAME_TYPE_SET;
+
+	Class<? extends TOP> type() default NoClassSet.class;
+
+	/**
+	 * @see FsIndexDescription#getKind()
+	 */
+	String kind() default KIND_BAG;
+
+	/**
+	 * @see FsIndexDescription#getKeys()
+	 */
+	FsIndexKey[] keys() default {};
+
+	/**
+	 * @see FsIndexKeyDescription#isTypePriority()
+	 */
+	boolean typePriorities() default true;
+
+	public static final class NoClassSet extends TOP { /* Nothing */ }
+
+	public static final String NO_NAME_TYPE_SET = "org.uimafit.descriptor.FsIndex.NO_NAME_TYPE_SET";
+
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndex.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndexCollection.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndexCollection.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndexCollection.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndexCollection.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,40 @@
+/*
+ Copyright 2011
+ Ubiquitous Knowledge Processing (UKP) Lab
+ Technische Universitaet Darmstadt
+ All rights reserved.
+
+ Licensed 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.uimafit.descriptor;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.uimafit.factory.FsIndexFactory;
+
+/**
+ * @author Richard Eckart de Castilho
+ * @see org.apache.uima.resource.metadata.FsIndexCollection
+ * @see FsIndexFactory
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface FsIndexCollection {
+	/**
+	 * @see org.apache.uima.resource.metadata.FsIndexCollection#getFsIndexes()
+	 */
+	FsIndex[] fsIndexes();
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndexCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndexKey.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndexKey.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndexKey.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndexKey.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,56 @@
+/*
+ Copyright 2011
+ Ubiquitous Knowledge Processing (UKP) Lab
+ Technische Universitaet Darmstadt
+ All rights reserved.
+
+ Licensed 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.uimafit.descriptor;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.uima.resource.metadata.FsIndexKeyDescription;
+import org.uimafit.factory.FsIndexFactory;
+
+/**
+ * @author Richard Eckart de Castilho
+ * @see FsIndexKeyDescription
+ * @see FsIndexFactory
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface FsIndexKey {
+	/**
+	 * @see FsIndexKeyDescription#STANDARD_COMPARE
+	 */
+	public static final int STANDARD_COMPARE = FsIndexKeyDescription.STANDARD_COMPARE;
+
+	/**
+	 * @see FsIndexKeyDescription#REVERSE_STANDARD_COMPARE
+	 */
+	public static final int REVERSE_STANDARD_COMPARE = FsIndexKeyDescription.REVERSE_STANDARD_COMPARE;
+
+	/**
+	 * @see FsIndexKeyDescription#getFeatureName()
+	 */
+	String featureName();
+
+	/**
+	 * @see FsIndexKeyDescription#getComparator()
+	 */
+	int comparator() default STANDARD_COMPARE;
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/FsIndexKey.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/OperationalProperties.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/OperationalProperties.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/OperationalProperties.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/OperationalProperties.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,84 @@
+/*
+ Copyright 2009
+ Ubiquitous Knowledge Processing (UKP) Lab
+ Technische Universitaet Darmstadt
+ All rights reserved.
+
+ Licensed 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.
+
+ JavaDoc for multipleDeploymentAllowed(), modifiesCas() and outputsNewCases() is duplicated from
+ org.apache.uima.resource.metadata.OperationalProperties for sake of the users' convenience. The
+ copied JavaDoc is licensed as under the Apache 2.0 license as well. No particular author
+ attribution was given in the original source file.
+ */
+
+package org.uimafit.descriptor;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.uima.analysis_engine.AnalysisEngine;
+
+/**
+ * Control aspects of the UIMA analysis component.<br/>
+ * 
+ * @author Richard Eckart de Castilho
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface OperationalProperties {
+	/**
+	 * the default value for multipleDeploymentAllowed if none is given.
+	 */
+	public static final boolean MULTIPLE_DEPLOYMENT_ALLOWED_DEFAULT = true;
+	/**
+	 * the default value for modifiesCas if none is given
+	 */
+	public static final boolean MODIFIES_CAS_DEFAULT = true;
+	/**
+	 * the default value for outputsNewCases if none is given
+	 */
+	public static final boolean OUTPUTS_NEW_CASES_DEFAULT = false;
+
+	/**
+	 * Gets whether multiple instances of this component can be run in parallel, each receiving a
+	 * subset of the documents from a collection.
+	 * 
+	 * @return true if multiple instances can be run in parallel, false if not
+	 * @see org.apache.uima.resource.metadata.OperationalProperties#isMultipleDeploymentAllowed()
+	 */
+	boolean multipleDeploymentAllowed() default MULTIPLE_DEPLOYMENT_ALLOWED_DEFAULT;
+
+	/**
+	 * Gets whether this component will modify the CAS.
+	 * 
+	 * @return true if this component modifies the CAS, false if it does not.
+	 * @see org.apache.uima.resource.metadata.OperationalProperties#getModifiesCas()
+	 */
+	boolean modifiesCas() default MODIFIES_CAS_DEFAULT;
+
+	/**
+	 * Gets whether this AnalysisEngine may output new CASes. If this property is set to true, an
+	 * application can use the
+	 * {@link AnalysisEngine#processAndOutputNewCASes(org.apache.uima.cas.CAS)} to pass a CAS to
+	 * this this AnalysisEngine and then step through all of the output CASes that it produces. For
+	 * example, such an AnalysisEngine could segment a CAS into smaller pieces, emitting each as a
+	 * separate CAS.
+	 * 
+	 * @return true if this component may output new CASes, false if it does not
+	 * @see org.apache.uima.resource.metadata.OperationalProperties#getOutputsNewCASes()
+	 */
+	boolean outputsNewCases() default OUTPUTS_NEW_CASES_DEFAULT;
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/OperationalProperties.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/SofaCapability.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/SofaCapability.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/SofaCapability.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/SofaCapability.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,72 @@
+/*
+ Copyright 2009-2010	Regents of the University of Colorado.
+ All rights reserved.
+
+ Licensed 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.uimafit.descriptor;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 
+ * <pre>
+ *   		@SofaCapability(inputSofas = { GOLD_VIEW, SYSTEM_VIEW })
+ *   		or
+ *   		@SofaCapability(inputSofas = CAS.NAME_DEFAULT_SOFA, outputSofas = GOLD_VIEW)
+ * </pre>
+ * 
+ * Adding this annotation to your analysis engine description makes your component "sofa aware." The
+ * base CAS delivered to "sofa aware" components has no explicit view associated with it. The logic
+ * is that it is impossible to know the intent of a sofa aware component and it should use getView
+ * as needed. You should therefore be aware that if you need to work with the "_InitialView" view,
+ * then you must explicitly request it with a call like:
+ * 
+ * JCas initialView = jCas.getView(CAS.NAME_DEFAULT_SOFA);
+ * 
+ * This is because the base CAS that it passed into the process method to "sofa aware" components is
+ * not the same as the "_InitialView". See how the following member variable is used to understand
+ * why/how:
+ * 
+ * org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl. mSofaAware
+ * 
+ * @author Philip Ogren A typical use of this annotation might look something like:
+ */
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface SofaCapability {
+	/**
+	 * the values should be string vales corresponding to view names such as e.g.
+	 * CAS.NAME_DEFAULT_SOFA that this analysis component expects to be present in the CAS.
+	 */
+	String[] inputSofas() default NO_DEFAULT_VALUE;
+
+	/**
+	 * the values should be string vales corresponding to view names that this analysis component
+	 * will create.
+	 */
+	String[] outputSofas() default NO_DEFAULT_VALUE;
+
+	/**
+	 * Provides the default value for the inputs and the outputs that tells the CapabilityFactory
+	 * that no value has been given to the inputs or outputs elements.
+	 */
+
+	public static final String NO_DEFAULT_VALUE = "org.uimafit.descriptor.SofaCapability.NO_DEFAULT_VALUE";
+
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/SofaCapability.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/TypeCapability.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/TypeCapability.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/TypeCapability.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/TypeCapability.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,65 @@
+/*
+ Copyright 2010 Regents of the University of Colorado.
+ All rights reserved.
+
+ Licensed 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.uimafit.descriptor;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A typical use of this annotation might look something like:
+ * 
+ * <pre>
+ *  	@TypeCapability(inputs="org.uimafit.type.Token", outputs="org.uimafit.type.Token:pos")
+ * </pre>
+ * 
+ * or
+ * 
+ * <pre>
+ *  	@TypeCapability(inputs={"org.uimafit.type.Token","org.uimafit.type.Sentence"}, outputs={"org.uimafit.type.Token:pos", "org.apache.uima.tutorial.RoomNumber"})
+ * </pre>
+ * 
+ * @author Philip Ogren
+ */
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface TypeCapability {
+
+	/**
+	 * inputs can be type names or feature names. A feature name typically looks like a type name
+	 * followed by a colon (':') followed by the feature name. A valid feature name from the uimaFIT
+	 * test type system is "org.uimafit.type.Token:pos"
+	 * 
+	 */
+	String[] inputs() default NO_DEFAULT_VALUE;
+
+	/**
+	 * outputs can be type names or feature names. A feature name typically looks like a type name
+	 * followed by a colon (':') followed by the feature name. A valid feature name from the uimaFIT
+	 * test type system is "org.uimafit.type.Token:pos"
+	 */
+	String[] outputs() default NO_DEFAULT_VALUE;
+
+	/**
+	 * Provides the default value for the inputs and the outputs that tells the CapabilityFactory
+	 * that no value has been given to the inputs or outputs elements.
+	 */
+	public static final String NO_DEFAULT_VALUE = "org.uimafit.descriptor.TypeCapability.NO_DEFAULT_VALUE";
+}

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/TypeCapability.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/package-info.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/package-info.java?rev=1420449&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/package-info.java (added)
+++ uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/package-info.java Tue Dec 11 22:02:45 2012
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright 2010
+ * Ubiquitous Knowledge Processing (UKP) Lab
+ * Technische Universität Darmstadt
+ *
+ * Licensed 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.
+ ******************************************************************************/
+
+/**
+ * uimaFIT annotations used for dependency injection.
+ */
+package org.uimafit.descriptor;

Propchange: uima/sandbox/trunk/uimaFIT/uimafit/src/main/java/org/uimafit/descriptor/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native