View Javadoc

1   /*
2    * Copyright 2006-2007 the original author or authors.
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  
17  package net.sf.ezmorph.object;
18  
19  import net.sf.ezmorph.ObjectMorpher;
20  
21  /**
22   * Base class for ObjectMorpher implementations.
23   *
24   * @author Andres Almiray <aalmiray@users.sourceforge.net>
25   */
26  public abstract class AbstractObjectMorpher implements ObjectMorpher
27  {
28     private boolean useDefault;
29  
30     public AbstractObjectMorpher()
31     {
32  
33     }
34  
35     /**
36      * @param useDefault if morph() should return a default value if the value to
37      *        be morphed is null
38      */
39     public AbstractObjectMorpher( boolean useDefault )
40     {
41        this.useDefault = useDefault;
42     }
43  
44     /**
45      * Returns if this morpher will use a default value.
46      */
47     public boolean isUseDefault()
48     {
49        return useDefault;
50     }
51  
52     /**
53      * Sets if this morpher will use a default value.
54      */
55     public void setUseDefault( boolean useDefault )
56     {
57        this.useDefault = useDefault;
58     }
59  
60     /**
61      * Returns true if the Morpher supports conversion from this Class.<br>
62      * Supports any type that is not an Array.
63      *
64      * @param clazz the source Class
65      * @return true if clazz is supported by this morpher, false otherwise.
66      */
67     public boolean supports( Class clazz )
68     {
69        return !clazz.isArray();
70     }
71  }