diff --git a/distro/LICENSE b/distro/LICENSE index 7bca8c8..630ba97 100644 --- a/distro/LICENSE +++ b/distro/LICENSE @@ -1,2 +1,6 @@ -${gcube.license} +gCube System - License +------------------------------------------------------------ +The gCube/gCore software is licensed as Free Open Source software conveying to the EUPL (http://ec.europa.eu/idabc/eupl). +The software and documentation is provided by its authors/distributors "as is" and no expressed or +implied warranty is given for its use, quality or fitness for a particular case. diff --git a/distro/README b/distro/README index 0c1ed6c..65ef90f 100644 Binary files a/distro/README and b/distro/README differ diff --git a/pom.xml b/pom.xml index ef11732..4e85b5e 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ org.gcube.resources common-gcore-resources - 1.3.1-SNAPSHOT + 1.3.2-SNAPSHOT scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId} @@ -19,7 +19,7 @@ distro - + junit diff --git a/src/main/java/org/gcube/common/resources/gcore/GenericResource.java b/src/main/java/org/gcube/common/resources/gcore/GenericResource.java index a56fe0f..e475a34 100644 --- a/src/main/java/org/gcube/common/resources/gcore/GenericResource.java +++ b/src/main/java/org/gcube/common/resources/gcore/GenericResource.java @@ -20,6 +20,11 @@ public class GenericResource extends Resource { this.type(Type.GENERIC); } + public GenericResource(String id) { + this(); + this.setId(id); + } + @XmlElementRef private Profile profile; diff --git a/src/main/java/org/gcube/common/resources/gcore/Resource.java b/src/main/java/org/gcube/common/resources/gcore/Resource.java index 8f0e807..22feafc 100644 --- a/src/main/java/org/gcube/common/resources/gcore/Resource.java +++ b/src/main/java/org/gcube/common/resources/gcore/Resource.java @@ -96,7 +96,7 @@ public abstract class Resource { return id; } - void setId(String id){ + public void setId(String id){ this.id=id; } diff --git a/src/main/java/org/gcube/common/resources/gcore/Resources.java b/src/main/java/org/gcube/common/resources/gcore/Resources.java index c5dc13b..b00cc67 100644 --- a/src/main/java/org/gcube/common/resources/gcore/Resources.java +++ b/src/main/java/org/gcube/common/resources/gcore/Resources.java @@ -41,10 +41,10 @@ public class Resources { //cached schemas private static Map,Schema> schemas = new HashMap, Schema>(); - + private static Map, JAXBContext> contexts = new HashMap, JAXBContext>(); - - + + static { schemaFactory.setResourceResolver(new SchemaResolver()); @@ -92,22 +92,23 @@ public class Resources { public static void validate(Resource resource) throws IllegalArgumentException, Exception { Schema schema = schema(resource.getClass()); - + ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(marshal(resource,out).toByteArray()); - + schema.newValidator().validate(new StreamSource(in)); + } - + //helper private static synchronized Schema schema(Class resourceClass) throws Exception { String schemaResource = schemaResources.get(resourceClass); - + if (schemaResource==null) throw new IllegalArgumentException("no known schema for:\n "+resourceClass); - + Schema schema = schemas.get(resourceClass); if (schema==null) { InputStream stream = Resources.class.getClassLoader().getResourceAsStream(schemaResource); @@ -123,22 +124,22 @@ public class Resources { * @param stream the stream in input */ public static T marshal(Object resource,T stream) { - + marshal(resource, new StreamResult(stream)); return stream; } - + /** * Write the serialisation of a given resource to a given character stream. * @param resource the resource * @param stream the stream in input */ public static T marshal(Object resource,T stream) { - + marshal(resource,new StreamResult(stream)); return stream; } - + /** * Write the serialisation of a given resource to a {@link Result}. * @param resource the resource @@ -146,16 +147,16 @@ public class Resources { * @return the result in input */ public static T marshal(Object resource,T result) { - + if (resource instanceof Resource) ((Resource) resource).lock.lock(); try { JAXBContext context = context(resource.getClass()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - + m.marshal(resource,result); - + return result; } catch(Exception e) { @@ -164,7 +165,7 @@ public class Resources { if (resource instanceof Resource) ((Resource) resource).lock.unlock(); } - + } /** @@ -195,7 +196,7 @@ public class Resources { public static T unmarshal(Class resourceClass, InputStream stream) { return unmarshal(resourceClass,new StreamSource(stream)); } - + /** * Creates a resource of given class from its serialisation in a given {@link Source}. * @param resourceClass the class of the resource @@ -212,16 +213,16 @@ public class Resources { throw new RuntimeException("deserialisation error",e); } } - + //helper private static synchronized JAXBContext context(Class resourceClass) throws Exception { - + JAXBContext ctx = contexts.get(resourceClass); if (ctx==null) { ctx = JAXBContext.newInstance(resourceClass); contexts.put(resourceClass,ctx); } return ctx; - + } } diff --git a/src/test/java/org/gcube/common/resources/gcore/GCoreEndpointTest.java b/src/test/java/org/gcube/common/resources/gcore/GCoreEndpointTest.java index b0576c2..26ff3fd 100644 --- a/src/test/java/org/gcube/common/resources/gcore/GCoreEndpointTest.java +++ b/src/test/java/org/gcube/common/resources/gcore/GCoreEndpointTest.java @@ -54,6 +54,8 @@ public class GCoreEndpointTest { endpoint.profile().newDeploymentData().activationTime(Calendar.getInstance()); endpoint.profile().endpoints().add().nameAndAddress("name",URI.create("http://acme.org")); + + return endpoint; }