001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kew.workgroup; 017 018import org.kuali.rice.kew.util.Utilities; 019import org.kuali.rice.kim.api.KimConstants; 020 021/** 022 * A {@link GroupId} which identifies the name of a {@link Workgroup}. 023 * 024 * @see Workgroup 025 * 026 * @author Kuali Rice Team (rice.collab@kuali.org) 027 */ 028public final class GroupNameId implements GroupId { 029 030 private static final long serialVersionUID = -4625193242111678434L; 031 032 private String namespace = KimConstants.KIM_GROUP_DEFAULT_NAMESPACE_CODE; 033 private String nameId; 034 035 public GroupNameId(String nameId) { 036 this.nameId = nameId; 037 this.namespace = Utilities.parseGroupNamespaceCode(nameId); 038 this.nameId = Utilities.parseGroupName(nameId); 039 } 040 041 public GroupNameId(String namespace, String nameId) { 042 this.namespace = namespace; 043 this.nameId = nameId; 044 } 045 046 public String getNameId() { 047 return nameId; 048 } 049 050 public String getNamespace() { 051 return namespace; 052 } 053 054 public boolean isEmpty() { 055 return (nameId == null) || (nameId.trim().length() == 0); 056 } 057 058 /** 059 * If you make this class non-final, you must rewrite equals to work for subclasses. 060 */ 061 public boolean equals(Object obj) { 062 boolean isEqual = false; 063 064 if (obj != null && (obj instanceof GroupNameId)) { 065 GroupNameId w = (GroupNameId) obj; 066 067 if (w.getNameId() != null && getNameId() != null) { 068 return w.getNameId().equals(getNameId()) && w.getNamespace().equals(getNamespace()); 069 } else { 070 return false; 071 } 072 } 073 074 return isEqual; 075 } 076 077 public int hashCode() { 078 if (nameId == null) { 079 return 0; 080 } 081 return nameId.hashCode(); 082 } 083 084 public String toString() { 085 if (nameId != null) { 086 return nameId; 087 } 088 return "null"; 089 } 090 091}