View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/common/src/java/org/astrogrid/community/common/policy/data/CommunityIdent.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.6 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: CommunityIdent.java,v $
9    *   Revision 1.6  2004/07/14 13:50:07  dave
10   *   Merged development branch, dave-dev-200406301228, into HEAD
11   *
12   *   Revision 1.5.12.1  2004/07/05 14:18:55  dave
13   *   Tried to remove the JConfig libraries
14   *
15   *   Revision 1.5  2004/06/18 13:45:20  dave
16   *   Merged development branch, dave-dev-200406081614, into HEAD
17   *
18   *   Revision 1.4.62.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 CommunityIdent
34      {
35      /***
36       * The default account name.
37       *
38       */
39      public static String DEFAULT_ACCOUNT = "nobody" ;
40  
41      /***
42       * The separator for name and community.
43       *
44       */
45      public static char IDENT_SEPARATOR = '@' ;
46  
47      /***
48       * Flag to indicate the ident is valid.
49       *
50       */
51      private boolean valid = false ;
52  
53      /***
54       * Flag to indicate the ident is local.
55       *
56       */
57      private boolean local = false ;
58  
59      /***
60       * Our ident.
61       *
62       */
63      private String ident ;
64  
65      /***
66       * Our ident name.
67       *
68       */
69      private String name ;
70  
71      /***
72       * Our Ident community.
73       *
74       */
75      private String community ;
76  
77      /***
78       * Public constructor.
79       *
80       */
81      public CommunityIdent(String ident)
82          {
83          //
84          // Check for a null ident.
85          if ((null == ident) || (0 == ident.length()))
86              {
87              ident = DEFAULT_ACCOUNT ;
88              }
89          //
90          // Convert everything to lowercase.
91          ident = ident.toLowerCase() ;
92          //
93          // Save the ident.
94          this.ident = ident ;
95          //
96          // Find the first and last separator.
97          int first = ident.indexOf(IDENT_SEPARATOR) ;
98          int last  = ident.lastIndexOf(IDENT_SEPARATOR) ;
99          //
100         // If the ident contains separator.
101         if (-1 != first)
102             {
103             //
104             // If the first and last are the same.
105             if (first == last)
106                 {
107                 //
108                 // Split the ident into name and community.
109                 this.name = ident.substring(0, first) ;
110                 this.community = ident.substring(first + 1) ;
111 //
112 // Check the lengths ...
113 //
114                 //
115                 // Check if the community is local.
116                 if (CommunityConfig.getCommunityName().equals(this.community))
117                     {
118                     this.valid = true ;
119                     this.local = true ;
120                     }
121                 //
122                 // If the community is not local.
123                 else {
124                     this.valid = true ;
125                     this.local = false ;
126                     }
127                 }
128             //
129             // If the first and last do not match.
130             else {
131                 this.valid = false ;
132                 this.local = false ;
133                 this.name  = null ;
134                 this.community = null ;
135                 }
136             }
137         //
138         // If the ident does not contain a community.
139         else {
140             //
141             // Use the local community ident.
142             this.name = ident ;
143             this.community = CommunityConfig.getCommunityName() ;
144             this.ident = this.name +  IDENT_SEPARATOR + this.community ;
145             this.valid = true ;
146             this.local = true ;
147             }
148         }
149 
150     /***
151      * Public constructor.
152      *
153      */
154     public CommunityIdent(String name, String community)
155         {
156         this(name +  IDENT_SEPARATOR + community) ;
157         }
158 
159     /***
160      * Is this a valid ident.
161      *
162      */
163     public boolean isValid()
164         {
165         return this.valid ;
166         }
167 
168     /***
169      * Is this a local ident.
170      *
171      */
172     public boolean isLocal()
173         {
174         return this.local ;
175         }
176 
177     /***
178      * Get the name from this ident.
179      *
180      */
181     public String getName()
182         {
183         return this.name ;
184         }
185 
186     /***
187      * Get the community name from this ident.
188      *
189      */
190     public String getCommunity()
191         {
192         return this.community ;
193         }
194 
195     /***
196      * Convert the ident as a string.
197      *
198      */
199     public String toString()
200         {
201         return this.ident ;
202         }
203 
204     }