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
.io
.Serializable
;
13 import java
.util
.NoSuchElementException
;
14 import java
.util
.StringTokenizer
;
16 import javax
.persistence
.Embeddable
;
18 import com
.ibm
.lsid
.MalformedLSIDException
;
21 * This class is copied from com.ibm.lsid.LSID, I needed to re-implement this since
22 * the domain objects are required to be Serializable
25 * @author Ben Szekely (<a href="mailto:bhszekel@us.ibm.com">bhszekel@us.ibm.com</a>)
27 * @see com.ibm.lsid.client.LSID
30 public class LSID
implements Serializable
{
34 private String authority
;
36 private String namespace
;
38 private String object
;
40 private String revision
;
45 * Construct a new LSID with the String representation.
46 * @param String The lsid String respresentation
48 public LSID(String lsid
) throws MalformedLSIDException
{
49 if (lsid
.endsWith(":")) {
50 lsid
= lsid
.substring(0, lsid
.length() - 1);
52 StringTokenizer st
= new StringTokenizer(lsid
, ":");
53 // check for urn and lsid
55 String urn
= st
.nextToken().toLowerCase();
56 String l
= st
.nextToken().toLowerCase();
57 if (!urn
.equals("urn") || !l
.equals("lsid")) {
58 throw new MalformedLSIDException("urn:lsid: not found: [" + lsid
+ "]");
61 catch (NoSuchElementException e
) {
62 throw new MalformedLSIDException(e
, "urn:lsid: not found: [" + lsid
+ "]");
66 authority
= st
.nextToken().toLowerCase();
68 catch (NoSuchElementException e
) {
69 throw new MalformedLSIDException(e
, "authority not found: [" + lsid
+ "]");
73 namespace
= st
.nextToken();
75 catch (NoSuchElementException e
) {
76 throw new MalformedLSIDException(e
, "namespace not found: [" + lsid
+ "]");
80 object
= st
.nextToken();
82 catch (NoSuchElementException e
) {
83 throw new MalformedLSIDException(e
, "object not found: [" + lsid
+ "]");
85 if (st
.hasMoreTokens()) {
86 revision
= st
.nextToken();
89 this.lsid
= "urn:lsid:" + this.authority
+ ":" + this.namespace
+ ":" + this.object
+ (this.revision
!= null ?
":" + this.revision
: "");
93 * Construct a new LSID with the given components
94 * @param String the authority
95 * @param String the namespace
96 * @param String the object
97 * @param String the revision, can be null
99 public LSID(String authority
, String namespace
, String object
, String revision
) throws MalformedLSIDException
{
100 this.authority
= authority
.toLowerCase();
101 this.namespace
= namespace
;//.toLowerCase();
102 this.object
= object
;//.toLowerCase();
103 if (revision
!= null)
104 this.revision
= revision
;//.toLowerCase();
105 lsid
= "urn:lsid:" + this.authority
+ ":" + this.namespace
+ ":" + this.object
+ (this.revision
!= null ?
":" + this.revision
: "");
110 * @return String The lsid String representation
112 public String
getLsid() {
119 * Returns the authority component of the LSID
120 * @return LSIDAuthority the authority
122 public String
getAuthority() {
127 * Returns the namespace component of the LSID
130 public String
getNamespace() {
135 * Returns the object component of the LSID
138 public String
getObject() {
143 * Returns the revision component of the LSID if it exists
146 public String
getRevision() {
151 * return the string representation
154 public String
toString() {
159 * Two LSIDs are equal their string representations are equal disregarding case.
161 public boolean equals(Object lsid
) {
164 } else if (lsid
!= null && lsid
instanceof LSID
) {
165 LSID theLSID
= (LSID
)lsid
;
166 return theLSID
.toString().equals(toString());