You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by jo...@apache.org on 2009/05/22 20:22:41 UTC

svn commit: r777644 - in /incubator/uima/sandbox/trunk/CasEditorEclipsePlugin: plugin.xml src/main/java/org/apache/uima/caseditor/core/model/CasProcessorFolder.java

Author: joern
Date: Fri May 22 18:22:40 2009
New Revision: 777644

URL: http://svn.apache.org/viewvc?rev=777644&view=rev
Log:
UIMA-767

Modified:
    incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/plugin.xml
    incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/core/model/CasProcessorFolder.java

Modified: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/plugin.xml
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/plugin.xml?rev=777644&r1=777643&r2=777644&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/plugin.xml (original)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/plugin.xml Fri May 22 18:22:40 2009
@@ -23,6 +23,29 @@
 <plugin>
    <extension-point id="org.apache.uima.caseditor.editor" name="DocumentProvider" schema="schema/org.apache.uima.caseditor.editor.exsd"/>
 
+	<extension point="org.eclipse.core.contenttype.contentTypes">
+	   <content-type base-type="org.eclipse.core.runtime.xml"
+	                 file-extensions="xml"
+	                 id="org.apache.uima.caseditor.AnalysisEngineDescriptor"
+	                 name="Analysis Engine Descriptor"
+	                 priority="normal">
+	      <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber">
+	         <parameter name="element" value="analysisEngineDescription"/>
+	      </describer>
+	   </content-type>
+	   
+	   <content-type base-type="org.eclipse.core.runtime.xml"
+	                 file-extensions="xml"
+	                 id="org.apache.uima.caseditor.CasConsumerDescriptor"
+	                 name="Cas Consumer Descriptor"
+	                 priority="normal">
+	      <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber">
+	         <parameter name="element" value="casConsumerDescription"/>
+	      </describer>
+	   </content-type>
+	</extension>
+
+
 	<extension point="org.eclipse.ui.views">
 		<category id="org.apache.uima.caseditor.ui.views" name="NLP" />
 

Modified: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/core/model/CasProcessorFolder.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/core/model/CasProcessorFolder.java?rev=777644&r1=777643&r2=777644&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/core/model/CasProcessorFolder.java (original)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/core/model/CasProcessorFolder.java Fri May 22 18:22:40 2009
@@ -29,12 +29,18 @@
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.content.IContentDescription;
+import org.eclipse.core.runtime.content.IContentType;
 
 /**
- * The UimaSourceFolder contains folders, each of these folders can contain uima consumer or
+ * The UimaSourceFolder contains folders, each of these folders can contain UIMA consumer or
  * annotator configurations.
  */
 public class CasProcessorFolder extends AbstractNlpElement implements IAdaptable {
+  
+  private static final String CONSUMER_DESCRIPTOR_ID = "org.apache.uima.caseditor.CasConsumerDescriptor";
+  private static final String ANALYSIS_ENGINE_DESCRIPTOR_ID = "org.apache.uima.caseditor.AnalysisEngineDescriptor";
+  
   private IFolder mConfigFolder;
 
   private NlpProject mProject;
@@ -67,14 +73,49 @@
     return mAnnotators;
   }
 
+  private boolean isConsumerDescriptorFile(IResource resource) throws CoreException {
+    
+    boolean isConsumerDescritporFile = false;
+    
+    if (resource instanceof IFile) {
+      IContentDescription contentDescription = ((IFile) resource).getContentDescription();
+     
+      if (contentDescription != null) {
+        IContentType contentType = contentDescription.getContentType();
+        
+        isConsumerDescritporFile = 
+                contentType != null && CONSUMER_DESCRIPTOR_ID.equals(contentType.getId());
+      }
+    }
+    
+    return isConsumerDescritporFile;
+  }
+
+  private boolean isAnalysisEngineDescriptorFile(IResource resource) throws CoreException {
+    
+    boolean isAnalysisEngineDescriptorFile = false;
+    
+    if (resource instanceof IFile) {
+      IContentDescription contentDescription = ((IFile) resource).getContentDescription();
+      
+      if (contentDescription != null) {
+        IContentType contentType = contentDescription.getContentType();
+        
+        isAnalysisEngineDescriptorFile = 
+                contentType != null && ANALYSIS_ENGINE_DESCRIPTOR_ID.equals(contentType.getId());
+
+      }
+    }
+    
+    return isAnalysisEngineDescriptorFile;
+  }  
+  
   private void createAnnotatorConfigurations() throws CoreException {
     mAnnotators = new LinkedList<AnnotatorElement>();
 
     for (IResource resource : mConfigFolder.members()) {
-      if (resource instanceof IFile && resource.getName().endsWith(".ann")) {
-        IFile consumerFile = (IFile) resource;
-
-        AnnotatorElement annotator = new AnnotatorElement(this, consumerFile);
+      if (isAnalysisEngineDescriptorFile(resource)) {
+        AnnotatorElement annotator = new AnnotatorElement(this, (IFile) resource);
         mAnnotators.add(annotator);
       }
     }
@@ -93,14 +134,13 @@
     mConsumers = new LinkedList<ConsumerElement>();
 
     for (IResource resource : mConfigFolder.members()) {
-      if (resource instanceof IFile && resource.getName().endsWith(".con")) {
+      if (isConsumerDescriptorFile(resource)) {
         IFile consumerFile = (IFile) resource;
 
         ConsumerElement consumer = new ConsumerElement(this, consumerFile);
         mConsumers.add(consumer);
       }
     }
-
   }
 
   /**
@@ -110,11 +150,11 @@
    * @throws CoreException
    */
   public Collection<IResource> getNonNlpResources() throws CoreException {
-    // just filter all .con and .ann files
+    
     Collection<IResource> resources = new LinkedList<IResource>();
 
     for (IResource candidate : mConfigFolder.members()) {
-      if (candidate.getName().endsWith(".con") || candidate.getName().endsWith(".ann")) {
+      if (isConsumerDescriptorFile(candidate) || isAnalysisEngineDescriptorFile(candidate)) {
         continue;
       }
 
@@ -205,45 +245,33 @@
   }
 
   /**
-   * Not implemented.
+   * Adds a consumer or analysis engine descriptor to the CAS processor folder.
    */
   @Override
   void addResource(INlpElementDelta delta, IResource resource) throws CoreException {
-    if (resource instanceof IFile) {
-      // if .con file notify it
-      if (resource.getName().endsWith(".con")) {
-        ConsumerElement consumerElement = new ConsumerElement(this, (IFile) resource);
-        mConsumers.add(consumerElement);
-      } else if (resource.getName().endsWith(".ann")) {
-        AnnotatorElement annotator = new AnnotatorElement(this, (IFile) resource);
 
-        mAnnotators.add(annotator);
-      } else {
-        // do nothing
-      }
+    if (isConsumerDescriptorFile(resource)) {
+      mConsumers.add(new ConsumerElement(this, (IFile) resource));
+    } else if (isAnalysisEngineDescriptorFile(resource)) {
+      mAnnotators.add(new AnnotatorElement(this, (IFile) resource));
     }
   }
 
   @Override
   void changedResource(IResource resource, INlpElementDelta delta) throws CoreException {
-    if (resource instanceof IFile) {
-      // if .con file notify it
-      if (resource.getName().endsWith(".con")) {
-        for (ConsumerElement consumer : mConsumers) {
-          if (consumer.getResource().equals(resource)) {
-            consumer.changedResource(resource, delta);
-            break;
-          }
+    if (isConsumerDescriptorFile(resource)) {
+      for (ConsumerElement consumer : mConsumers) {
+        if (consumer.getResource().equals(resource)) {
+          consumer.changedResource(resource, delta);
+          break;
         }
-      } else if (resource.getName().endsWith(".ann")) {
-        for (AnnotatorElement annotator : mAnnotators) {
-          if (annotator.getResource().equals(resource)) {
-            annotator.changedResource(resource, delta);
-            break;
-          }
+      }
+    } else if (isAnalysisEngineDescriptorFile(resource)) {
+      for (AnnotatorElement annotator : mAnnotators) {
+        if (annotator.getResource().equals(resource)) {
+          annotator.changedResource(resource, delta);
+          break;
         }
-      } else {
-        // do nothing
       }
     }
   }
@@ -252,25 +280,20 @@
    * Not implemented.
    */
   @Override
-  void removeResource(INlpElementDelta delta, IResource resource) {
-    if (resource instanceof IFile) {
-      // if .con file notify it
-      if (resource.getName().endsWith(".con")) {
-        for (ConsumerElement consumer : mConsumers) {
-          if (consumer.getResource().equals(resource)) {
-            mConsumers.remove(consumer);
-            break;
-          }
+  void removeResource(INlpElementDelta delta, IResource resource) throws CoreException {
+    if (isConsumerDescriptorFile(resource)) {
+      for (ConsumerElement consumer : mConsumers) {
+        if (consumer.getResource().equals(resource)) {
+          mConsumers.remove(consumer);
+          break;
         }
-      } else if (resource.getName().endsWith(".ann")) {
-        for (AnnotatorElement annotator : mAnnotators) {
-          if (annotator.getResource().equals(resource)) {
-            mAnnotators.remove(annotator);
-            break;
-          }
+      }
+    } else if (isAnalysisEngineDescriptorFile(resource)) {
+      for (AnnotatorElement annotator : mAnnotators) {
+        if (annotator.getResource().equals(resource)) {
+          mAnnotators.remove(annotator);
+          break;
         }
-      } else {
-        // do nothing
       }
     }
   }