View Javadoc

1   /*
2    * Copyright 2004 Carlos Sanchez.
3    *
4    * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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 net.sf.oness.common.webapp.controller.util;
17  
18  import java.util.HashSet;
19  import java.util.Set;
20  
21  import net.sf.oness.common.model.auditing.Auditable;
22  
23  import org.apache.commons.beanutils.Converter;
24  
25  /***
26   * Given a string array, converts it into an Auditable array with ids equal
27   * to that strings.
28   * 
29   * @deprecated
30   * 
31   * @author Carlos Sanchez
32   * @version $Revision: 1.2 $
33   */
34  public class StringArrayToAuditableConverter implements Converter {
35  
36      private Auditable auditableValue;
37  
38      /***
39       * 
40       * @param auditableValue
41       *            an object of the destination class
42       */
43      public StringArrayToAuditableConverter(Auditable auditableValue) {
44          this.auditableValue = auditableValue;
45      }
46  
47      /***
48       * @return a Set with <code>Auditable</code> objects cloned from the
49       *         provided at creation time with ids set to values or null if value
50       *         has zero length
51       * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class,
52       *      java.lang.Object)
53       */
54      public Object convert(Class type, Object value) {
55          String values[] = (String[]) value;
56          if (values.length == 0)
57              return null;
58          Set auditableValues = new HashSet(values.length);
59          for (int i = 0; i < values.length; i++) {
60              Auditable av = (Auditable) auditableValue.clone();
61              av.setId(new Long(values[i]));
62              auditableValues.add(av);
63          }
64          return auditableValues;
65      }
66  
67  }