View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.jetspeed.om.impl;
19  
20  import java.io.Serializable;
21  import java.util.ArrayList;
22  import java.util.Collection;
23  import java.util.Locale;
24  
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  import org.apache.jetspeed.om.common.MutableDescription;
28  import org.apache.jetspeed.om.common.ParameterComposite;
29  import org.apache.jetspeed.util.HashCodeBuilder;
30  import org.apache.jetspeed.util.JetspeedLocale;
31  import org.apache.pluto.om.common.Description;
32  import org.apache.pluto.om.common.DescriptionSet;
33  
34  
35  /***
36   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
37   */
38  public class ParameterImpl implements ParameterComposite, Serializable
39  {
40  
41      private String name;
42      private String value;
43      private String description;
44  
45      protected long parameterId;
46  
47      protected long parentId;
48  
49      private Collection descriptions;
50      private DescriptionSetImpl descCollWrapper = new DescriptionSetImpl(DescriptionImpl.TYPE_PARAMETER);
51      
52      private static final Log log = LogFactory.getLog(ParameterImpl.class);
53  
54      /***
55       * @see org.apache.pluto.om.common.Parameter#getName()
56       */
57      public String getName()
58      {
59          return name;
60      }
61  
62      /***
63       * @see org.apache.pluto.om.common.Parameter#getValue()
64       */
65      public String getValue()
66      {
67          return value;
68      }
69  
70      /***
71       * @see org.apache.pluto.om.common.ParameterCtrl#setName(java.lang.String)
72       */
73      public void setName(String name)
74      {
75          this.name = name;
76  
77      }
78  
79      /***
80       * @see org.apache.pluto.om.common.ParameterCtrl#setValue(java.lang.String)
81       */
82      public void setValue(String value)
83      {
84          this.value = value;
85  
86      }
87  
88      /***
89       * @see java.lang.Object#equals(java.lang.Object)
90       */
91      public boolean equals(Object obj)
92      {
93          if (obj != null && obj.getClass().equals(getClass()))
94          {
95              ParameterImpl p = (ParameterImpl) obj;            
96              boolean sameParent = (p.parentId == parentId);
97              boolean sameName  = (name != null && p.getName() != null && name.equals(p.getName()));
98              return sameParent && sameName;            
99          }
100 
101         return false;
102 
103     }
104 
105     /***
106      * @see java.lang.Object#hashCode()
107      */
108     public int hashCode()
109     {
110         HashCodeBuilder hash = new HashCodeBuilder(17, 77);
111         return hash.append(name).toHashCode();
112     }
113 
114     /***
115      * @see org.apache.pluto.om.common.Parameter#getDescription(java.util.Locale)
116      */
117     public Description getDescription(Locale arg0)
118     {
119         if (descriptions != null)
120         {
121             return new DescriptionSetImpl(descriptions).get(arg0);
122         }
123         return null;
124 
125     }
126 
127     /***
128      * @see org.apache.pluto.om.common.ParameterCtrl#setDescriptionSet(org.apache.pluto.om.common.DescriptionSet)
129      */
130     public void setDescriptionSet(DescriptionSet arg0)
131     {
132         this.descriptions = ((DescriptionSetImpl) arg0).getInnerCollection();
133     }
134 
135     /***
136      * @see org.apache.jetspeed.om.common.ParameterComposite#addDescription(java.util.Locale, java.lang.String)
137      */
138     public void addDescription(Locale locale, String desc)
139     {
140         if (descriptions == null)
141         {
142 			descriptions = new ArrayList();
143         }
144         descCollWrapper.setInnerCollection(descriptions);
145         try
146         {
147             MutableDescription descObj = new ParameterDescriptionImpl();
148                 
149 			descObj.setLocale(locale);
150 			descObj.setDescription(desc);
151 			descCollWrapper.addDescription(descObj);
152         }
153         catch (Exception e)
154         {
155             String msg = "Unable to instantiate Description implementor, " + e.toString();
156             log.error(msg, e);
157             throw new IllegalStateException(msg);
158         }
159 
160     }
161 
162     public void addDescription(Description desc)
163     {
164         if (descriptions == null)
165         {
166             descriptions = new ArrayList();
167         }
168 
169         descCollWrapper.setInnerCollection(descriptions);
170         descCollWrapper.addDescription(desc);
171     }
172 
173     /***
174      * Remove when Castor is mapped correctly
175      * 
176      * @deprecated
177      * @param desc
178      */
179     public void setDescription(String desc)
180     {
181 //        System.out.println("Setting description..." + desc);
182         addDescription(JetspeedLocale.getDefaultLocale(), desc);
183 //        System.out.println("Description Set " + desc);
184     }
185 
186     /***
187      *  Remove when Castor is mapped correctly
188      * @deprecated
189      * @return
190      */
191     public String getDescription()
192     {
193 
194         Description desc = getDescription(JetspeedLocale.getDefaultLocale());
195 
196         if (desc != null)
197         {
198             return desc.getDescription();
199         }
200 
201         return null;
202     }
203 
204     /***
205      * @see org.apache.jetspeed.om.common.ParameterComposite#getDescriptionSet()
206      */
207     public DescriptionSet getDescriptionSet()
208     {
209         if (descriptions != null)
210         {
211             descCollWrapper.setInnerCollection(descriptions);
212         }        
213         return descCollWrapper;
214     }
215 
216 }