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
.persistence
.Transient
;
9 import javax
.wsdl
.Definition
;
10 import javax
.xml
.bind
.annotation
.XmlAccessType
;
11 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
12 import javax
.xml
.bind
.annotation
.XmlElement
;
13 import javax
.xml
.bind
.annotation
.XmlRootElement
;
14 import javax
.xml
.bind
.annotation
.XmlTransient
;
15 import javax
.xml
.bind
.annotation
.XmlType
;
16 import javax
.xml
.bind
.annotation
.adapters
.XmlJavaTypeAdapter
;
18 import org
.hibernate
.annotations
.CollectionOfElements
;
19 import org
.hibernate
.annotations
.NaturalId
;
20 import org
.hibernate
.annotations
.Type
;
21 import org
.hibernate
.annotations
.TypeDef
;
22 import org
.hibernate
.annotations
.TypeDefs
;
23 import org
.hibernate
.envers
.Audited
;
25 import com
.ibm
.lsid
.MalformedLSIDException
;
27 import eu
.etaxonomy
.cdm
.jaxb
.NamespacesAdapter
;
29 @XmlAccessorType(XmlAccessType
.FIELD
)
30 @XmlType(name
= "LSIDAuthority", propOrder
= {
37 @XmlRootElement(name
= "LSIDAuthority")
39 @TypeDefs(@TypeDef(name
="wsdlDefinitionUserType", typeClass
=WSDLDefinitionUserType
.class))
40 public class LSIDAuthority
extends CdmBase
{
45 private static final long serialVersionUID
= 9168994979216936689L;
47 public static final String AUTHORITY_ID_PREFIX
= "lsidauth:";
49 private static final String AUTHORITY_PROTOCOL
="http";
50 private static final String AUTHORITY_PATH
="/authority/";
52 @XmlElement(name
= "Authority")
54 private String authority
;
56 // the resolved components of the lsid
57 @XmlElement(name
= "Server")
58 private String server
;
59 @XmlElement(name
= "Port")
60 private int port
= -1;
61 @XmlElement(name
= "Url")
64 // the wsdl describing how to invoke operations on the authority
66 @Type(type
= "wsdlDefinitionUserType")
67 private Definition authorityWSDL
;
69 @XmlElement(name
= "Namespaces")
70 @XmlJavaTypeAdapter(NamespacesAdapter
.class)
71 @CollectionOfElements(fetch
= FetchType
.LAZY
)
72 private Map
<String
,Class
<?
extends IIdentifiableEntity
>> namespaces
= new HashMap
<String
,Class
<?
extends IIdentifiableEntity
>>();
75 * Hibernate requires a no-arguement constructor (this could be private, I suppose)
77 private LSIDAuthority() { }
80 * Construct an LSID authority object.
81 * @param String LSID Authority must be valid authority string, or an ID of the form: lsidauth:<validauthoritystring>"
83 public LSIDAuthority(String authstr
) throws MalformedLSIDException
{
85 authority
= authstr
.toLowerCase();
86 if (authority
.startsWith(AUTHORITY_ID_PREFIX
))
87 authority
= authority
.substring(AUTHORITY_ID_PREFIX
.length());
88 } catch (Exception e
) {
89 throw new MalformedLSIDException(e
, "LSID Authority must be valid authority string, or of form: lsidauth:<validauthoritystring>");
94 * Convenience constructor, construct an LSID authority object
95 * @param LSID use this LSID's authority to construct this object
97 public LSIDAuthority(LSID lsid
) throws MalformedLSIDException
{
98 authority
= lsid
.getAuthority();
102 * Returns the authority String
103 * @return String the authority String
105 public String
getAuthority() {
110 * Returns the authority ID representation of this authority, lsidauth:authstr
111 * @return String the ID representation
113 public String
getAuthorityID() {
114 return AUTHORITY_ID_PREFIX
+ authority
;
118 * Returns the authority String
119 * @return String the authority String
121 public String
toString() {
126 * Tests equality on the authority string
129 public boolean equals(Object o
) {
130 if (!(o
instanceof LSIDAuthority
))
132 LSIDAuthority auth
= (LSIDAuthority
)o
;
133 return o
.toString().equals(toString());
137 * Returns the port of the resolved Authority, invalid until resolved.
138 * @return int the port.
140 public int getPort() {
145 * Returns the server of the resolved Authority, invalid until resolved.
146 * @return String the hostname of the server
148 public String
getServer() {
153 * Returns the url of the resolved Authority, invalid until resolved. This overrides the
154 * server and port properties, and might contain a full path or even a different protocol.
158 public String
getUrl() {
160 if (server
!= null && port
!= -1)
161 url
= "http://" + getServer() + ":" + getPort() + AUTHORITY_PATH
;
170 * @param port The port to set
172 public void setPort(int port
) {
178 * @param server The server to set
180 public void setServer(String server
) {
181 this.server
= server
;
185 * Sets the URL to use. This overrides the server and port properties, and might contain a full path or even a
186 * different protocol.
187 * @param server The server to set
189 public void setUrl(String url
) {
194 * Set the wsdl describing the ports available
195 * @param LSIDWSDLWrapper the wsdl to set
197 public void setWSDL(Definition wsdl
) {
198 this.authorityWSDL
= wsdl
;
202 * get the wsdl describing the ports available
203 * @return LSIDWSDLWRapper the wsdl
205 public Definition
getWSDL() {
206 return this.authorityWSDL
;
210 * @return boolean, whether or not the authority has been resolved.
213 public boolean isResolved() {
214 return (getUrl() != null);
218 * get the url of an authority with the given server and port
220 public String
getAuthorityEnpointURL(String server
, int port
) {
221 return AUTHORITY_PROTOCOL
+ "://" + server
+ ":" + port
+ AUTHORITY_PATH
;
224 public Map
<String
,Class
<?
extends IIdentifiableEntity
>> getNamespaces() {
228 public void addNamespace(String namespace
, Class
<?
extends IIdentifiableEntity
> identifiableClass
) {
229 this.namespaces
.put(namespace
, identifiableClass
);
232 public void removeNamespace(String namespace
) {
233 this.namespaces
.remove(namespace
);