You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2011/10/19 13:53:58 UTC

svn commit: r1186126 - in /uima/uimaj/trunk: uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/ uimaj-ep-cas-editor/ uimaj-ep-cas-editor/schema/ uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/searchStrategy/

Author: pkluegl
Date: Wed Oct 19 11:53:58 2011
New Revision: 1186126

URL: http://svn.apache.org/viewvc?rev=1186126&view=rev
Log:
UIMA-2266
Added extension point for type system search strategies and integrated the extension in the DefaultCasDocumentProvider. Early version, tested only with one external additional strategy. No user settings in the preferences are available yet. The new package needs to be exported, but I have no clue what to do with the generated manifest.

Added:
    uima/uimaj/trunk/uimaj-ep-cas-editor/schema/org.apache.uima.caseditor.searchstrategy.exsd
    uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/searchStrategy/
    uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/searchStrategy/ITypeSystemSearchStrategy.java
    uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/searchStrategy/TypeSystemSearchStrategyFactory.java
Modified:
    uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java
    uima/uimaj/trunk/uimaj-ep-cas-editor/plugin.xml

Modified: uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java?rev=1186126&r1=1186125&r2=1186126&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor-ide/src/main/java/org/apache/uima/caseditor/ide/DefaultCasDocumentProvider.java Wed Oct 19 11:53:58 2011
@@ -23,14 +23,12 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.nio.charset.Charset;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 
 import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.Type;
 import org.apache.uima.cas.TypeSystem;
 import org.apache.uima.caseditor.CasEditorPlugin;
 import org.apache.uima.caseditor.core.model.DefaultColors;
@@ -42,6 +40,8 @@ import org.apache.uima.caseditor.editor.
 import org.apache.uima.caseditor.editor.DocumentUimaImpl;
 import org.apache.uima.caseditor.editor.ICasDocument;
 import org.apache.uima.caseditor.editor.ICasEditor;
+import org.apache.uima.caseditor.editor.searchStrategy.ITypeSystemSearchStrategy;
+import org.apache.uima.caseditor.editor.searchStrategy.TypeSystemSearchStrategyFactory;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IResourceChangeEvent;
@@ -73,8 +73,8 @@ public class DefaultCasDocumentProvider 
         org.apache.uima.caseditor.editor.CasDocumentProvider {
 
   /**
-   * Listens for resource remove/delete event, if the input file for the
-   * editor is removed the editor will be closed.
+   * Listens for resource remove/delete event, if the input file for the editor is removed the
+   * editor will be closed.
    */
   private class DeleteElementListener implements IResourceChangeListener {
 
@@ -93,7 +93,7 @@ public class DefaultCasDocumentProvider 
                     && delta.getResource().getType() == IResource.FILE) {
               if (delta.getKind() == IResourceDelta.REMOVED) {
                 IResource resource = delta.getResource();
-                
+
                 if (resource.equals(fileInput.getFile())) {
                   handleElementDeleted(fileInput);
                 }
@@ -110,97 +110,94 @@ public class DefaultCasDocumentProvider 
       }
     }
   }
-  
+
   private static class FileElementInfo extends ElementInfo {
-    
+
     private DeleteElementListener deleteListener;
-    
+
     FileElementInfo(ElementInfo info) {
       super(info.element);
     }
   }
-  
+
   private class SaveSessionPreferencesTrigger implements IPropertyChangeListener {
     private Object element;
-    
+
     SaveSessionPreferencesTrigger(Object element) {
       this.element = element;
     }
-    
+
     public void propertyChange(PropertyChangeEvent event) {
       IResource tsFile = ResourcesPlugin.getWorkspace().getRoot()
-          .findMember((getTypesystemId(element)));
-      
+              .findMember((getTypesystemId(element)));
+
       PreferenceStore prefStore = (PreferenceStore) getSessionPreferenceStore(element);
-      
+
       ByteArrayOutputStream prefBytes = new ByteArrayOutputStream();
       try {
         prefStore.save(prefBytes, "");
       } catch (IOException e) {
         CasEditorIdePlugin.log(e);
       }
-      
+
       try {
-        tsFile.setPersistentProperty(
-            new QualifiedName("", CAS_EDITOR_SESSION_PROPERTIES),
-            new String(prefBytes.toByteArray(), "UTF-8"));
+        tsFile.setPersistentProperty(new QualifiedName("", CAS_EDITOR_SESSION_PROPERTIES),
+                new String(prefBytes.toByteArray(), "UTF-8"));
       } catch (CoreException e) {
         CasEditorIdePlugin.log(e);
-      }
-      catch(IOException e) {
+      } catch (IOException e) {
         CasEditorIdePlugin.log(e);
       }
     }
   }
-  
+
   private static final String CAS_EDITOR_SESSION_PROPERTIES = "CAS_EDITOR_SESSION_PROPERTIES";
-  
+
   /**
    * This map resolved an opened document to its associated style object id.
    * 
-   * The tracking is done in the provider because the document element itself
-   * does not has any link to the style object.
+   * The tracking is done in the provider because the document element itself does not has any link
+   * to the style object.
    */
   private Map<String, String> documentToTypeSystemMap = new HashMap<String, String>();
-  
+
   private Map<String, IPreferenceStore> sessionPreferenceStores = new HashMap<String, IPreferenceStore>();
-  
+
   /**
-   * This map resolves a type system to a style. It is used to cache type system
-   * preference instance while the editor is open.
+   * This map resolves a type system to a style. It is used to cache type system preference instance
+   * while the editor is open.
    */
   private Map<String, PreferenceStore> typeSystemPreferences = new HashMap<String, PreferenceStore>();
-  
+
   // UIMA-2245 Remove this method together with the migration code below one day
   private String getStyleFileForTypeSystem(String typeSystemFile) {
     int lastSlashIndex = typeSystemFile.lastIndexOf("/");
-    
+
     String styleId = typeSystemFile.substring(0, lastSlashIndex + 1);
     styleId = styleId + ".style-" + typeSystemFile.substring(lastSlashIndex + 1);
-    
+
     return styleId;
   }
-  
+
   private String getPreferenceFileForTypeSystem(String typeSystemFile) {
     int lastSlashIndex = typeSystemFile.lastIndexOf("/");
-    
+
     String styleId = typeSystemFile.substring(0, lastSlashIndex + 1);
     styleId = styleId + ".pref-" + typeSystemFile.substring(lastSlashIndex + 1);
-    
+
     return styleId;
   }
-  
 
-  
-  private Collection<AnnotationStyle> getConfiguredAnnotationStyles(IPreferenceStore store, TypeSystem types) {
+  private Collection<AnnotationStyle> getConfiguredAnnotationStyles(IPreferenceStore store,
+          TypeSystem types) {
 
     Collection<AnnotationStyle> styles = new HashSet<AnnotationStyle>();
-    
+
     // TODO: for each annotation type, try to retrieve annotation styles
-    
+
     return styles;
   }
-  
+
   @Override
   protected ICasDocument createDocument(Object element) throws CoreException {
     if (element instanceof FileEditorInput) {
@@ -210,21 +207,38 @@ public class DefaultCasDocumentProvider 
 
       // Try to find a type system for the CAS file
       // TODO: Change to only use full path
-      IFile typeSystemFile = null; 
-      
+      IFile typeSystemFile = null;
+
       // First check if a type system is already known or was
       // set by the editor for this specific CAS
-      String typeSystemFileString = documentToTypeSystemMap.get(casFile.getFullPath().toPortableString());
-      
+      String typeSystemFileString = documentToTypeSystemMap.get(casFile.getFullPath()
+              .toPortableString());
+
       if (typeSystemFileString != null)
-        typeSystemFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(typeSystemFileString));
-      
+        typeSystemFile = ResourcesPlugin.getWorkspace().getRoot()
+                .getFile(new Path(typeSystemFileString));
+
       // If non was found get it from project
       if (typeSystemFile == null)
         typeSystemFile = TypeSystemLocationPropertyPage.getTypeSystemLocation(casFile.getProject());
-      
+
+      // use search strategies for finding the type system
+      if (typeSystemFile == null || !typeSystemFile.exists()) {
+        Map<Integer, ITypeSystemSearchStrategy> searchStrategies = TypeSystemSearchStrategyFactory
+                .instance().getSearchStrategies();
+        // TODO sort again for user preference settings
+        Collection<ITypeSystemSearchStrategy> values = searchStrategies.values();
+        for (ITypeSystemSearchStrategy eachStrategy : values) {
+          IFile findTypeSystem = eachStrategy.findTypeSystem(casFile);
+          if (findTypeSystem != null && findTypeSystem.exists()) {
+            typeSystemFile = findTypeSystem;
+            break;
+          }
+        }
+      }
+
       if (typeSystemFile != null && typeSystemFile.exists()) {
-        
+
         // TODO: Update this comment!
         // Try to load a style file for the type system
         // Should be named: ts file name, prefixed with .style-
@@ -232,12 +246,17 @@ public class DefaultCasDocumentProvider 
         // Creating it after the default is changed means that
         // colors could change completely when the a type is
         // added or removed to the type system
-        
-        IFile prefFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(
-                getPreferenceFileForTypeSystem(typeSystemFile.getFullPath().toPortableString())));
-        
-        PreferenceStore tsPrefStore = typeSystemPreferences.get(prefFile.getFullPath().toPortableString());
-        
+
+        IFile prefFile = ResourcesPlugin
+                .getWorkspace()
+                .getRoot()
+                .getFile(
+                        new Path(getPreferenceFileForTypeSystem(typeSystemFile.getFullPath()
+                                .toPortableString())));
+
+        PreferenceStore tsPrefStore = typeSystemPreferences.get(prefFile.getFullPath()
+                .toPortableString());
+
         // If lookup for store failed ...
         if (tsPrefStore == null) {
           if (prefFile.exists()) {
@@ -247,43 +266,47 @@ public class DefaultCasDocumentProvider 
             } catch (IOException e) {
               e.printStackTrace(); // TODO: Handle this correctly!
             }
-          }
-          else {
-            
+          } else {
+
             // UIMA-2245
             // DotCorpus to Eclipse PreferenceStore migration code.
             // If there is DotCorpus style file and not yet a preference store file
-            // the settings from the DotCorpus style file should be written into a preference store file.
-            IFile styleFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(
-                    getStyleFileForTypeSystem(typeSystemFile.getFullPath().toPortableString())));
-            
+            // the settings from the DotCorpus style file should be written into a preference store
+            // file.
+            IFile styleFile = ResourcesPlugin
+                    .getWorkspace()
+                    .getRoot()
+                    .getFile(
+                            new Path(getStyleFileForTypeSystem(typeSystemFile.getFullPath()
+                                    .toPortableString())));
+
             if (styleFile.exists()) {
-              InputStream styleFileIn = null;;
+              InputStream styleFileIn = null;
+              ;
               DotCorpus dotCorpus = null;
               try {
                 styleFileIn = styleFile.getContents();
                 dotCorpus = DotCorpusSerializer.parseDotCorpus(styleFileIn);
-                
-              }
-              finally {
+
+              } finally {
                 if (styleFileIn != null)
-                 try {
-                   styleFileIn.close();
-                 } catch (IOException e) {
-                   CasEditorPlugin.log(e);
-                 }
+                  try {
+                    styleFileIn.close();
+                  } catch (IOException e) {
+                    CasEditorPlugin.log(e);
+                  }
               }
-              
+
               if (dotCorpus != null) {
                 tsPrefStore = new PreferenceStore(prefFile.getName());
                 for (AnnotationStyle style : dotCorpus.getAnnotationStyles()) {
                   AnnotationStyle.putAnnotatationStyleToStore(tsPrefStore, style);
                 }
-                
+
                 for (String shownType : dotCorpus.getShownTypes()) {
                   tsPrefStore.putValue(shownType + ".isShown", "true");
                 }
-                
+
                 ByteArrayOutputStream prefOut = new ByteArrayOutputStream();
                 try {
                   tsPrefStore.save(prefOut, "");
@@ -291,66 +314,64 @@ public class DefaultCasDocumentProvider 
                   // Should never happen!
                   CasEditorPlugin.log(e);
                 }
-                
+
                 // TODO: Do we need to handle exceptions here?
                 prefFile.create(new ByteArrayInputStream(prefOut.toByteArray()), IFile.FORCE, null);
               }
-             }
+            }
           }
-          
+
           // No preference defined, lets use defaults
           if (tsPrefStore == null) {
             tsPrefStore = new PreferenceStore(prefFile.getName());
-            
+
             CAS cas = DocumentUimaImpl.getVirginCAS(typeSystemFile);
             TypeSystem ts = cas.getTypeSystem();
-            
-            Collection<AnnotationStyle> defaultStyles = getConfiguredAnnotationStyles(tsPrefStore, ts);
-            
+
+            Collection<AnnotationStyle> defaultStyles = getConfiguredAnnotationStyles(tsPrefStore,
+                    ts);
+
             Collection<AnnotationStyle> newStyles = DefaultColors.assignColors(ts, defaultStyles);
-            
+
             // TODO: Settings defaults must be moved to the AnnotationEditor
             for (AnnotationStyle style : newStyles) {
               AnnotationStyle.putAnnotatationStyleToStore(tsPrefStore, style);
             }
           }
-          
+
           typeSystemPreferences.put(prefFile.getFullPath().toPortableString(), tsPrefStore);
         }
-        
-        documentToTypeSystemMap.put(casFile.getFullPath().toPortableString(),
-                typeSystemFile.getFullPath().toPortableString());
 
-        
+        documentToTypeSystemMap.put(casFile.getFullPath().toPortableString(), typeSystemFile
+                .getFullPath().toPortableString());
+
         IPreferenceStore store = sessionPreferenceStores.get(getTypesystemId(element));
-        
+
         if (store == null) {
           PreferenceStore newStore = new PreferenceStore();
           sessionPreferenceStores.put(getTypesystemId(element), newStore);
           newStore.addPropertyChangeListener(new SaveSessionPreferencesTrigger(element));
-          
-          String sessionPreferenceString = typeSystemFile.getPersistentProperty(
-                  new QualifiedName("", CAS_EDITOR_SESSION_PROPERTIES));
-          
+
+          String sessionPreferenceString = typeSystemFile.getPersistentProperty(new QualifiedName(
+                  "", CAS_EDITOR_SESSION_PROPERTIES));
+
           if (sessionPreferenceString != null) {
             try {
-              newStore.load(new ByteArrayInputStream(
-                      sessionPreferenceString.getBytes("UTF-8")));
+              newStore.load(new ByteArrayInputStream(sessionPreferenceString.getBytes("UTF-8")));
             } catch (IOException e) {
               CasEditorPlugin.log(e);
             }
           }
         }
-        
-        
+
         // TODO:
         // Preferences are bound to the type system
         // Changed in one place, then it should change in all places
-        
+
         CAS cas = DocumentUimaImpl.getVirginCAS(typeSystemFile);
-  
+
         DocumentFormat documentFormat;
-  
+
         // Which file format to use ?
         if (casFile.getName().endsWith("xmi")) {
           documentFormat = DocumentFormat.XMI;
@@ -360,7 +381,7 @@ public class DefaultCasDocumentProvider 
           throw new CoreException(new Status(IStatus.ERROR, "org.apache.uima.dev",
                   "Unkown file format!"));
         }
-  
+
         InputStream casIn = casFile.getContents();
 
         org.apache.uima.caseditor.editor.ICasDocument doc;
@@ -377,29 +398,27 @@ public class DefaultCasDocumentProvider 
             // does not notice the error and can just
             // edit the file, tough saving it might fail
             // if the io error persists
-            
+
             CasEditorPlugin.log(e);
           }
         }
 
         elementErrorStatus.remove(element);
-        
+
         return doc;
-      }
-      else {
-        
+      } else {
+
         String message = null;
-        
+
         if (typeSystemFile != null) {
-          message = "Cannot find type system!\nPlease place a valid type system in this path:\n" +
-                  typeSystemFile.getFullPath().toString();
-        }
-        else
+          message = "Cannot find type system!\nPlease place a valid type system in this path:\n"
+                  + typeSystemFile.getFullPath().toString();
+        } else
           message = "Type system is not set, please choose a type system to open the CAS.";
-        
+
         IStatus status = new Status(IStatus.ERROR, "org.apache.uima.dev",
-        		CasDocumentProvider.TYPE_SYSTEM_NOT_AVAILABLE_STATUS_CODE, message, null);
-        
+                CasDocumentProvider.TYPE_SYSTEM_NOT_AVAILABLE_STATUS_CODE, message, null);
+
         elementErrorStatus.put(element, status);
       }
     }
@@ -417,12 +436,12 @@ public class DefaultCasDocumentProvider 
       IFile file = fileInput.getFile();
 
       if (document instanceof DocumentUimaImpl) {
-        
+
         DocumentUimaImpl documentImpl = (DocumentUimaImpl) document;
-        
-        ByteArrayOutputStream outStream = new ByteArrayOutputStream(40000); 
+
+        ByteArrayOutputStream outStream = new ByteArrayOutputStream(40000);
         documentImpl.serialize(outStream);
-        
+
         InputStream stream = new ByteArrayInputStream(outStream.toByteArray());
 
         file.setContents(stream, true, false, null);
@@ -438,73 +457,70 @@ public class DefaultCasDocumentProvider 
       FileEditorInput editorInput = (FileEditorInput) element;
       return documentToTypeSystemMap.get(editorInput.getFile().getFullPath().toPortableString());
     }
-    
+
     return null;
   }
-  
+
   @Override
   public void saveTypeSystemPreferenceStore(Object element) {
     String prefereceFileId = getPreferenceFileForTypeSystem(getTypesystemId(element));
-    
+
     PreferenceStore preferences = typeSystemPreferences.get(prefereceFileId);
-    
-    // serialize ... 
-    IFile preferenceFile = ResourcesPlugin.getWorkspace().getRoot().getFile(
-            Path.fromPortableString(prefereceFileId));
-    
+
+    // serialize ...
+    IFile preferenceFile = ResourcesPlugin.getWorkspace().getRoot()
+            .getFile(Path.fromPortableString(prefereceFileId));
+
     ByteArrayOutputStream preferenceBytes = new ByteArrayOutputStream();
-    
+
     try {
       preferences.save(preferenceBytes, "");
     } catch (IOException e) {
       // will not fail, writing to memory
       CasEditorPlugin.log(e);
     }
-    
+
     try {
       if (preferenceFile.exists()) {
-        preferenceFile.setContents(new ByteArrayInputStream(preferenceBytes.toByteArray()),
-                true, false, null);
+        preferenceFile.setContents(new ByteArrayInputStream(preferenceBytes.toByteArray()), true,
+                false, null);
+      } else {
+        preferenceFile.create(new ByteArrayInputStream(preferenceBytes.toByteArray()), true, null);
       }
-      else {
-        preferenceFile.create(new ByteArrayInputStream(preferenceBytes.toByteArray()),
-                true, null);
-      }
-    }
-    catch (CoreException e) {
+    } catch (CoreException e) {
       // might fail if writing is not possible
       // for some reason
       CasEditorPlugin.log(e);
     }
   }
-  
+
   @Override
   public IPreferenceStore getTypeSystemPreferenceStore(Object element) {
     String tsId = getTypesystemId(element);
-    
+
     return typeSystemPreferences.get(getPreferenceFileForTypeSystem(tsId));
   }
-  
+
   @Override
   public IPreferenceStore getSessionPreferenceStore(Object element) {
     return sessionPreferenceStores.get(getTypesystemId(element));
   }
-  
+
   void setTypeSystem(String document, String typeSystem) {
     documentToTypeSystemMap.put(document, typeSystem);
   }
-  
+
   @Override
-  public Composite createTypeSystemSelectorForm(final ICasEditor editor,
-          Composite parent, IStatus status) {
-    
+  public Composite createTypeSystemSelectorForm(final ICasEditor editor, Composite parent,
+          IStatus status) {
+
     // Note:
     // If the editor is not active and the user clicks on the button
     // the editor gets activated and an exception is logged
     // on the second click the button is selected
     // How to fix the exception ?!
     // Only tested on OS X Snow Leopard
-    
+
     Composite provideTypeSystemForm = new Composite(parent, SWT.NONE);
     provideTypeSystemForm.setLayout(new GridLayout(1, false));
     Label infoLabel = new Label(provideTypeSystemForm, SWT.NONE);
@@ -513,18 +529,18 @@ public class DefaultCasDocumentProvider 
     retryButton.setText("Choose Type System ...");
     retryButton.addSelectionListener(new SelectionListener() {
       public void widgetSelected(SelectionEvent e) {
-        
+
         // Open a dialog to let the user choose a type system
-        IResource resource = WorkspaceResourceDialog.getWorkspaceResourceElement(Display.getCurrent().getActiveShell(),
-                ResourcesPlugin.getWorkspace().getRoot(),
+        IResource resource = WorkspaceResourceDialog.getWorkspaceResourceElement(Display
+                .getCurrent().getActiveShell(), ResourcesPlugin.getWorkspace().getRoot(),
                 "Select a Type System", "Please select a Type System:");
-        
+
         if (resource != null) {
-          
+
           FileEditorInput editorInput = (FileEditorInput) editor.getEditorInput();
-          setTypeSystem(editorInput.getFile().getFullPath().toPortableString(),
-                  resource.getFullPath().toString());
-          
+          setTypeSystem(editorInput.getFile().getFullPath().toPortableString(), resource
+                  .getFullPath().toString());
+
           // Now set the input again to open the editor with the
           // specified type system
           editor.reopenEditorWithNewTypeSystem();
@@ -535,34 +551,34 @@ public class DefaultCasDocumentProvider 
         throw new IllegalStateException("Never be called!");
       }
     });
-    
+
     return provideTypeSystemForm;
   }
-  
+
   @Override
-	protected ElementInfo createElementInfo(Object element) {
-    
+  protected ElementInfo createElementInfo(Object element) {
+
     FileElementInfo info = new FileElementInfo(super.createElementInfo(element));
 
     // Register listener to listens for deletion events,
     // if the file opened in this editor is deleted, the editor should be closed!
-    
+
     info.deleteListener = new DeleteElementListener((FileEditorInput) element);
     ResourcesPlugin.getWorkspace().addResourceChangeListener(info.deleteListener,
             IResourceChangeEvent.POST_CHANGE);
 
     return info;
-	}
-  
+  }
+
   @Override
-	protected void disposeElementInfo(Object element, ElementInfo info) {
-	  
+  protected void disposeElementInfo(Object element, ElementInfo info) {
+
     FileElementInfo fileInfo = (FileElementInfo) info;
     ResourcesPlugin.getWorkspace().removeResourceChangeListener(fileInfo.deleteListener);
-	  
-		super.disposeElementInfo(element, info);
-	}
-  
+
+    super.disposeElementInfo(element, info);
+  }
+
   private void handleElementDeleted(Object element) {
     fireElementDeleted(element);
   }

Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/plugin.xml
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/plugin.xml?rev=1186126&r1=1186125&r2=1186126&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/plugin.xml (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/plugin.xml Wed Oct 19 11:53:58 2011
@@ -22,6 +22,7 @@
 
 <plugin>
    <extension-point id="org.apache.uima.caseditor.editor" name="DocumentProvider" schema="schema/org.apache.uima.caseditor.editor.exsd"/>
+   <extension-point id="org.apache.uima.caseditor.searchstrategy" name="Type System Search Strategy" schema="schema/org.apache.uima.caseditor.searchstrategy.exsd"/>
 
 	<extension point="org.eclipse.ui.editors">
 		<editor icon="icons/svgicons/document.png"

Added: uima/uimaj/trunk/uimaj-ep-cas-editor/schema/org.apache.uima.caseditor.searchstrategy.exsd
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/schema/org.apache.uima.caseditor.searchstrategy.exsd?rev=1186126&view=auto
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/schema/org.apache.uima.caseditor.searchstrategy.exsd (added)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/schema/org.apache.uima.caseditor.searchstrategy.exsd Wed Oct 19 11:53:58 2011
@@ -0,0 +1,114 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.apache.uima.caseditor.editor" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appinfo>
+         <meta.schema plugin="org.apache.uima.caseditor.editor" id="org.apache.uima.caseditor.searchstrategy." name="Type System Search Strategy"/>
+      </appinfo>
+      <documentation>
+         
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appinfo>
+            <meta.element />
+         </appinfo>
+      </annotation>
+      <complexType>
+         <sequence>
+            <element ref="searchStrategy" minOccurs="1" maxOccurs="unbounded"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute translatable="true"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="searchStrategy">
+      <complexType>
+         <attribute name="class" type="string" use="required">
+            <annotation>
+               <documentation>
+                  the qualified name of the document provider class
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="java" basedOn=":org.apache.uima.caseditor.searchStrategy.ICasEditorSearchStrategy"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string" use="required">
+            <annotation>
+               <documentation>
+                  the unique id of this provider
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="description" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="priority" type="string" use="default" value="100">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+
+
+
+
+   <annotation>
+      <appinfo>
+         <meta.section type="copyright"/>
+      </appinfo>
+      <documentation>
+         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
+&quot;License&quot;); 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
+&quot;AS IS&quot; 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.
+      </documentation>
+   </annotation>
+
+</schema>

Added: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/searchStrategy/ITypeSystemSearchStrategy.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/searchStrategy/ITypeSystemSearchStrategy.java?rev=1186126&view=auto
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/searchStrategy/ITypeSystemSearchStrategy.java (added)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/searchStrategy/ITypeSystemSearchStrategy.java Wed Oct 19 11:53:58 2011
@@ -0,0 +1,9 @@
+package org.apache.uima.caseditor.editor.searchStrategy;
+
+import org.eclipse.core.resources.IFile;
+
+public interface ITypeSystemSearchStrategy {
+
+  IFile findTypeSystem(IFile casFile);
+
+}

Added: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/searchStrategy/TypeSystemSearchStrategyFactory.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/searchStrategy/TypeSystemSearchStrategyFactory.java?rev=1186126&view=auto
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/searchStrategy/TypeSystemSearchStrategyFactory.java (added)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/searchStrategy/TypeSystemSearchStrategyFactory.java Wed Oct 19 11:53:58 2011
@@ -0,0 +1,63 @@
+package org.apache.uima.caseditor.editor.searchStrategy;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.uima.caseditor.CasEditorPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+
+public class TypeSystemSearchStrategyFactory {
+
+  private static final String SEARCH_STRATEGY_EXTENSION = "org.apache.uima.caseditor.searchstrategy";
+
+  private static TypeSystemSearchStrategyFactory instance;
+
+  private Map<Integer, ITypeSystemSearchStrategy> searchStrategies = new TreeMap<Integer, ITypeSystemSearchStrategy>();
+
+  private TypeSystemSearchStrategyFactory() {
+
+    IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(
+            SEARCH_STRATEGY_EXTENSION);
+
+    for (IConfigurationElement element : config) {
+
+      if ("searchStrategy".equals(element.getName())) {
+
+        // extract id element
+        String id = element.getAttribute("id");
+        String priority = element.getAttribute("priority");
+        String description = element.getAttribute("description");
+
+        Object searchStrategyObject;
+        try {
+          searchStrategyObject = element.createExecutableExtension("class");
+        } catch (CoreException e) {
+          CasEditorPlugin.log("Failed to load search strategy with id: " + id, e);
+          searchStrategyObject = null;
+        }
+
+        if (searchStrategyObject instanceof ITypeSystemSearchStrategy) {
+          searchStrategies.put(Integer.parseInt(priority),
+                  (ITypeSystemSearchStrategy) searchStrategyObject);
+        }
+      }
+    }
+
+  }
+
+  public static TypeSystemSearchStrategyFactory instance() {
+
+    if (instance == null) {
+      instance = new TypeSystemSearchStrategyFactory();
+    }
+
+    return instance;
+  }
+
+  public Map<Integer, ITypeSystemSearchStrategy> getSearchStrategies() {
+    return searchStrategies;
+  }
+
+}