Revision: 20006
http://sourceforge.net/p/gate/code/20006
Author: markagreenwood
Date: 2017-01-27 14:18:12 +0000 (Fri, 27 Jan 2017)
Log Message:
-----------
all the plugin loading now passes around a Plugin instance rather than two URLs
so that we can access any of the plugin info at any point
Modified Paths:
--------------
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/CreoleRegisterImpl.java
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/CreoleXmlHandler.java
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/Parameter.java
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
Modified:
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/CreoleRegisterImpl.java
===================================================================
---
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/CreoleRegisterImpl.java
2017-01-27 14:17:24 UTC (rev 20005)
+++
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/CreoleRegisterImpl.java
2017-01-27 14:18:12 UTC (rev 20006)
@@ -277,7 +277,7 @@
// directory defines
annotationHandler.createResourceElementsForDirInfo(jdomDoc);
- processFullCreoleXmlTree(directoryUrl, creoleFileUrl, jdomDoc,
+ processFullCreoleXmlTree(plugin, jdomDoc,
annotationHandler);
} catch(IOException e) {
throw (new GateException(e));
@@ -288,7 +288,7 @@
} // parseDirectory
- private void processFullCreoleXmlTree(URL directoryUrl, URL creoleFileUrl,
+ private void processFullCreoleXmlTree(Plugin plugin,
Document jdomDoc, CreoleAnnotationHandler annotationHandler)
throws GateException, IOException, JDOMException {
// now we can process any annotations on the new classes
@@ -303,13 +303,12 @@
// finally, parse the augmented definition with the normal parser
DefaultHandler handler =
- new CreoleXmlHandler(this, directoryUrl, creoleFileUrl);
+ new CreoleXmlHandler(this, plugin);
SAXOutputter outputter =
new SAXOutputter(handler, handler, handler, handler);
outputter.output(jdomDoc);
if(DEBUG) {
- Out.prln("done parsing "
- + ((directoryUrl == null) ? "null" : directoryUrl.toString()));
+ Out.prln("done parsing " + plugin);
}
}
Modified:
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/CreoleXmlHandler.java
===================================================================
---
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/CreoleXmlHandler.java
2017-01-27 14:17:24 UTC (rev 20005)
+++
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/CreoleXmlHandler.java
2017-01-27 14:18:12 UTC (rev 20006)
@@ -90,14 +90,11 @@
/** Debug flag */
private static final boolean DEBUG = false;
-
- /** The source URL of the directory file being parsed. */
- private URL sourceUrl;
/**
- * The URL to the creole.xml file being parsed.
+ * The plugin currently being loaded
*/
- private URL creoleFileUrl;
+ private Plugin plugin;
/** This object indicates what to do when the parser encounts an error*/
private SimpleErrorHandler _seh = new SimpleErrorHandler();
@@ -120,12 +117,12 @@
private boolean readCharacterStatus = false;
/** Construction */
- public CreoleXmlHandler(CreoleRegister register, URL directoryUrl,
- URL creoleFileUrl) {
+ public CreoleXmlHandler(CreoleRegister register, Plugin plugin) {
this.register = register;
- this.sourceUrl = directoryUrl;
- this.creoleFileUrl = creoleFileUrl;
- currentParam = new Parameter(this.creoleFileUrl);
+ this.plugin = plugin;
+ //this.sourceUrl = directoryUrl;
+ //this.creoleFileUrl = creoleFileUrl;
+ currentParam = new Parameter(plugin);
} // construction
/** The register object that we add ResourceData objects to during parsing.
@@ -315,7 +312,15 @@
);
//set the URL to the creole.xml file on the resource data object
- resourceData.setXmlFileUrl(creoleFileUrl);
+ //TODO should this be a URI instead of the URL?
+ try {
+ resourceData.setXmlFileUrl(new URL(plugin.getBaseURL(), "creole.xml"));
+ }
+ catch (MalformedURLException e) {
+ throw new GateSaxException(
+ "Couldn't load autoloading resource: " +
+ resourceData.getName() + "; problem was: " + e,e);
+ }
// add the new resource data object to the creole register
register.put(resourceData.getClassName(), resourceData);
// if the resource is auto-loading, try and load it
@@ -441,8 +446,8 @@
}
// add jar file URL if there is one
- if(sourceUrl != null) {
- String sourceUrlName = sourceUrl.toExternalForm();
+ //if(sourceUrl != null) {
+ String sourceUrlName = plugin.getBaseURL().toExternalForm();
String separator = "/";
if(sourceUrlName.endsWith(separator))
@@ -460,7 +465,7 @@
} catch(MalformedURLException e) {
throw new GateSaxException("bad URL " + jarFileUrl + e);
}// End try
- }// End if
+ //}// End if
// End JAR processing
//////////////////////////////////////////////////////////////////
} else if(elementName.toUpperCase().equals("CLASS")) {
@@ -516,7 +521,7 @@
paramList.add(currentParam);
if(DEBUG)
Out.prln("added param: " + currentParam);
- currentParam = new Parameter(creoleFileUrl);
+ currentParam = new Parameter(plugin);
// End PARAMETER processing
//////////////////////////////////////////////////////////////////
} else if(elementName.toUpperCase().equals("AUTOLOAD")) {
Modified:
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/Parameter.java
===================================================================
--- gate/branches/sawdust2/gate-core/src/main/java/gate/creole/Parameter.java
2017-01-27 14:17:24 UTC (rev 20005)
+++ gate/branches/sawdust2/gate-core/src/main/java/gate/creole/Parameter.java
2017-01-27 14:18:12 UTC (rev 20006)
@@ -53,8 +53,12 @@
* this parameter belongs to. This will be used a context when deriving
* default values for the parameters of type URL.
*/
- public Parameter(URL baseUrl){
+ /*public Parameter(URL baseUrl){
this.baseURL = baseUrl;
+ }*/
+
+ public Parameter(Plugin plugin) {
+ this.plugin = plugin;
}
/** The type name of the parameter */
@@ -285,7 +289,7 @@
else if(typeName.equals("java.net.URL"))
try{
if(stringValue != null && !stringValue.equals("")) {
- value = new URL(baseURL, stringValue);
+ value = new URL(plugin.getBaseURL(), stringValue);
}
}catch(MalformedURLException mue){
//value = null;
@@ -392,7 +396,10 @@
* belongs to. It is used for deriving default values for parameters of type
* {@link URL}.
*/
- protected URL baseURL;
+ //protected URL baseURL;
+
+ protected Plugin plugin;
+
/** Set runtime status of this parameter */
public void setRuntime(boolean runtime) { this.runtime = runtime; }
Modified:
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
===================================================================
---
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
2017-01-27 14:17:24 UTC (rev 20005)
+++
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
2017-01-27 14:18:12 UTC (rev 20006)
@@ -38,13 +38,12 @@
public ResourceReference(Plugin plugin, String path)
throws URISyntaxException {
- if (plugin != null) {
+ if(plugin != null) {
uri = plugin.getBaseURI().resolve(path);
- }
- else {
+ } else {
uri = new URI(path);
}
-
+
if(!uri.isAbsolute())
throw new URISyntaxException(path,
"Context is null and path is not absolute");
@@ -52,26 +51,32 @@
public ResourceReference(URL context, String path)
throws URISyntaxException, MalformedURLException {
-
+
+ // not sure if we need this constructor as we could just assume people can
+ // do the right thing before calling the constructor
+
uri = new URI(path);
-
+
if(context != null && !uri.isAbsolute()) {
uri = (new URL(context, path)).toURI();
}
-
+
if(!uri.isAbsolute())
throw new URISyntaxException(path,
"Context is null and path is not absolute");
}
- public ResourceReference(URI context, String path) throws URISyntaxException
{
- if (context != null) {
+ public ResourceReference(URI context, String path) throws URISyntaxException
{
+
+ // not sure if we need this constructor as we could just assume people can
+ // do the right thing before calling the constructor
+
+ if(context != null) {
uri = context.resolve(path);
- }
- else {
+ } else {
uri = new URI(path);
}
-
+
if(!uri.isAbsolute())
throw new URISyntaxException(path,
"Context is null and path is not absolute");
@@ -79,13 +84,12 @@
public ResourceReference(ResourceReference context, String path)
throws IOException, URISyntaxException {
- if (context != null) {
+ if(context != null) {
uri = context.uri.resolve(path);
- }
- else {
+ } else {
uri = new URI(path);
}
-
+
if(!uri.isAbsolute())
throw new URISyntaxException(path,
"Context is null and path is not absolute");
@@ -128,6 +132,7 @@
return uri;
}
+ @Override
public String toString() {
return uri.toString();
}
Modified:
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
===================================================================
---
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
2017-01-27 14:17:24 UTC (rev 20005)
+++
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
2017-01-27 14:18:12 UTC (rev 20006)
@@ -20,7 +20,6 @@
private Plugin creolePlugin;
-
@Override
public void setUp() throws Exception {
// Initialise the GATE library and creole register
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs