001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.om.impl;
018:
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Locale;
023:
024: import org.apache.jetspeed.om.common.MutableDescription;
025: import org.apache.jetspeed.om.common.SecurityRoleRefComposite;
026: import org.apache.jetspeed.util.HashCodeBuilder;
027: import org.apache.jetspeed.util.JetspeedLocale;
028: import org.apache.pluto.om.common.Description;
029: import org.apache.pluto.om.common.DescriptionSet;
030: import org.apache.pluto.om.common.SecurityRoleRef;
031:
032: /**
033: *
034: * SecurityRoleRefImpl
035: *
036: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
037: * @version $Id: SecurityRoleRefImpl.java 517124 2007-03-12 08:10:25Z ate $
038: *
039: */
040: public class SecurityRoleRefImpl implements SecurityRoleRefComposite,
041: Serializable {
042:
043: protected long id;
044: protected long portletId;
045: private String link;
046: private String name;
047: private Collection descriptions;
048: private DescriptionSetImpl descCollWrapper = new DescriptionSetImpl(
049: DescriptionImpl.TYPE_SEC_ROLE_REF);
050:
051: /**
052: * @see org.apache.pluto.om.common.SecurityRoleRef#getRoleLink()
053: */
054: public String getRoleLink() {
055: return link;
056: }
057:
058: /**
059: * @see org.apache.pluto.om.common.SecurityRoleRef#getRoleName()
060: */
061: public String getRoleName() {
062: return name;
063: }
064:
065: /**
066: * @see org.apache.pluto.om.common.SecurityRoleRefCtrl#setRoleLink(java.lang.String)
067: */
068: public void setRoleLink(String value) {
069: this .link = value;
070: }
071:
072: /**
073: * @see org.apache.pluto.om.common.SecurityRoleRefCtrl#setRoleName(java.lang.String)
074: */
075: public void setRoleName(String name) {
076: this .name = name;
077: }
078:
079: /**
080: * @see java.lang.Object#equals(java.lang.Object)
081: */
082: public boolean equals(Object obj) {
083: if (obj != null && obj instanceof SecurityRoleRef) {
084: SecurityRoleRef aRef = (SecurityRoleRef) obj;
085: //TODO: Because of a bug in OJB 1.0.rc4 fields seems not have been set
086: // before this object is put into a HashMap.
087: // Therefore, for the time being, check against null values is
088: // required.
089: // Once 1.0rc5 or higher can be used the following line should be
090: // used again.
091: //return this.getRoleName().equals(aRef.getRoleName());
092: return getRoleName() != null
093: && getRoleName().equals(aRef.getRoleName());
094: }
095:
096: return false;
097: }
098:
099: /**
100: * @see java.lang.Object#hashCode()
101: */
102: public int hashCode() {
103:
104: HashCodeBuilder hasher = new HashCodeBuilder(21, 81);
105: hasher.append(name);
106: return hasher.toHashCode();
107: }
108:
109: /**
110: * @see org.apache.pluto.om.common.SecurityRoleRef#getDescription(java.util.Locale)
111: */
112: public Description getDescription(Locale arg0) {
113: if (descriptions != null) {
114: descCollWrapper.setInnerCollection(descriptions);
115: return descCollWrapper.get(arg0);
116: }
117: return null;
118: }
119:
120: /**
121: * @see org.apache.jetspeed.om.common.SecurityRoleRefComposite#addDescription(org.apache.pluto.om.common.Description)
122: */
123: public void addDescription(Description description) {
124: if (descriptions == null) {
125: descriptions = new ArrayList();
126: }
127: descCollWrapper.setInnerCollection(descriptions);
128: descCollWrapper.addDescription(description);
129: }
130:
131: /**
132: * @see org.apache.jetspeed.om.common.MutableDescriptionSet#addDescription(java.util.Locale, java.lang.String)
133: */
134: public void addDescription(Locale locale, String description) {
135: SecurityRoleRefDescriptionImpl descImpl = new SecurityRoleRefDescriptionImpl();
136: descImpl.setDescription(description);
137: descImpl.setLocale(locale);
138:
139: addDescription(descImpl);
140: }
141:
142: /**
143: * @see org.apache.jetspeed.om.common.SecurityRoleRefComposite#setDescriptionSet(org.apache.pluto.om.common.DescriptionSet)
144: */
145: public void setDescriptionSet(DescriptionSet descriptions) {
146: this .descriptions = ((DescriptionSetImpl) descriptions)
147: .getInnerCollection();
148:
149: }
150:
151: /**
152: * We should be using one of the more locale-specific methods.
153: *
154: *
155: * @see org.apache.pluto.om.common.SecurityRoleRefCtrl#setDescription(java.lang.String)
156: * @param arg0
157: */
158: public void setDescription(String arg0) {
159: MutableDescription descObj = new SecurityRoleRefDescriptionImpl();
160:
161: descObj.setLocale(JetspeedLocale.getDefaultLocale());
162: descObj.setDescription(arg0);
163: addDescription(descObj);
164: }
165:
166: /**
167: * @see org.apache.jetspeed.om.common.SecurityRoleRefComposite#getDescriptionSet()
168: */
169: public DescriptionSet getDescriptionSet() {
170: if (descriptions != null) {
171: descCollWrapper.setInnerCollection(descriptions);
172: }
173: return descCollWrapper;
174: }
175: }
|