Browse Source

Branched to release version 1.3

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/common/common-gcore-resources/1.3@114431 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Luca Frosini 7 years ago
commit
54d9fcf300
  1. 37
      .classpath
  2. 36
      .project
  3. 7
      .settings/org.eclipse.core.resources.prefs
  4. 12
      .settings/org.eclipse.jdt.core.prefs
  5. 5
      .settings/org.eclipse.m2e.core.prefs
  6. 6
      .settings/org.eclipse.wst.common.component
  7. 5
      .settings/org.eclipse.wst.common.project.facet.core.xml
  8. 2
      .settings/org.eclipse.wst.validation.prefs
  9. 1
      distro/INSTALL
  10. 6
      distro/LICENSE
  11. 4
      distro/MAINTAINERS
  12. 41
      distro/README
  13. 22
      distro/changelog.xml
  14. 38
      distro/descriptor.xml
  15. 26
      distro/profile.xml
  16. 1
      distro/svnpath.txt
  17. 84
      pom.xml
  18. 1288
      src/main/java/org/gcube/common/resources/gcore/GCoreEndpoint.java
  19. 166
      src/main/java/org/gcube/common/resources/gcore/GenericResource.java
  20. 2271
      src/main/java/org/gcube/common/resources/gcore/HostingNode.java
  21. 175
      src/main/java/org/gcube/common/resources/gcore/Resource.java
  22. 222
      src/main/java/org/gcube/common/resources/gcore/Resources.java
  23. 21
      src/main/java/org/gcube/common/resources/gcore/ScopeGroup.java
  24. 710
      src/main/java/org/gcube/common/resources/gcore/ServiceEndpoint.java
  25. 377
      src/main/java/org/gcube/common/resources/gcore/ServiceInstance.java
  26. 2383
      src/main/java/org/gcube/common/resources/gcore/Software.java
  27. 170
      src/main/java/org/gcube/common/resources/gcore/common/AnyMixedWrapper.java
  28. 89
      src/main/java/org/gcube/common/resources/gcore/common/AnyWrapper.java
  29. 39
      src/main/java/org/gcube/common/resources/gcore/common/BooleanWrapper.java
  30. 52
      src/main/java/org/gcube/common/resources/gcore/common/DateWrapper.java
  31. 47
      src/main/java/org/gcube/common/resources/gcore/common/FileList.java
  32. 41
      src/main/java/org/gcube/common/resources/gcore/common/GHNReference.java
  33. 68
      src/main/java/org/gcube/common/resources/gcore/common/Identity.java
  34. 139
      src/main/java/org/gcube/common/resources/gcore/common/Platform.java
  35. 41
      src/main/java/org/gcube/common/resources/gcore/common/ServiceReference.java
  36. 31
      src/main/java/org/gcube/common/resources/gcore/utils/DateFormatterAdapter.java
  37. 76
      src/main/java/org/gcube/common/resources/gcore/utils/Group.java
  38. 87
      src/main/java/org/gcube/common/resources/gcore/utils/ReadOnlyGroup.java
  39. 65
      src/main/java/org/gcube/common/resources/gcore/utils/Utils.java
  40. 128
      src/main/java/org/gcube/common/resources/gcore/utils/XPathHelper.java
  41. 79
      src/main/resources/schema/CommonTypeDefinitions.xsd
  42. 98
      src/main/resources/schema/endpoint.xsd
  43. 197
      src/main/resources/schema/gcoreendpoint.xsd
  44. 24
      src/main/resources/schema/generic.xsd
  45. 254
      src/main/resources/schema/node.xsd
  46. 391
      src/main/resources/schema/service.xsd
  47. 170
      src/test/java/org/gcube/common/resources/gcore/GCoreEndpointTest.java
  48. 138
      src/test/java/org/gcube/common/resources/gcore/GenericResourceTests.java
  49. 141
      src/test/java/org/gcube/common/resources/gcore/HostingNodeTest.java
  50. 105
      src/test/java/org/gcube/common/resources/gcore/ServiceEndpointTest.java
  51. 45
      src/test/java/org/gcube/common/resources/gcore/ServiceInstanceTest.java
  52. 178
      src/test/java/org/gcube/common/resources/gcore/SoftwareTest.java
  53. 12
      src/test/java/org/gcube/common/resources/gcore/TestUtils.java
  54. 42
      src/test/resources/endpoint.xml
  55. 104
      src/test/resources/gcoreendpoint.xml
  56. 21
      src/test/resources/generic.xml
  57. 57
      src/test/resources/instance.xml
  58. 160
      src/test/resources/node.xml
  59. 107
      src/test/resources/service.xml
  60. 15
      src/test/resources/textgeneric.xml

37
.classpath

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

36
.project

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>common-gcore-resources</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

7
.settings/org.eclipse.core.resources.prefs

@ -0,0 +1,7 @@
#Mon Dec 03 17:40:30 CET 2012
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

12
.settings/org.eclipse.jdt.core.prefs

@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7

5
.settings/org.eclipse.m2e.core.prefs

@ -0,0 +1,5 @@
#Mon Dec 03 17:40:29 CET 2012
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

6
.settings/org.eclipse.wst.common.component

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="common-gcore-resources">
<wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
</wb-module>
</project-modules>

5
.settings/org.eclipse.wst.common.project.facet.core.xml

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.7"/>
<installed facet="jst.utility" version="1.0"/>
</faceted-project>

2
.settings/org.eclipse.wst.validation.prefs

@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1

1
distro/INSTALL

@ -0,0 +1 @@

6
distro/LICENSE

@ -0,0 +1,6 @@
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.

4
distro/MAINTAINERS

@ -0,0 +1,4 @@
* Fabio Simeoni (fabio.simeoni@fao.org), FAO of the UN, Italy
* Roberto Cirillo (roberto.cirillo@isti.cnr.it), CNR, Italy
* Luigi Fortunati (luigi.fortunati@isti.cnr.it), CNR, Italy
* Luca Frosini (luca.frosini@isti.cnr.it), CNR, Italy

41
distro/README

@ -0,0 +1,41 @@
The gCube System - ${name}
----------------------
This work has been partially supported by the following European projects: DILIGENT (FP6-2003-IST-2), D4Science (FP7-INFRA-2007-1.2.2),
D4Science-II (FP7-INFRA-2008-1.2.2), iMarine (FP7-INFRASTRUCTURES-2011-2), and EUBrazilOpenBio (FP7-ICT-2011-EU-Brazil).
Authors
-------
* Fabio Simeoni (fabio.simeoni@fao.org), FAO of the UN, Italy
* Roberto Cirillo (roberto.cirillo@isti.cnr.it), CNR, Italy
* Luigi Fortunati (luigi.fortunati@isti.cnr.it), CNR, Italy
* Luca Frosini (luca.frosini@isti.cnr.it), CNR, Italy
Version and Release Date
------------------------
${version}
Description
-----------
${description}
Download information
--------------------
Source code is available from SVN:
${scm.url}
Binaries can be downloaded from:
Documentation
-------------
Documentation is available on-line from the Projects Documentation Wiki:
https://gcube.wiki.gcube-system.org/gcube/index.php/Common-gcore-resources
Licensing
---------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

22
distro/changelog.xml

@ -0,0 +1,22 @@
<ReleaseNotes>
<Changeset component="common-gcore-resources-1.0.0" date="2013-11-01">
<Change>First Release</Change>
</Changeset>
<Changeset component="common-gcore-resources-1.1.0" date="2013-13-09">
<Change>readonly groups are iterables and can be converted in collections</Change>
<Change>hosting node's load work with doubles instead of integers</Change>
<Change>resources with no scopes (e.g. just created) now pass validation</Change>
<Change>hosting node's load work with doubles instead of integers</Change>
<Change>more robust serialisation to contain a JAXB bug</Change>
<Change>date serialisation now retro-compatible with legacy processor</Change>
<Change>GenericResource now takes mixed content in its body. #newBody(String) and #bodyAsString() as helpers to work with plain string bodies</Change>
<Change>Software now takes mixed content in its body. #newSpecificData(String) and #specificDataAsString() as helpers to work with plain string data</Change>
</Changeset>
<Changeset component="common-gcore-resources-1.2.0" date="2013-02-10">
<Change>better string vs. DOM handling of Any content</Change>
<Change>Fixed visibility of Software inner class LevelWrapper to be public</Change>
</Changeset>
<Changeset component="common-gcore-resources-1.3.0" date="2015-04-27">
<Change>Deprecated localAvailableStorage() methods and added replacements localAvailableSpace()</Change>
</Changeset>
</ReleaseNotes>

38
distro/descriptor.xml

@ -0,0 +1,38 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>INSTALL</include>
<include>MAINTAINERS</include>
<include>changelog.xml</include>
<include>profile.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
<file>
<source>${distroDirectory}/svnpath.txt</source>
<outputDirectory>/${artifactId}</outputDirectory>
<filtered>true</filtered>
</file>
</files>
</assembly>

26
distro/profile.xml

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID />
<Type>Service</Type>
<Profile>
<Description>${description}</Description>
<Class>Common</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>${build.finalName}.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

1
distro/svnpath.txt

@ -0,0 +1 @@
${scm.url}

84
pom.xml

@ -0,0 +1,84 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.gcube.tools</groupId>
<artifactId>maven-parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>org.gcube.resources</groupId>
<artifactId>common-gcore-resources</artifactId>
<version>1.3.0-SNAPSHOT</version>
<scm>
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId}</connection>
<developerConnection>scm:svn:https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId}</developerConnection>
<url>http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId}</url>
</scm>
<properties>
<distroDirectory>distro</distroDirectory>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

1288
src/main/java/org/gcube/common/resources/gcore/GCoreEndpoint.java

File diff suppressed because it is too large Load Diff

166
src/main/java/org/gcube/common/resources/gcore/GenericResource.java

@ -0,0 +1,166 @@
package org.gcube.common.resources.gcore;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.gcube.common.resources.gcore.common.AnyMixedWrapper;
import org.w3c.dom.Element;
/**
* A resource with custom semantics.
*
*/
@XmlRootElement(name="Resource")
@XmlType(propOrder={"profile"})
public class GenericResource extends Resource {
public GenericResource() {
this.type(Type.GENERIC);
}
@XmlElementRef
private Profile profile;
public Profile profile() {
return profile;
};
public Profile newProfile() {
return profile = new Profile();
}
@XmlRootElement(name="Profile")
@XmlType(propOrder={"secondaryType","name","description","body"})
public static class Profile {
@XmlElement(name="SecondaryType")
private String secondaryType;
@XmlElement(name="Name")
private String name;
@XmlElement(name="Description")
private String description;
@XmlElementRef
private Body body;
public String type() {
return secondaryType;
}
public Profile type(String secondaryType) {
this.secondaryType = secondaryType;
return this;
}
public String name() {
return name;
}
public Profile name(String name) {
this.name = name;
return this;
}
public String description() {
return description;
}
public Profile description(String description) {
this.description = description;
return this;
}
/**
* Returns the body as a DOM document.
* @return the body
*/
public Element body() {
return body==null?null:body.root();
}
/**
* Returns the body as a string.
* @return the body
*/
public String bodyAsString() {
return body==null?null:body.asString();
}
public Element newBody() {
body = new Body();
return body();
}
public Profile newBody(String text) {
body = new Body();
body.setString(text);
return this;
}
@Override
public String toString() {
return "[secondaryType=" + secondaryType + ", name=" + name + ", description=" + description
+ ", body=" + body + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((body == null) ? 0 : body.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((secondaryType == null) ? 0 : secondaryType.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Profile other = (Profile) obj;
if (body == null) {
if (other.body != null)
return false;
} else if (!body.equals(other.body))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (secondaryType == null) {
if (other.secondaryType != null)
return false;
} else if (!secondaryType.equals(other.secondaryType))
return false;
return true;
}
}
@XmlRootElement(name="Body")
public static class Body extends AnyMixedWrapper{}
@Override
public String toString() {
return super.toString()+profile;
}
}

2271
src/main/java/org/gcube/common/resources/gcore/HostingNode.java

File diff suppressed because it is too large Load Diff

175
src/main/java/org/gcube/common/resources/gcore/Resource.java

@ -0,0 +1,175 @@
package org.gcube.common.resources.gcore;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlType;
/**
* Partial implementation for resource classes.
*
*/
@XmlType(propOrder={"id","type","scopes"})
public abstract class Resource {
//default resource type version
private static String CURRENT_VERSION = "0.4.x";
/**
* The type of the resource
*/
public static enum Type {
GENERIC{public String toString() {return "GenericResource"; }},
ENDPOINT{public String toString() {return "RuntimeResource"; }},
GCOREENDPOINT{public String toString() {return "RunningInstance"; }},
SOFTWARE{public String toString() {return "Service"; }},
NODE{public String toString() {return "GHN"; }};
}
//type string values -> enum values
private static Map<String,Type> types = new HashMap<String, Resource.Type>();
//populates type map
static {
for (Type t : Type.values())
types.put(t.toString(),t);
}
@XmlElement(name="ID")
private String id = UUID.randomUUID().toString();
@XmlElementWrapper(name = "Scopes")
@XmlElement(name = "Scope")
private Set<String> scopes = new LinkedHashSet<String>(); //order preserving
@XmlElement(name="Type")
private String type;
@XmlAttribute
private String version = CURRENT_VERSION;
public ScopeGroup<String> scopes() {
return new ScopeGroup<String>(scopes,String.class);
}
protected String addScope(String scope){
scopes.add(scope);
return scope;
}
protected String removeScope(String scope){
scopes.remove(scope);
return scope;
}
public Type type() {
return typeOf(type);
}
protected void type(Type t) {
this.type=t.toString();
}
public String version() {
return version;
}
protected void version(String version) {
this.version = version;
}
public String id() {
return id;
}
void setId(String id){
this.id=id;
}
abstract protected Object profile();
@Override
public String toString() {
return getClass().getSimpleName()+" [id=" + id + ", scopes=" + scopes + ", type=" + type + ", version=" + version
+ ", profile=" + profile() + "]";
}
//helper
private static Type typeOf(String type) {
return types.get(type);
}
//before serialisation, we null the optional fields
void beforeMarshal(Marshaller marshaller) {
if (scopes!=null && scopes.isEmpty())
scopes=null;
}
//after serialisation, we reinitialise them
void afterMarshal(Marshaller marshaller) {
if (scopes==null)
scopes=new LinkedHashSet<String>();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((scopes == null) ? 0 : scopes.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((version == null) ? 0 : version.hashCode());
result = prime * result + ((profile() == null) ? 0 : profile().hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Resource other = (Resource) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (scopes == null) {
if (other.scopes != null)
return false;
} else if (!scopes.equals(other.scopes))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
if (version == null) {
if (other.version != null)
return false;
} else if (!version.equals(other.version))
return false;
if (profile() == null) {
if (other.profile() != null)
return false;
} else if (!profile().equals(other.profile())){
return false;
}
return true;
}
}

222
src/main/java/org/gcube/common/resources/gcore/Resources.java

@ -0,0 +1,222 @@
package org.gcube.common.resources.gcore;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;
/**
* Utility methods over resources.
*
* @author Fabio Simeoni
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public class Resources {
private static SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
//known schema files embedded as classpath resources
private static Map<Class<?>, String> schemaResources = new HashMap<Class<?>, String>();
//cached schemas
private static Map<Class<?>,Schema> schemas = new HashMap<Class<?>, Schema>();
private static Map<Class<?>, JAXBContext> contexts = new HashMap<Class<?>, JAXBContext>();
static {
schemaFactory.setResourceResolver(new SchemaResolver());
//populates schema map
schemaResources.put(GenericResource.class, "schema/generic.xsd");
schemaResources.put(ServiceEndpoint.class, "schema/endpoint.xsd");
schemaResources.put(Software.class, "schema/service.xsd");
schemaResources.put(GCoreEndpoint.class, "schema/gcoreendpoint.xsd");
schemaResources.put(HostingNode.class, "schema/node.xsd");
//note: service instances have no schema so far
}
// helper: resolves common type declarations in schemas
private static class SchemaResolver implements LSResourceResolver {
private static LSInput input;
static {
try {
input = ((DOMImplementationLS) DOMImplementationRegistry.newInstance().getDOMImplementation("LS"))
.createLSInput();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId,
String baseURI) {
if (systemId.equals("CommonTypeDefinitions.xsd")) {
input.setByteStream(Resources.class.getResourceAsStream("/schema/CommonTypeDefinitions.xsd"));
}
return input;
}
};
/**
* Validates a resource against its own schema, if one exists.
* @param resource the resource
* @throws IllegalArgumentException if the resource has no associated scheme
* @throws Exception if the resource is not valid with respect to its own schema
*/
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);
schema = schemaFactory.newSchema(new StreamSource(stream));
schemas.put(resourceClass,schema);
}
return schema;
}
/**
* Write the serialisation of a given resource to a given stream.
* @param resource the resource
* @param stream the stream in input
*/
public static <T extends OutputStream> 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 extends Writer> 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
* @param stream the result
* @return the result in input
*/
public static <T extends Result> T marshal(Object resource,T result) {
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) {
throw new RuntimeException("serialisation error",e);
}
}
/**
* Prints the serialisation of a given resource to {@link System#out}
* @param resource the resource
*/
public static void print(Object resource) {
marshal(resource,new OutputStreamWriter(System.out));
}
/**
* Creates a resource of given class from its serialisation in a given {@link Reader}.
* @param resourceClass the class of the resource
* @param reader the reader
* @return the resource
*/
public static <T> T unmarshal(Class<T> resourceClass, Reader reader) {
return unmarshal(resourceClass,new StreamSource(reader));
}
/**
* Creates a resource of given class from its serialisation in a given {@link InputStream}.
* @param resourceClass the class of the resource
* @param stream the stream
* @return the resource
*/
public static <T> T unmarshal(Class<T> 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
* @param source the source
* @return the resource
*/
public static <T> T unmarshal(Class<T> resourceClass,Source source) {
try {
JAXBContext ctx = context(resourceClass);
Unmarshaller um = ctx.createUnmarshaller();
return resourceClass.cast(um.unmarshal(source));
}
catch(Exception e) {
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;
}
}

21
src/main/java/org/gcube/common/resources/gcore/ScopeGroup.java

@ -0,0 +1,21 @@
package org.gcube.common.resources.gcore;
import java.util.Collection;
import org.gcube.common.resources.gcore.utils.ReadOnlyGroup;
public class ScopeGroup<T> extends ReadOnlyGroup<T> {
public ScopeGroup(Collection<T> values, Class<? extends T> clazz) {
super(values, clazz);
}
protected boolean add(T element) {
return base.add(element);
}
protected boolean remove(T element) {
return base.remove(element);
}
}

710
src/main/java/org/gcube/common/resources/gcore/ServiceEndpoint.java

@ -0,0 +1,710 @@
package org.gcube.common.resources.gcore;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
import org.gcube.common.resources.gcore.common.GHNReference;
import org.gcube.common.resources.gcore.common.Platform;
import org.gcube.common.resources.gcore.utils.Group;
/**
* Describes endpoints of arbitrary services.
*/
@XmlRootElement(name = "Resource")
@XmlType(propOrder={"profile"})
public class ServiceEndpoint extends Resource {
public ServiceEndpoint() {
this.type(Type.ENDPOINT);
}
@XmlElementRef
private Profile profile;
public Profile profile() {
return profile;
};
public Profile newProfile() {
return profile = new Profile();
};
@XmlRootElement(name="Profile")
@XmlType(propOrder={"category","name","version","description","platform","runtime","accessPoints"})
public static class Profile {
@XmlElement(name = "Category")
private String category;
@XmlElement(name = "Name")
private String name;
@XmlElement(name = "Version")
private String version;
@XmlElement(name = "Description")
private String description;
@XmlElementRef
private Platform platform;
@XmlElementRef
private Runtime runtime;
@XmlElementRef
private List<AccessPoint> accessPoints = new ArrayList<AccessPoint>();
public String name() {
return name;
}
public Profile name(String name) {
this.name = name;
return this;
}
public String description() {
return description;
}
public Profile description(String description) {
this.description = description;
return this;
}
public String version() {
return version;
}
public Profile version(String version) {
this.version = version;
return this;
}
public String category() {
return category;
}
public Profile category(String category) {
this.category = category;
return this;
}
public Runtime runtime() {
return runtime;
}
public Runtime newRuntime() {
return runtime=new Runtime();
}
public Platform platform() {
return platform;
}
public Platform newPlatform() {
return platform = new Platform();
}
public Group<AccessPoint> accessPoints() {
return new Group<AccessPoint>(accessPoints,AccessPoint.class);
}
@Override
public String toString() {
return "[name=" + name + ", description=" + description + ", version=" + version + ", category="
+ category + ", runtime=" + runtime + ", platform=" + platform + ", accessPoints=" + accessPoints
+ "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((accessPoints == null) ? 0 : accessPoints.hashCode());
result = prime * result + ((category == null) ? 0 : category.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((platform == null) ? 0 : platform.hashCode());
result = prime * result + ((runtime == null) ? 0 : runtime.hashCode());
result = prime * result + ((version == null) ? 0 : version.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Profile other = (Profile) obj;
if (accessPoints == null) {
if (other.accessPoints != null)
return false;
} else if (!accessPoints.equals(other.accessPoints))
return false;
if (category == null) {
if (other.category != null)
return false;
} else if (!category.equals(other.category))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (platform == null) {
if (other.platform != null)
return false;
} else if (!platform.equals(other.platform))
return false;
if (runtime == null) {
if (other.runtime != null)
return false;
} else if (!runtime.equals(other.runtime))
return false;
if (version == null) {
if (other.version != null)
return false;
} else if (!version.equals(other.version))
return false;
return true;
}
}
@XmlRootElement(name = "RunTime")
@XmlType(propOrder={"hostedOn","ghn","status"})
public static class Runtime {
@XmlElement(name = "HostedOn")
private String hostedOn;
@XmlElement(name = "GHN")
private GHNReference ghn = new GHNReference();
@XmlElement(name = "Status")
private String status;
public String hostedOn() {
return hostedOn;
}
public Runtime hostedOn(String hostedOn) {
this.hostedOn = hostedOn;
return this;
}
public String status() {
return status;
}
public Runtime status(String status) {
this.status = status;
return this;
}
public String ghnId() {
return ghn.id;
}
public Runtime ghnId(String id) {
this.ghn.id=id;
return this;
}
//before serialisation, we null the optional fields
void beforeMarshal(Marshaller marshaller) {
if (ghn!=null && ghn.id==null)
ghn=null;
}
//after serialisation, we reinitialise them
void afterMarshal(Marshaller marshaller) {
if (ghn==null)
ghn = new GHNReference();
}
@Override
public String toString() {
return "[hostedOn=" + hostedOn + ", status=" + status + ", ghn=" + ghn + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((ghn == null) ? 0 : ghn.hashCode());
result = prime * result + ((hostedOn == null) ? 0 : hostedOn.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Runtime other = (Runtime) obj;
if (ghn == null) {
if (other.ghn != null)
return false;
} else if (!ghn.equals(other.ghn))
return false;
if (hostedOn == null) {
if (other.hostedOn != null)
return false;
} else if (!hostedOn.equals(other.hostedOn))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
return true;
}
}
@XmlRootElement(name = "AccessData")
@XmlType(propOrder={"username","password"})
static class AccessData {
@XmlElement(name = "Username")
private String username;
@XmlElement(name = "Password")
private String password;
public void set(String password,String username) {
this.password = password;
this.username=username;
}
@Override
public String toString() {
return "[username=" + username + ", password=" + password + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((password == null) ? 0 : password.hashCode());
result = prime * result + ((username == null) ? 0 : username.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AccessData other = (AccessData) obj;
if (password == null) {
if (other.password != null)
return false;
} else if (!password.equals(other.password))
return false;
if (username == null) {
if (other.username != null)
return false;
} else if (!username.equals(other.username))
return false;
return true;
}
}
@XmlRootElement(name = "Endpoint")
public static class Endpoint {
@XmlAttribute(name = "EntryName")
private String name;
@XmlValue
private String address;
public String name() {
return name;
}
public String address() {
return address;
}
public void name(String name) {
this.name = name;
}
public void address(String address) {
this.address = address;
}
@Override
public String toString() {
return "[name=" + name + ", address=" + address + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((address == null) ? 0 : address.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Endpoint other = (Endpoint) obj;
if (address == null) {
if (other.address != null)
return false;
} else if (!address.equals(other.address))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}
@XmlRootElement(name = "Interface")
public static class Interface {
@XmlElementRef
private Endpoint endpoint = new Endpoint();
public Endpoint endpoint() {
return endpoint;
}
@Override
public String toString() {
return "[endpoints=" + endpoint + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Interface other = (Interface) obj;
if (endpoint == null) {
if (other.endpoint != null)
return false;
} else if (!endpoint.equals(other.endpoint))
return false;
return true;
}
}
@XmlRootElement(name = "AccessPoint")
@XmlType(propOrder={"description","itfce","accessData","properties"})
public static class AccessPoint {
@XmlElement(name = "Description")
private String description;