[UIMA-5035] Add support for mime type capabilities

git-svn-id: https://svn.apache.org/repos/asf/uima/uimafit/trunk@1754764 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/uimafit-core/src/main/java/org/apache/uima/fit/descriptor/MimeTypeCapability.java b/uimafit-core/src/main/java/org/apache/uima/fit/descriptor/MimeTypeCapability.java
new file mode 100644
index 0000000..f613105
--- /dev/null
+++ b/uimafit-core/src/main/java/org/apache/uima/fit/descriptor/MimeTypeCapability.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.fit.descriptor;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Provides information on the MIME types supported by a component.
+ * 
+ * <pre><code>
+ * {@literal @}MimeTypeCapability({ "application/xml", "text/html" })
+ * </code></pre>
+ */
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface MimeTypeCapability {
+  /**
+   * The MIME types supported by this component.
+   * 
+   * @return the supported MIME types
+   */
+  String[] value() default NO_DEFAULT_VALUE;
+
+  /**
+   * Provides the default value that tells the CapabilityFactory that no value has been provided.
+   */
+  public static final String NO_DEFAULT_VALUE = "org.apache.uima.fit.descriptor.MimeTypeCapability.NO_DEFAULT_VALUE";
+}
diff --git a/uimafit-core/src/main/java/org/apache/uima/fit/factory/CapabilityFactory.java b/uimafit-core/src/main/java/org/apache/uima/fit/factory/CapabilityFactory.java
index 9795dc4..2ceb547 100644
--- a/uimafit-core/src/main/java/org/apache/uima/fit/factory/CapabilityFactory.java
+++ b/uimafit-core/src/main/java/org/apache/uima/fit/factory/CapabilityFactory.java
@@ -24,6 +24,7 @@
 import org.apache.uima.analysis_engine.TypeOrFeature;
 import org.apache.uima.analysis_engine.impl.TypeOrFeature_impl;
 import org.apache.uima.fit.descriptor.LanguageCapability;
+import org.apache.uima.fit.descriptor.MimeTypeCapability;
 import org.apache.uima.fit.descriptor.SofaCapability;
 import org.apache.uima.fit.descriptor.TypeCapability;
 import org.apache.uima.fit.internal.ReflectionUtil;
@@ -63,6 +64,16 @@
       capability.setLanguagesSupported(languages);
     }
     
+    if (ReflectionUtil.isAnnotationPresent(componentClass, MimeTypeCapability.class)) {
+      MimeTypeCapability annotation = ReflectionUtil.getAnnotation(componentClass,
+              MimeTypeCapability.class);
+      String[] mimeTypes = annotation.value();
+      if (mimeTypes.length == 1 && mimeTypes[0].equals(MimeTypeCapability.NO_DEFAULT_VALUE)) {
+        mimeTypes = new String[0];
+      }
+      capability.setMimeTypesSupported(mimeTypes);
+    }
+    
     if (ReflectionUtil.isAnnotationPresent(componentClass, SofaCapability.class)) {
       SofaCapability annotation = ReflectionUtil.getAnnotation(componentClass, SofaCapability.class);
       String[] inputSofas = annotation.inputSofas();
diff --git a/uimafit-core/src/test/java/org/apache/uima/fit/factory/testAes/SerializationTestAnnotator.java b/uimafit-core/src/test/java/org/apache/uima/fit/factory/testAes/SerializationTestAnnotator.java
index 4eff307..b04e129 100644
--- a/uimafit-core/src/test/java/org/apache/uima/fit/factory/testAes/SerializationTestAnnotator.java
+++ b/uimafit-core/src/test/java/org/apache/uima/fit/factory/testAes/SerializationTestAnnotator.java
@@ -21,6 +21,7 @@
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
 import org.apache.uima.fit.descriptor.LanguageCapability;
+import org.apache.uima.fit.descriptor.MimeTypeCapability;
 import org.apache.uima.fit.descriptor.SofaCapability;
 import org.apache.uima.jcas.JCas;
 
@@ -28,6 +29,7 @@
  * Used to test if metadata gets correctly serialized to XML.
  */
 @LanguageCapability({"en", "de"})
+@MimeTypeCapability({ "application/xml", "text/html" })
 @SofaCapability(inputSofas = "input1", outputSofas = "output1")
 public class SerializationTestAnnotator extends JCasAnnotator_ImplBase {
 
diff --git a/uimafit-core/src/test/resources/data/reference/SerializationTestAnnotator.xml b/uimafit-core/src/test/resources/data/reference/SerializationTestAnnotator.xml
index 887250d..b7ad5c0 100644
--- a/uimafit-core/src/test/resources/data/reference/SerializationTestAnnotator.xml
+++ b/uimafit-core/src/test/resources/data/reference/SerializationTestAnnotator.xml
@@ -87,6 +87,10 @@
                     <language>en</language>
                     <language>de</language>
                 </languagesSupported>
+                <mimeTypesSupported>
+                    <mimeType>application/xml</mimeType>
+                    <mimeType>text/html</mimeType>
+                </mimeTypesSupported>
             </capability>
         </capabilities>
         <operationalProperties>