View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/common/src/java/org/astrogrid/community/common/policy/data/ResourceIdent.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/07/14 13:50:07 $</cvs:date>
5    * <cvs:version>$Revision: 1.4 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: ResourceIdent.java,v $
9    *   Revision 1.4  2004/07/14 13:50:07  dave
10   *   Merged development branch, dave-dev-200406301228, into HEAD
11   *
12   *   Revision 1.3.12.1  2004/07/05 14:18:55  dave
13   *   Tried to remove the JConfig libraries
14   *
15   *   Revision 1.3  2004/06/18 13:45:20  dave
16   *   Merged development branch, dave-dev-200406081614, into HEAD
17   *
18   *   Revision 1.2.70.1  2004/06/17 13:38:58  dave
19   *   Tidied up old CVS log entries
20   *
21   * </cvs:log>
22   *
23   */
24  package org.astrogrid.community.common.policy.data ;
25  
26  import org.astrogrid.community.common.config.CommunityConfig ;
27  
28  /***
29   * @todo deprecate the whole class.
30   *
31   *
32   */
33  public class ResourceIdent
34      {
35      /***
36       * The separator for name and community.
37       *
38       */
39      public static char IDENT_SEPARATOR = ':' ;
40  
41      /***
42       * Flag to indicate the ident is valid.
43       *
44       */
45      private boolean valid = false ;
46  
47      /***
48       * Flag to indicate the ident is local.
49       *
50       */
51      private boolean local = false ;
52  
53      /***
54       * Our ident.
55       *
56       */
57      private String ident ;
58  
59      /***
60       * Our ident name.
61       *
62       */
63      private String name ;
64  
65      /***
66       * Our Ident community.
67       *
68       */
69      private String community ;
70  
71      /***
72       * Public constructor.
73       *
74       */
75      public ResourceIdent(String ident)
76          {
77          //
78          // Save the ident.
79          this.ident = ident ;
80          //
81          // Find the first and last separator.
82          int first = ident.indexOf(IDENT_SEPARATOR) ;
83          int last  = ident.lastIndexOf(IDENT_SEPARATOR) ;
84          //
85          // If the ident contains separator.
86          if (-1 != first)
87              {
88              //
89              // If the first and last are the same.
90              if (first == last)
91                  {
92                  //
93                  // Split the ident into name and community.
94                  this.community = ident.substring(0, first) ;
95                  this.name      = ident.substring(first + 1) ;
96  //
97  // Check the lengths ...
98  //
99                  //
100                 // Check if the community is local.
101                 if (CommunityConfig.getCommunityName().equals(this.community))
102                     {
103                     this.valid = true ;
104                     this.local = true ;
105                     }
106                 //
107                 // If the community is not local.
108                 else {
109                     this.valid = true ;
110                     this.local = false ;
111                     }
112                 }
113             //
114             // If the first and last do not match.
115             else {
116                 this.valid = false ;
117                 this.local = false ;
118                 this.name  = null ;
119                 this.community = null ;
120                 }
121             }
122         //
123         // If the ident does not contain a community.
124         else {
125             //
126             // Use the local community ident.
127             this.name = ident ;
128             this.community = CommunityConfig.getCommunityName() ;
129             this.ident = this.community +  IDENT_SEPARATOR + this.name ;
130             this.valid = true ;
131             this.local = true ;
132             }
133         }
134 
135     /***
136      * Is this a valid ident.
137      *
138      */
139     public boolean isValid()
140         {
141         return this.valid ;
142         }
143 
144     /***
145      * Is this a local ident.
146      *
147      */
148     public boolean isLocal()
149         {
150         return this.local ;
151         }
152 
153     /***
154      * Get the name from this ident.
155      *
156      */
157     public String getName()
158         {
159         return this.name ;
160         }
161 
162     /***
163      * Get the community name from this ident.
164      *
165      */
166     public String getCommunity()
167         {
168         return this.community ;
169         }
170 
171     /***
172      * Convert the ident as a string.
173      *
174      */
175     public String toString()
176         {
177         return this.ident ;
178         }
179 
180     }