From 973b95aa9965db087627474af969606893d31467 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Mon, 3 Oct 2016 09:25:29 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/common/common-gcore-resources/1.3@132321 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/LICENSE | 6 ++- distro/README | Bin 1692 -> 1094 bytes pom.xml | 4 +- .../resources/gcore/GenericResource.java | 5 +++ .../common/resources/gcore/Resource.java | 2 +- .../common/resources/gcore/Resources.java | 41 +++++++++--------- .../resources/gcore/GCoreEndpointTest.java | 2 + 7 files changed, 36 insertions(+), 24 deletions(-) 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 0c1ed6c61b4a131bbe3ef7ed8131f27938e1ad2e..65ef90f3e4f8a67d48bf35defb422dc3136eb2e1 100644 GIT binary patch literal 1094 zcmaJ>O;g)25WVYH>@XalgB75i(#Z)(oQ`MGz{CkXE3%wyktL5Lle!H5y(>F>gnr}{ z?Y@0adU>10M!|a2tQ6#}52}I$4j+xE)Dy7euOG%18}zWX?jAP6!%8UwwQvE2)-Cv^ zuB{8IfK>~D*h{Om-J)4T+BjP)L1<@xC>i_^#@RIcn$8w*G`anpoS&Y4OtO5DoFAXS z_){)X8L49LBFScx`Bg+*Bxn4bM+AF;Bw6+j_2mVH--JW+mL*@zm!rjUp60}NcGjs0 zQ$V`BcH$T6n_8J`v^&NTT_>W_Wzx5gIb&B%*jVSEEn@5gOvH+2a;%g!2uEc+a^D{> zOJTWnYr6F0>IQ7tIkTLdKo*2nvK#~o*wi)dUSz~me{(Mv)}%CS}Xtn literal 1692 zcmbtUO>Y`85Jjrg1HWPvaY&-Dy+=KS@F5`)TCp@eR6Q8)>@teirv3;;i2vT%_0mF{ zRE1jd!DG+(y_q*NUm_I!us}#R&SME(=xntpao6siyxP$2Y%_Gy(#n(3J2q6NLh=X6 zZx?%W9&|>!h;JX!I(9tw@8{^ggUil#5lCeN;c<7xAU-M-4#6RUXUaJ#go2vs z%w?R;$6Y2At1vKYt&GUHc1)mTKIcj(HNi>*X)*-XfOr<9#DcZL1WQOCr?*UmS7+;F znFOmU+1`^Dme7F|8n~0P1`dm>cB=#zdu)vhM;>F4eFHSc*Z^bgxVq{;C>%y$C^D4D zS+7!Z%*g1j;#x$#?*V?MC%SDI#;#qnWoC@uz561vlAEIl#K~ESA~p~#(c;&tywDyT z{dQR6e;g%$#5k(K>4<|v`!e9yIA-|FqhR&A8$(RPYQ=p5=MlUQ1q(}O;F>TNzXf#u zr+h3{(OEq8B-&SooC`d=tdLJUEx{Y3jtf;km^b%POcRo*xl4=lkj|?y=uGa{!q)Ae z>UfNdM>c1u(zQohI@p*1rQk_P%&UQYIASN`{&1QOUl^`QtM#VUYQ5+EmUpve!`|Rw F_yeFO?#loG 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; }