View Javadoc
1   /*
2    * Copyright 2007 Keith Visco, Ralf Joachim
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    * 
7    * http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  package org.exolab.castor.builder.types;
15  
16  import org.exolab.castor.xml.schema.Facet;
17  import org.exolab.javasource.JClass;
18  import org.exolab.javasource.JSourceCode;
19  import org.exolab.javasource.JType;
20  
21  /**
22   * The XML Schema user-defined archetype.
23   * 
24   * @author <a href="mailto:keith AT kvisco DOT com">Keith Visco</a>
25   * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
26   * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
27   */
28  public final class XSClass extends XSType {
29    // --------------------------------------------------------------------------
30  
31    /** Type number of this XSType. */
32    public static final short TYPE = XSType.CLASS;
33  
34    // --------------------------------------------------------------------------
35  
36    /** Name of this type. */
37    private final String _name;
38  
39    /** The JClass represented by this type. */
40    private final JClass _jClass;
41  
42    // --------------------------------------------------------------------------
43  
44    /**
45     * Creates a new XSClass with the given JClass reference.
46     * 
47     * @param jClass The JClass type of this XSClass.
48     */
49    public XSClass(final JClass jClass) {
50      this(jClass, null);
51    }
52  
53    /**
54     * Creates a new XSClass with the given JClass reference.
55     * 
56     * @param jClass The JClass associated with this XSType.
57     * @param schemaTypeName The XML Schema type name.
58     */
59    public XSClass(final JClass jClass, final String schemaTypeName) {
60      super();
61  
62      _jClass = jClass;
63      if (schemaTypeName != null) {
64        _name = schemaTypeName;
65      } else {
66        _name = jClass.getName();
67      }
68    }
69  
70    // --------------------------------------------------------------------------
71  
72    /**
73     * {@inheritDoc}
74     */
75    public String getName() {
76      return _name;
77    }
78  
79    /**
80     * {@inheritDoc}
81     */
82    public short getType() {
83      return TYPE;
84    }
85  
86    /**
87     * {@inheritDoc}
88     */
89    public boolean isPrimitive() {
90      return false;
91    }
92  
93    /**
94     * {@inheritDoc}
95     */
96    public boolean isDateTime() {
97      return false;
98    }
99  
100   /**
101    * {@inheritDoc}
102    */
103   public JType getJType() {
104     return _jClass;
105   }
106 
107   /**
108    * {@inheritDoc}
109    */
110   public String newInstanceCode() {
111     return "new " + getJType().getName() + "();";
112   }
113 
114   /**
115    * {@inheritDoc}
116    */
117   public String createToJavaObjectCode(final String variableName) {
118     return variableName;
119   }
120 
121   /**
122    * {@inheritDoc}
123    */
124   public String createFromJavaObjectCode(final String variableName) {
125     return "(" + getJType().getName() + ") " + variableName;
126   }
127 
128   // --------------------------------------------------------------------------
129 
130   /**
131    * {@inheritDoc}
132    */
133   protected void setFacet(final Facet facet) {
134     // Not implemented
135   }
136 
137   /**
138    * {@inheritDoc}
139    */
140   public void validationCode(final JSourceCode jsc, final String fixedValue,
141       final String validatorInstanceName) {
142     // Not implemented
143   }
144 
145   // --------------------------------------------------------------------------
146 }