View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/filestore/common/src/java/org/astrogrid/filestore/common/identifier/UniqueIdentifier.java,v $</cvs:source>
3    * <cvs:author>$Author: jdt $</cvs:author>
4    * <cvs:date>$Date: 2004/11/25 00:19:27 $</cvs:date>
5    * <cvs:version>$Revision: 1.4 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: UniqueIdentifier.java,v $
9    *   Revision 1.4  2004/11/25 00:19:27  jdt
10   *   Merge from dave-dev-200410061224-200411221626
11   *
12   *   Revision 1.3.46.1  2004/10/21 21:00:13  dave
13   *   Added mock://xyz URL handler to enable testing of transfer.
14   *   Implemented importInit to the mock service and created transfer tests.
15   *
16   *   Revision 1.3  2004/08/18 19:00:01  dave
17   *   Myspace manager modified to use remote filestore.
18   *   Tested before checkin - integration tests at 91%.
19   *
20   *   Revision 1.2.22.1  2004/08/04 17:03:33  dave
21   *   Added container to servlet
22   *
23   *   Revision 1.2  2004/07/14 13:50:29  dave
24   *   Merged development branch, dave-dev-200406301228, into HEAD
25   *
26   *   Revision 1.1.2.3  2004/07/12 14:39:03  dave
27   *   Added server repository classes
28   *
29   *   Revision 1.1.2.2  2004/07/07 14:24:14  dave
30   *   Changed internal class DataConrainer to FileContainer
31   *
32   *   Revision 1.1.2.1  2004/07/05 04:50:29  dave
33   *   Created initial FileStore components
34   *
35   * </cvs:log>
36   *
37   */
38  package org.astrogrid.filestore.common.identifier ;
39  
40  import java.rmi.server.UID ;
41  
42  /***
43   * A base class for unique identifiers.
44   * This enable us to swap between different identifier generator implementations.
45   * @todo Move this to astrogrid common ?
46   *
47   */
48  public class UniqueIdentifier
49      {
50      /***
51       * Create a new unique identifier.
52       *
53       */
54      public UniqueIdentifier()
55          {
56          //
57          // Use the RMI library to generate a new identifier.
58          UID uid = new UID() ;
59  		//
60  		// Split it on non.
61  		String[] temp = uid.toString().split("[^a-zA-Z0-9]") ;
62  		//
63  		// Start with an empty StringBuffer.
64  		StringBuffer buffer = new StringBuffer() ;
65  		for (int i = 0 ; i < temp.length ; i++)
66  			{
67  			if (temp[i].length() > 0)
68  				{
69  				if (i > 0)
70  					{
71  					buffer.append(".") ;
72  					}
73  				buffer.append(
74  					temp[i]
75  					) ;
76  				}
77  			}
78  		this.string = buffer.toString() ;
79          }
80  
81      /***
82       * Create an identifier from a string.
83       * @param ident The identifier string.
84  	 * @throws IllegalArgumentException If the identifier is null or invalid.
85       * @todo This should throw an Exception if the format is not valid.
86       *
87       */
88      public UniqueIdentifier(String ident)
89          {
90  		if (null == ident)
91  			{
92  			throw new IllegalArgumentException(
93  				"Null identifier"
94  				) ;
95  			}
96          this.string = ident ;
97          }
98  
99      /***
100      * An internal string representation of the identifier.
101      *
102      */
103     private String string ;
104 
105     /***
106      * Convert the identifier to a String.
107      *
108      */
109     public String toString()
110         {
111         return this.string ;
112         }
113 
114 	/***
115 	 * Generate a new identifier.
116 	 *
117 	 */
118 	public static UniqueIdentifier next()
119 		{
120 		return new UniqueIdentifier() ;
121 		}
122 
123     }
124 
125