You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2007/11/16 17:52:49 UTC

svn commit: r595734 - in /incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config: ConfigFactory.java ServerSpec.java impl/ServerSpecImpl.java impl/XmlConfigReader.java

Author: twgoetz
Date: Fri Nov 16 08:52:49 2007
New Revision: 595734

URL: http://svn.apache.org/viewvc?rev=595734&view=rev
Log:
Jira UIMA-632: add config xml reading to SimpleServer.

https://issues.apache.org/jira/browse/UIMA-632

Modified:
    incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/ConfigFactory.java
    incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/ServerSpec.java
    incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/ServerSpecImpl.java
    incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/XmlConfigReader.java

Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/ConfigFactory.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/ConfigFactory.java?rev=595734&r1=595733&r2=595734&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/ConfigFactory.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/ConfigFactory.java Fri Nov 16 08:52:49 2007
@@ -97,10 +97,18 @@
     return new SimpleFilterImpl(featurePath, condition);
   }
 
+  /**
+   * Create a new filter conjunction.
+   * @return A new filter conjunction.
+   */
   public static AndFilter newAndFilter() {
     return new AndFilterImpl();
   }
   
+  /**
+   * Create a new filter disjunction.
+   * @return A new filter disjunction.
+   */
   public static OrFilter newOrFilter() {
     return new OrFilterImpl();
   }

Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/ServerSpec.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/ServerSpec.java?rev=595734&r1=595733&r2=595734&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/ServerSpec.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/ServerSpec.java Fri Nov 16 08:52:49 2007
@@ -21,20 +21,56 @@
 
 import java.util.List;
 
-/*
- * represents the whole ResultSpecification XML file.
- * Consists of a collection of type specifications.
+import org.apache.uima.cas.TypeSystem;
+
+/**
+ * Output specification for a simple service.
  */
 public interface ServerSpec {
-  
+
+  /**
+   * The path separator of feature paths: /.
+   */
   public static final char PATH_SEPARATOR = '/';
 
+  /**
+   * @return A list of type specifications. Each type specification represents output specifications
+   *         for a single CAS type.
+   */
   public List<TypeMap> getTypeSpecs();
 
+  /**
+   * Add a type map to an existing spec.
+   * 
+   * @param typeMap
+   *                The input type map to be added.
+   */
   public void addTypeMap(TypeMap typeMap);
 
+  /**
+   * Get the service's short description.
+   * 
+   * @return The short description.
+   */
   public String getShortDescription();
 
+  /**
+   * Get the service's long description.
+   * 
+   * @return The long description.
+   */
   public String getLongDescription();
+
+  /**
+   * Validate a service spec with respect to a type system. Check that types and feature paths
+   * exist.  None of the errors found here need to be considered fatal.  A non-existing type simply
+   * means a type spec that will never produce any output.  Similarly, an invalid feature path means
+   * a filter that will never match or an output spec that will never produce output.  Server-side,
+   * it's probably valid to simply log those errors and carry on.
+   * 
+   * @param typeSystem
+   * @return
+   */
+  public List<SimpleServerException> validate(TypeSystem typeSystem);
 
 }

Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/ServerSpecImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/ServerSpecImpl.java?rev=595734&r1=595733&r2=595734&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/ServerSpecImpl.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/ServerSpecImpl.java Fri Nov 16 08:52:49 2007
@@ -23,7 +23,9 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.uima.cas.TypeSystem;
 import org.apache.uima.simpleserver.config.ServerSpec;
+import org.apache.uima.simpleserver.config.SimpleServerException;
 import org.apache.uima.simpleserver.config.TypeMap;
 
 /**
@@ -57,6 +59,11 @@
 
   public List<TypeMap> getTypeSpecs() {
     return this.typeMaps;
+  }
+
+  public List<SimpleServerException> validate(TypeSystem typeSystem) {
+    // TODO Auto-generated method stub
+    return null;
   }
 
 }

Modified: incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/XmlConfigReader.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/XmlConfigReader.java?rev=595734&r1=595733&r2=595734&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/XmlConfigReader.java (original)
+++ incubator/uima/sandbox/trunk/SimpleServer/src/main/java/org/apache/uima/simpleserver/config/impl/XmlConfigReader.java Fri Nov 16 08:52:49 2007
@@ -74,32 +74,45 @@
 
   private static final int GREATER_EQ = FilterOperator.Enum.forString("null").intValue();
 
+  /**
+   * Read a config file.
+   * @param file The config file.
+   * @return The corresponding server spec.
+   * @throws IOException
+   * @throws XmlException XML parsing error.
+   * @throws SimpleServerException Content parsing error.
+   */
   public static ServerSpec readServerSpec(File file) throws IOException, XmlException,
       SimpleServerException {
     return readServerSpec(new BufferedInputStream(new FileInputStream(file)));
   }
 
+  /**
+   * Read a config XML stream.
+   * @param is The XML input stream.
+   * @return The corresponding server spec.
+   * @throws IOException
+   * @throws XmlException XML parsing error.
+   * @throws SimpleServerException Content parsing error.
+   */
   public static ServerSpec readServerSpec(InputStream is) throws IOException, XmlException,
       SimpleServerException {
     UimaSimpleServerSpec specBean = UimaSimpleServerSpecDocument.Factory.parse(is)
         .getUimaSimpleServerSpec();
+
+    // Do validation.  If XML is not valid, throw first error.
     ArrayList<XmlError> validationErrors = new ArrayList<XmlError>();
     XmlOptions validationOptions = new XmlOptions();
     validationOptions.setErrorListener(validationErrors);
-
     boolean isValid = specBean.validate(validationOptions);
-
-    // output the errors if the XML is invalid.
     if (!isValid) {
       Iterator<XmlError> iter = validationErrors.iterator();
-      StringBuffer errorMessages = new StringBuffer();
-      while (iter.hasNext()) {
-        errorMessages.append("\n>> ");
-        errorMessages.append(iter.next());
+      if (iter.hasNext()) {
+        throw new XmlException(iter.next());
       }
-      System.err.println(errorMessages);
     }
 
+    // Create new server spec from XML beans.
     ServerSpec spec = ConfigFactory.newServerSpec(specBean.getShortDescription(), specBean
         .getLongDescription());
     TypeElementType[] typeMaps = specBean.getTypeArray();
@@ -109,9 +122,11 @@
     return spec;
   }
 
+  // Read a type element.
   private static TypeMap readTypeMap(TypeElementType typeBean) throws SimpleServerException {
     boolean coveredText = typeBean.getOutputCoveredText();
     Filter filter = null;
+    // Check if type element has a filter, and what kind of filter it is (atomic filter, and, or).
     if (typeBean.getFilters() != null) {
       Filters filterBean = typeBean.getFilters();
       if (filterBean.getAnd() != null) {
@@ -126,8 +141,11 @@
         coveredText, typeBean.getShortDescription(), typeBean.getLongDescription());
   }
 
+  // Process a filter bean.
   private static final Filter readFilter(FilterType filterBean) throws SimpleServerException {
+    System.out.println(filterBean.toString());
     Filter filter = null;
+    // Need to distinguish the various kinds of filters.
     if (filterBean instanceof And) {
       filter = readAndFilter((And) filterBean);
     } else if (filterBean instanceof Or) {
@@ -138,8 +156,10 @@
     return filter;
   }
 
+  // Parse an AND filter.
   private static final AndFilter readAndFilter(And filterBean) throws SimpleServerException {
     AndFilter filter = ConfigFactory.newAndFilter();
+    // May embed any number of simple filters, conjunctions and disjunctions.
     SimpleFilterType[] simpleFilters = filterBean.getFilterArray();
     And[] andBeans = filterBean.getAndArray();
     Or[] orBeans = filterBean.getOrArray();
@@ -150,6 +170,7 @@
     return filter;
   }
 
+  // Aggregate the various forms of filter arrays into one filter list.
   private static final List<FilterType> getFilters(SimpleFilterType[] simpleFilters,
       And[] andBeans, Or[] orBeans) {
     List<FilterType> list = new ArrayList<FilterType>();
@@ -165,6 +186,7 @@
     return list;
   }
 
+  // Parse an OR filter
   private static final OrFilter readOrFilter(Or filterBean) throws SimpleServerException {
     OrFilter filter = ConfigFactory.newOrFilter();
     SimpleFilterType[] simpleFilters = filterBean.getFilterArray();
@@ -177,6 +199,7 @@
     return filter;
   }
 
+  // Process a simple, atomic filter.
   private static final SimpleFilter readSimpleFilter(SimpleFilterType filterBean)
       throws SimpleServerException {
     List<String> path = parseFeaturePath(filterBean.getFeaturePath());
@@ -184,8 +207,22 @@
     return ConfigFactory.newSimpleFilter(path, condition);
   }
 
+  // Process a condition.  Check that value is set according to the operator.
   private static final Condition readCondition(FilterOperator.Enum operator, String value) {
-    return ConfigFactory.newCondition(readOperator(operator), value);
+    FilterOp op = readOperator(operator);
+    checkCondition(op, value, operator);
+    return ConfigFactory.newCondition(op, value);
+  }
+  
+  private static final void checkCondition(FilterOp op, String value, FilterOperator.Enum opBean) {
+
+  }
+  
+  private static final void valueMustBeNull(FilterOp op, String value, FilterOperator.Enum opBean)
+      throws SimpleServerException {
+    if (value != null) {
+      throw new SimpleServerException(null, null);
+    }
   }
 
   private static final FilterOp readOperator(FilterOperator.Enum operator) {