Revision: 20008 http://sourceforge.net/p/gate/code/20008 Author: markagreenwood Date: 2017-01-27 17:25:55 +0000 (Fri, 27 Jan 2017) Log Message: ----------- default param values now resolve correctly against the base URI of the plugin
Modified Paths: -------------- gate/branches/sawdust2/gate-core/src/main/java/gate/creole/Parameter.java gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java 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:21:39 UTC (rev 20007) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/creole/Parameter.java 2017-01-27 17:25:55 UTC (rev 20008) @@ -26,6 +26,7 @@ import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; +import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; @@ -259,6 +260,13 @@ } } } + else if (typeName.equals("gate.creole.ResourceReference")) { + try { + value = new ResourceReference(plugin, stringValue); + } catch(URISyntaxException e) { + throw new ParameterException("Malformed ResourceReference parameter value: "+stringValue,e); + } + } // java builtin types - for numeric types, we don't attempt to parse an // empty string value, but just leave value as null else if(typeName.startsWith("java.")) { @@ -286,7 +294,7 @@ value = Float.valueOf(stringValue); } } - else if(typeName.equals("java.net.URL")) + else if(typeName.equals("java.net.URL")) { try{ if(stringValue != null && !stringValue.equals("")) { value = new URL(plugin.getBaseURL(), stringValue); @@ -295,6 +303,7 @@ //value = null; throw new ParameterException("Malformed URL parameter value: "+stringValue,mue); } + } else{ //try to construct a new value from the string using a constructor // e.g. for URLs 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:21:39 UTC (rev 20007) +++ gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java 2017-01-27 17:25:55 UTC (rev 20008) @@ -9,17 +9,34 @@ import org.jdom.Element; import org.jdom.JDOMException; +import gate.Factory; import gate.Gate; import gate.Resource; import gate.corpora.TestDocument; import gate.creole.metadata.CreoleParameter; +import gate.creole.metadata.CreoleResource; import junit.framework.TestCase; -@SuppressWarnings({"serial","unused"}) +@SuppressWarnings("serial") public class TestResourceReference extends TestCase { private Plugin creolePlugin; + + @CreoleResource + public static class TestResource extends AbstractResource { + ResourceReference rr = null; + + public ResourceReference getParam() { + return rr; + } + + @CreoleParameter(defaultValue = "resources/file.txt") + public void setParam(ResourceReference rr) { + this.rr = rr; + } + } + @Override public void setUp() throws Exception { // Initialise the GATE library and creole register @@ -39,11 +56,18 @@ @Override public Document getCreoleXML() throws Exception, JDOMException { Document doc = new Document(); - doc.addContent(new Element("CREOLE-DIRECTORY")); + Element element = null; + 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(TestResource.class.getName()); + element.addContent(classElement); return doc; } }; - + Gate.getCreoleRegister().registerPlugin(creolePlugin); } @@ -76,19 +100,8 @@ } public void testCreateFromURL() throws Exception { - Resource resource = new AbstractResource() { - ResourceReference rr = null; + Resource resource = new TestResource(); - public ResourceReference getParam() { - return rr; - } - - @CreoleParameter - public void setParam(ResourceReference rr) { - this.rr = rr; - } - }; - URL url = new URL("http://gate.ac.uk"); resource.setParameterValue("param", url); @@ -149,8 +162,21 @@ rr = new ResourceReference(new URI("http://gate.ac.uk"), path); assertEquals("String representations don't match (7)", path, rr.toString()); - + rr = new ResourceReference(creolePlugin, path); assertEquals("String representations don't match (8)", path, rr.toString()); } -} + + public void testDefaultValue() throws Exception { + + Resource resource = Factory.createResource(TestResource.class.getName()); + + ResourceReference rr = (ResourceReference)resource.getParameterValue("param"); + + assertNotNull("ResourceReference param should not be null", rr); + + assertEquals("References do not match", new URI("creole://group;artifact;version/resources/file.txt"), + rr.toURI()); + + } +} \ No newline at end of file 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 GATE-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gate-cvs