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 net.sf.oness.common.model.auditing.Auditable;
19  
20  import org.apache.commons.beanutils.Converter;
21  
22  /***
23   * Given a string, converts it into an Auditable with id equal to that
24   * string.
25   * 
26   * @deprecated
27   * 
28   * @author Carlos Sanchez
29   * @version $Revision: 1.2 $
30   */
31  public class StringToAuditableConverter implements Converter {
32  
33      private Auditable auditableValue;
34  
35      /***
36       * 
37       * @param auditableValue
38       *            an object of the destination class
39       */
40      public StringToAuditableConverter(Auditable auditableValue) {
41          this.auditableValue = auditableValue;
42      }
43  
44      /***
45       * @return an <code>Auditable</code> object cloned from the provided
46       *         at creation time with id set to value or null if value can't be
47       *         parsed as a Long
48       * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class,
49       *      java.lang.Object)
50       */
51      public Object convert(Class type, Object value) {
52          try {
53              Long id = new Long(value.toString());
54              Auditable av = (Auditable) auditableValue.clone();
55              av.setId(id);
56              return av;
57          } catch (NumberFormatException e) {
58              return null;
59          }
60      }
61  
62  }