Revision: 19192
          http://sourceforge.net/p/gate/code/19192
Author:   markagreenwood
Date:     2016-04-04 07:26:28 +0000 (Mon, 04 Apr 2016)
Log Message:
-----------
registerComponent now uses the new method as well

Modified Paths:
--------------
    gate/branches/sawdust2/src/main/gate/CreoleRegister.java
    gate/branches/sawdust2/src/main/gate/Plugin.java
    gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java

Modified: gate/branches/sawdust2/src/main/gate/CreoleRegister.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/CreoleRegister.java    2016-04-04 
01:22:39 UTC (rev 19191)
+++ gate/branches/sawdust2/src/main/gate/CreoleRegister.java    2016-04-04 
07:26:28 UTC (rev 19192)
@@ -87,6 +87,7 @@
    *
    * @param clazz Class object for class with CreoleResource annotations.
    */
+  @Deprecated
   public void registerComponent(Class<? extends Resource> clazz) throws 
GateException;
 
   /** Register a single CREOLE directory. The <CODE>creole.xml</CODE>

Modified: gate/branches/sawdust2/src/main/gate/Plugin.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/Plugin.java    2016-04-04 01:22:39 UTC 
(rev 19191)
+++ gate/branches/sawdust2/src/main/gate/Plugin.java    2016-04-04 07:26:28 UTC 
(rev 19192)
@@ -13,6 +13,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -511,6 +512,36 @@
     }
   }
   
+  public static class Component extends Plugin {
+
+    private Class<? extends Resource> resourceClass;
+    
+    public Component(Class<? extends Resource> resourceClass) throws 
MalformedURLException {
+      this.resourceClass = resourceClass;
+      baseURL = new 
URL(resourceClass.getResource("/gate/creole/CreoleRegisterImpl.class"), ".");
+    }
+    
+    @Override
+    public Document getCreoleXML() throws Exception, JDOMException {
+      Document doc = new Document();
+      Element element;
+      doc.addContent(element = new Element("CREOLE-DIRECTORY"));
+      element.addContent(element = new Element("CREOLE"));
+      element.addContent(element = new Element("RESOURCE"));
+      Element classElement  = new Element("CLASS");
+      classElement.setText(resourceClass.getName());
+      element.addContent(classElement);
+      
+      return doc;
+    }
+
+    @Override
+    public String getName() {
+      return resourceClass.getName();
+    }
+    
+  }
+  
   public static void main(String args[]) throws Exception {
     Gate.runInSandbox(true);
     Gate.init();

Modified: gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java 
2016-04-04 01:22:39 UTC (rev 19191)
+++ gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java 
2016-04-04 07:26:28 UTC (rev 19192)
@@ -38,6 +38,7 @@
 import gate.util.Out;
 
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.AbstractList;
 import java.util.ArrayList;
@@ -198,28 +199,12 @@
 
   @Override
   public void registerComponent(Class<? extends Resource> resourceClass) 
throws GateException {
-    //TODO put this back
-    /*URL creoleFileUrl = 
resourceClass.getResource("/gate/creole/CreoleRegisterImpl.class");
-    Gate.addKnownPlugin(creoleFileUrl);
-    Document doc = new Document();
-    Element element;
-    doc.addContent(element = new Element("CREOLE-DIRECTORY"));
-    element.addContent(element = new Element("CREOLE"));
-    element.addContent(element = new Element("RESOURCE"));
-    Element classElement  = new Element("CLASS");
-    classElement.setText(resourceClass.getName());
-    element.addContent(classElement);
-    CreoleAnnotationHandler annotationHandler = new 
CreoleAnnotationHandler(creoleFileUrl);
-    annotationHandler.processCreoleResourceAnnotations(element, resourceClass);
     try {
-      processFullCreoleXmlTree(new URL(creoleFileUrl, "."), creoleFileUrl, 
doc, annotationHandler);
+      registerPlugin(new Plugin.Component(resourceClass));
     }
-    catch(IOException e) {
-      throw new GateException(e);
+    catch (MalformedURLException mue) {
+      throw new GateException("Unable to register component",mue);
     }
-    catch(JDOMException e) {
-      throw new GateException(e);
-    }*/
   }
 
   /**
@@ -472,49 +457,15 @@
    */
   @Override
   public void removeDirectory(URL directory) {
-    int prCount = 0;
     
-    //TODO make this work again, would it be easier to store plugins in a map 
from name to plugin to get easier access?
-    /*
-    if(directories.remove(directory)) {
-      DirectoryInfo dInfo = Gate.getDirectoryInfo(directory);
-      if(dInfo != null) {
-        
-        for(ResourceInfo rInfo : dInfo.getResourceInfoList()) {
-          ResourceData rData = get(rInfo.getResourceClassName());          
-          if (rData != null && rData.getReferenceCount() == 1) {
-            // we only need to remove resources if we are actually going to
-            // remove the plugin
-            try {
-              List<Resource> loaded =
-                  getAllInstances(rInfo.getResourceClassName(),true);
-              prCount += loaded.size();
-              for(Resource r : loaded) {
-                //System.out.println(r);
-                Factory.deleteResource(r);  
-              }
-            } catch(GateException e) {
-              // not much we can do here other than dump the exception
-              e.printStackTrace();
-            }
-          }
-          
-          remove(rInfo.getResourceClassName());
-        }
+    if (directory == null) return;
+    
+    for (Plugin plugin : plugins) {
+      if (directory.equals(plugin.getBaseURL())) {
+        unregisterPlugin(plugin);
+        break;
       }
-      try {
-        Gate.getClassLoader().forgetClassLoader(new 
URL(directory,"creole.xml").toExternalForm(), dInfo);
-      }
-      catch (Exception e) {
-        e.printStackTrace();
-      }
-
-      log.info("CREOLE plugin unloaded: " + directory);
-      if (prCount > 0)
-        log.warn(prCount+" resources were deleted as they relied on the " + 
dInfo.getName() +" plugin");
-      
-      firePluginUnloaded(directory);
-    }*/
+    }
   }
 
   /**

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


------------------------------------------------------------------------------
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to