Revision: 17155
          http://sourceforge.net/p/gate/code/17155
Author:   markagreenwood
Date:     2013-12-01 16:56:43 +0000 (Sun, 01 Dec 2013)
Log Message:
-----------
some error checking and a little tweak to avoid creating a hidden schema when 
the file only includes other files

Modified Paths:
--------------
    gate/trunk/src/main/gate/creole/AnnotationSchema.java

Modified: gate/trunk/src/main/gate/creole/AnnotationSchema.java
===================================================================
--- gate/trunk/src/main/gate/creole/AnnotationSchema.java       2013-12-01 
16:44:44 UTC (rev 17154)
+++ gate/trunk/src/main/gate/creole/AnnotationSchema.java       2013-12-01 
16:56:43 UTC (rev 17155)
@@ -15,21 +15,26 @@
  */
 package gate.creole;
 
+import gate.Factory;
+import gate.FeatureMap;
+import gate.Resource;
+import gate.creole.metadata.CreoleParameter;
+import gate.creole.metadata.CreoleResource;
+
 import java.io.InputStream;
 import java.net.URL;
-import java.util.*;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import org.jdom.JDOMException;
 import org.jdom.Namespace;
 import org.jdom.input.SAXBuilder;
 
-import gate.Factory;
-import gate.FeatureMap;
-import gate.Gate;
-import gate.Resource;
-import gate.creole.metadata.CreoleParameter;
-import gate.creole.metadata.CreoleResource;
-
 /** This class handles annotation schemas.An annotation schema is a
   * representation of an annotation, together with its types and their
   * attributes, values and types.
@@ -126,11 +131,16 @@
     // parse the XML file if we have its URL
     if(xmlFileUrl != null) {
       fromXSchema(xmlFileUrl);
-      
-      if (annotationName == null) {
-        Gate.setHiddenAttribute(getFeatures(), true);
+
+      if(annotationName == null) {
+        Factory.deleteResource(this);
+
+        if(lastIncluded != null) return lastIncluded;
+
+        throw new ResourceInstantiationException(
+                "The specified XML Schema doesn't define any annotation 
types");
       }
-    }    
+    }
 
     return this;
   } // init()
@@ -142,6 +152,8 @@
    * The namepsace used in the xml file
    */
   protected Namespace namespace;
+  
+  private transient AnnotationSchema lastIncluded = null;
 
   /** Set method for the resource xml file URL */
   @CreoleParameter(comment="The url to the definition file", 
suffixes="xml;xsd")
@@ -201,29 +213,33 @@
     namespace = rootElement.getNamespace();
     
     // get all children elements from the rootElement
-    //TODO if there is more than one throw an exception as they will overwrite 
each other
-    List rootElementChildrenList = rootElement.getChildren("element", 
namespace);
+    List rootElementChildrenList =
+            rootElement.getChildren("element", namespace);
+    if(rootElementChildrenList.size() > 1)
+      throw new ResourceInstantiationException(
+              "Each Annotation must be defined in a separate XML Schema file");
     Iterator rootElementChildrenIterator = rootElementChildrenList.iterator();
-    while (rootElementChildrenIterator.hasNext()){
+    while(rootElementChildrenIterator.hasNext()) {
       org.jdom.Element childElement =
-                        (org.jdom.Element) rootElementChildrenIterator.next();
+              (org.jdom.Element)rootElementChildrenIterator.next();
       createAnnotationSchemaObject(childElement);
-    }//end while
+    }// end while
     
     rootElementChildrenList = rootElement.getChildren("include", namespace);
     rootElementChildrenIterator = rootElementChildrenList.iterator();
-    while (rootElementChildrenIterator.hasNext()){
+    while(rootElementChildrenIterator.hasNext()) {
       org.jdom.Element childElement =
-              (org.jdom.Element) rootElementChildrenIterator.next();
-      
+              (org.jdom.Element)rootElementChildrenIterator.next();
+
       try {
-          String url = childElement.getAttributeValue("schemaLocation");
-          FeatureMap params = Factory.newFeatureMap();
-          params.put("xmlFileUrl", new URL(xmlFileUrl,url));
-      
-          Factory.createResource("gate.creole.AnnotationSchema", params);
-      }
-      catch (Exception e) {
+        String url = childElement.getAttributeValue("schemaLocation");
+        FeatureMap params = Factory.newFeatureMap();
+        params.put("xmlFileUrl", new URL(xmlFileUrl, url));
+
+        lastIncluded =
+                (AnnotationSchema)Factory.createResource(
+                        "gate.creole.AnnotationSchema", params);
+      } catch(Exception e) {
         throw new ResourceInstantiationException(e);
       }
     }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to