2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.model
.common
;
12 import java
.util
.HashMap
;
15 import javax
.persistence
.Entity
;
16 import javax
.persistence
.FetchType
;
17 import javax
.persistence
.Transient
;
18 import javax
.wsdl
.Definition
;
19 import javax
.xml
.bind
.annotation
.XmlAccessType
;
20 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
21 import javax
.xml
.bind
.annotation
.XmlElement
;
22 import javax
.xml
.bind
.annotation
.XmlRootElement
;
23 import javax
.xml
.bind
.annotation
.XmlTransient
;
24 import javax
.xml
.bind
.annotation
.XmlType
;
25 import javax
.xml
.bind
.annotation
.adapters
.XmlJavaTypeAdapter
;
27 import org
.hibernate
.annotations
.CollectionOfElements
;
28 import org
.hibernate
.annotations
.NaturalId
;
29 import org
.hibernate
.annotations
.Type
;
30 import org
.hibernate
.annotations
.TypeDef
;
31 import org
.hibernate
.annotations
.TypeDefs
;
33 import com
.ibm
.lsid
.MalformedLSIDException
;
35 import eu
.etaxonomy
.cdm
.hibernate
.WSDLDefinitionUserType
;
36 import eu
.etaxonomy
.cdm
.jaxb
.NamespacesAdapter
;
38 @XmlAccessorType(XmlAccessType
.FIELD
)
39 @XmlType(name
= "LSIDAuthority", propOrder
= {
46 @XmlRootElement(name
= "LSIDAuthority")
48 @TypeDefs(@TypeDef(name
="wsdlDefinitionUserType", typeClass
=WSDLDefinitionUserType
.class))
49 public class LSIDAuthority
extends CdmBase
{
54 private static final long serialVersionUID
= 9168994979216936689L;
56 public static final String AUTHORITY_ID_PREFIX
= "lsidauth:";
58 private static final String AUTHORITY_PROTOCOL
="http";
59 private static final String AUTHORITY_PATH
="/authority/";
61 @XmlElement(name
= "Authority")
63 private String authority
;
65 // the resolved components of the lsid
66 @XmlElement(name
= "Server")
67 private String server
;
68 @XmlElement(name
= "Port")
69 private int port
= -1;
70 @XmlElement(name
= "Url")
73 // the wsdl describing how to invoke operations on the authority
75 @Type(type
= "wsdlDefinitionUserType")
76 private Definition authorityWSDL
;
78 @XmlElement(name
= "Namespaces")
79 @XmlJavaTypeAdapter(NamespacesAdapter
.class)
80 @CollectionOfElements(fetch
= FetchType
.LAZY
)
81 private Map
<String
,Class
<?
extends IIdentifiableEntity
>> namespaces
= new HashMap
<String
,Class
<?
extends IIdentifiableEntity
>>();
84 * Hibernate requires a no-arguement constructor (this could be private, I suppose)
86 private LSIDAuthority() { }
89 * Construct an LSID authority object.
90 * @param String LSID Authority must be valid authority string, or an ID of the form: lsidauth:<validauthoritystring>"
92 public LSIDAuthority(String authstr
) throws MalformedLSIDException
{
94 authority
= authstr
.toLowerCase();
95 if (authority
.startsWith(AUTHORITY_ID_PREFIX
))
96 authority
= authority
.substring(AUTHORITY_ID_PREFIX
.length());
97 } catch (Exception e
) {
98 throw new MalformedLSIDException(e
, "LSID Authority must be valid authority string, or of form: lsidauth:<validauthoritystring>");
103 * Convenience constructor, construct an LSID authority object
104 * @param LSID use this LSID's authority to construct this object
106 public LSIDAuthority(LSID lsid
) throws MalformedLSIDException
{
107 authority
= lsid
.getAuthority();
111 * Returns the authority String
112 * @return String the authority String
114 public String
getAuthority() {
119 * Returns the authority ID representation of this authority, lsidauth:authstr
120 * @return String the ID representation
122 public String
getAuthorityID() {
123 return AUTHORITY_ID_PREFIX
+ authority
;
127 * Returns the authority String
128 * @return String the authority String
130 public String
toString() {
135 * Tests equality on the authority string
138 public boolean equals(Object o
) {
139 if (!(o
instanceof LSIDAuthority
))
141 LSIDAuthority auth
= (LSIDAuthority
)o
;
142 return o
.toString().equals(toString());
146 * Returns the port of the resolved Authority, invalid until resolved.
147 * @return int the port.
149 public int getPort() {
154 * Returns the server of the resolved Authority, invalid until resolved.
155 * @return String the hostname of the server
157 public String
getServer() {
162 * Returns the url of the resolved Authority, invalid until resolved. This overrides the
163 * server and port properties, and might contain a full path or even a different protocol.
167 public String
getUrl() {
169 if (server
!= null && port
!= -1)
170 url
= "http://" + getServer() + ":" + getPort() + AUTHORITY_PATH
;
179 * @param port The port to set
181 public void setPort(int port
) {
187 * @param server The server to set
189 public void setServer(String server
) {
190 this.server
= server
;
194 * Sets the URL to use. This overrides the server and port properties, and might contain a full path or even a
195 * different protocol.
196 * @param server The server to set
198 public void setUrl(String url
) {
203 * Set the wsdl describing the ports available
204 * @param LSIDWSDLWrapper the wsdl to set
206 public void setWSDL(Definition wsdl
) {
207 this.authorityWSDL
= wsdl
;
211 * get the wsdl describing the ports available
212 * @return LSIDWSDLWRapper the wsdl
214 public Definition
getWSDL() {
215 return this.authorityWSDL
;
219 * @return boolean, whether or not the authority has been resolved.
222 public boolean isResolved() {
223 return (getUrl() != null);
227 * get the url of an authority with the given server and port
229 public String
getAuthorityEnpointURL(String server
, int port
) {
230 return AUTHORITY_PROTOCOL
+ "://" + server
+ ":" + port
+ AUTHORITY_PATH
;
233 public Map
<String
,Class
<?
extends IIdentifiableEntity
>> getNamespaces() {
237 public void addNamespace(String namespace
, Class
<?
extends IIdentifiableEntity
> identifiableClass
) {
238 this.namespaces
.put(namespace
, identifiableClass
);
241 public void removeNamespace(String namespace
) {
242 this.namespaces
.remove(namespace
);