View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.workgroup;
17  
18  import org.kuali.rice.kew.util.Utilities;
19  import org.kuali.rice.kim.api.KimConstants;
20  
21  /**
22   * A {@link GroupId} which identifies the name of a {@link Workgroup}.
23   *
24   * @see Workgroup
25   *
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public final class GroupNameId implements GroupId {
29  
30  	private static final long serialVersionUID = -4625193242111678434L;
31  
32  	private String namespace = KimConstants.KIM_GROUP_DEFAULT_NAMESPACE_CODE;
33  	private String nameId;
34  
35      public GroupNameId(String nameId) {
36          this.nameId = nameId;
37          this.namespace = Utilities.parseGroupNamespaceCode(nameId);
38          this.nameId = Utilities.parseGroupName(nameId);
39      }
40  
41      public GroupNameId(String namespace, String nameId) {
42      	this.namespace = namespace;
43      	this.nameId = nameId;
44      }
45  
46      public String getNameId() {
47          return nameId;
48      }
49  
50      public String getNamespace() {
51      	return namespace;
52      }
53  
54      public boolean isEmpty() {
55        return (nameId == null) || (nameId.trim().length() == 0);
56    }
57  
58      /**
59       * If you make this class non-final, you must rewrite equals to work for subclasses.
60       */
61      public boolean equals(Object obj) {
62          boolean isEqual = false;
63  
64          if (obj != null && (obj instanceof GroupNameId)) {
65              GroupNameId w = (GroupNameId) obj;
66  
67              if (w.getNameId() != null && getNameId() != null) {
68                  return w.getNameId().equals(getNameId()) && w.getNamespace().equals(getNamespace());
69              } else {
70                  return false;
71              }
72          }
73  
74          return isEqual;
75      }
76  
77      public int hashCode() {
78          if (nameId == null) {
79              return 0;
80          }
81          return nameId.hashCode();
82      }
83  
84      public String toString() {
85          if (nameId != null) {
86              return nameId;
87          }
88          return "null";
89      }
90  
91  }