1 package eu
.etaxonomy
.cdm
.model
.common
;
3 import java
.util
.HashMap
;
6 import javax
.persistence
.Entity
;
7 import javax
.persistence
.FetchType
;
8 import javax
.wsdl
.Definition
;
10 import org
.hibernate
.annotations
.CollectionOfElements
;
11 import org
.hibernate
.annotations
.NaturalId
;
12 import org
.hibernate
.annotations
.Type
;
13 import org
.hibernate
.annotations
.TypeDef
;
14 import org
.hibernate
.annotations
.TypeDefs
;
16 import com
.ibm
.lsid
.MalformedLSIDException
;
19 @TypeDefs(@TypeDef(name
="wsdlDefinitionUserType", typeClass
=WSDLDefinitionUserType
.class))
20 public class LSIDAuthority
extends CdmBase
{
25 private static final long serialVersionUID
= 9168994979216936689L;
27 public static final String AUTHORITY_ID_PREFIX
= "lsidauth:";
29 private static final String AUTHORITY_PROTOCOL
="http";
30 private static final String AUTHORITY_PATH
="/authority/";
33 private String authority
;
35 // the resolved components of the lsid
36 private String server
;
37 private int port
= -1;
40 // the wsdl describing how to invoke operations on the authority
41 @Type(type
= "wsdlDefinitionUserType")
42 private Definition authorityWSDL
;
44 @CollectionOfElements(fetch
= FetchType
.LAZY
)
45 private Map
<String
,Class
<?
extends IIdentifiableEntity
>> namespaces
= new HashMap
<String
,Class
<?
extends IIdentifiableEntity
>>();
48 * Hibernate requires a no-arguement constructor (this could be private, I suppose)
50 private LSIDAuthority() { }
53 * Construct an LSID authority object.
54 * @param String LSID Authority must be valid authority string, or an ID of the form: lsidauth:<validauthoritystring>"
56 public LSIDAuthority(String authstr
) throws MalformedLSIDException
{
58 authority
= authstr
.toLowerCase();
59 if (authority
.startsWith(AUTHORITY_ID_PREFIX
))
60 authority
= authority
.substring(AUTHORITY_ID_PREFIX
.length());
61 } catch (Exception e
) {
62 throw new MalformedLSIDException(e
, "LSID Authority must be valid authority string, or of form: lsidauth:<validauthoritystring>");
67 * Convenience constructor, construct an LSID authority object
68 * @param LSID use this LSID's authority to construct this object
70 public LSIDAuthority(LSID lsid
) throws MalformedLSIDException
{
71 authority
= lsid
.getAuthority();
75 * Returns the authority String
76 * @return String the authority String
78 public String
getAuthority() {
83 * Returns the authority ID representation of this authority, lsidauth:authstr
84 * @return String the ID representation
86 public String
getAuthorityID() {
87 return AUTHORITY_ID_PREFIX
+ authority
;
91 * Returns the authority String
92 * @return String the authority String
94 public String
toString() {
99 * Tests equality on the authority string
102 public boolean equals(Object o
) {
103 if (!(o
instanceof LSIDAuthority
))
105 LSIDAuthority auth
= (LSIDAuthority
)o
;
106 return o
.toString().equals(toString());
110 * Returns the port of the resolved Authority, invalid until resolved.
111 * @return int the port.
113 public int getPort() {
118 * Returns the server of the resolved Authority, invalid until resolved.
119 * @return String the hostname of the server
121 public String
getServer() {
126 * Returns the url of the resolved Authority, invalid until resolved. This overrides the
127 * server and port properties, and might contain a full path or even a different protocol.
130 public String
getUrl() {
132 if (server
!= null && port
!= -1)
133 url
= "http://" + getServer() + ":" + getPort() + AUTHORITY_PATH
;
142 * @param port The port to set
144 public void setPort(int port
) {
150 * @param server The server to set
152 public void setServer(String server
) {
153 this.server
= server
;
157 * Sets the URL to use. This overrides the server and port properties, and might contain a full path or even a
158 * different protocol.
159 * @param server The server to set
161 public void setUrl(String url
) {
166 * Set the wsdl describing the ports available
167 * @param LSIDWSDLWrapper the wsdl to set
169 public void setWSDL(Definition wsdl
) {
170 this.authorityWSDL
= wsdl
;
174 * get the wsdl describing the ports available
175 * @return LSIDWSDLWRapper the wsdl
177 public Definition
getWSDL() {
178 return this.authorityWSDL
;
182 * @return boolean, whether or not the authority has been resolved.
184 public boolean isResolved() {
185 return (getUrl() != null);
189 * get the url of an authority with the given server and port
191 public String
getAuthorityEnpointURL(String server
, int port
) {
192 return AUTHORITY_PROTOCOL
+ "://" + server
+ ":" + port
+ AUTHORITY_PATH
;
195 public Map
<String
,Class
<?
extends IIdentifiableEntity
>> getNamespaces() {
199 public void addNamespace(String namespace
, Class
<?
extends IIdentifiableEntity
> identifiableClass
) {
200 this.namespaces
.put(namespace
, identifiableClass
);
203 public void removeNamespace(String namespace
) {
204 this.namespaces
.remove(namespace
);