View Javadoc
1   /**
2    * Redistribution and use of this software and associated documentation ("Software"), with or
3    * without modification, are permitted provided that the following conditions are met:
4    *
5    * 1. Redistributions of source code must retain copyright statements and notices. Redistributions
6    * must also contain a copy of this document.
7    *
8    * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
9    * conditions and the following disclaimer in the documentation and/or other materials provided with
10   * the distribution.
11   *
12   * 3. The name "Exolab" must not be used to endorse or promote products derived from this Software
13   * without prior written permission of Intalio, Inc. For written permission, please contact
14   * info@exolab.org.
15   *
16   * 4. Products derived from this Software may not be called "Exolab" nor may "Exolab" appear in
17   * their names without prior written permission of Intalio, Inc. Exolab is a registered trademark of
18   * Intalio, Inc.
19   *
20   * 5. Due credit should be given to the Exolab Project (http://www.exolab.org/).
21   *
22   * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR
23   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
24   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTALIO, INC. OR ITS
25   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
29   * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30   *
31   * Copyright 1999-2000 (C) Intalio Inc. All Rights Reserved.
32   *
33   * $Id$
34   */
35  
36  package org.exolab.castor.xml.schema.simpletypes.factory;
37  
38  import java.util.Vector;
39  import java.io.PrintWriter;
40  
41  import org.exolab.castor.xml.schema.SimpleType;
42  
43  /**
44   * Stores information about an xml built in type.
45   *
46   */
47  public class Type {
48    /**
49     * The name of the built in type
50     */
51    private String name = null;
52  
53    /**
54     * The code of the built in type (name of the corresponding field in SimpleTypesFactory)
55     */
56    private String code = null;
57  
58    /**
59     * The name of the base type (null for primitive types)
60     */
61    private String base = null;
62  
63    /**
64     * The name of the implementing class (in org.exolab.castor.xml.schema.simpletypes)
65     */
66    private String impl = null;
67  
68    /**
69     * The name of the derivation method.
70     */
71    private String derivedBy = null;
72  
73    /**
74     * The class used to represent this type
75     */
76    private Class implClass = null;
77  
78    /**
79     * The instance representing this type
80     */
81    private SimpleType simpleType = null;
82  
83    /**
84     * This type's properties ("facet" like) Vector<TypeProperty>
85     */
86    private final Vector<TypeProperty> facet = new Vector<>(15);
87  
88    public String getName() {
89      return name;
90    }
91  
92    public String getCode() {
93      return code;
94    }
95  
96    public String getBase() {
97      return base;
98    }
99  
100   public String getImpl() {
101     return impl;
102   }
103 
104   public String getDerivedBy() {
105     return derivedBy;
106   }
107 
108   public Vector<TypeProperty> getFacet() {
109     return facet;
110   }
111 
112   public Class getImplClass() {
113     return implClass;
114   }
115 
116   public SimpleType getSimpleType() {
117     return simpleType;
118   }
119 
120 
121   public void setName(String name) {
122     this.name = name;
123   }
124 
125   public void setCode(String code) {
126     this.code = code;
127   }
128 
129   public void setBase(String base) {
130     this.base = base;
131   }
132 
133   public void setDerivedBy(String derivedBy) {
134     this.derivedBy = derivedBy;
135   }
136 
137   public void setSimpleType(SimpleType simpleType) {
138     this.simpleType = simpleType;
139   }
140 
141   /**
142    * Sets the implementing class name and tries to create the corresponding class in the package
143    * org.exolab.castor.xml.schema.simpletypes
144    */
145   public void setImpl(String impl) {
146     this.impl = impl;
147     try {
148       String fullName = "org.exolab.castor.xml.schema.simpletypes." + impl;
149       implClass = Class.forName(fullName);
150     } catch (Exception e) {
151       implClass = null;
152     }
153   }
154 
155   /**
156    * Prints this instance's content
157    */
158   public void Print(PrintWriter output) {
159     output.println("name: " + name + " code: " + code + " base: " + base + " impl: " + impl
160         + " derivedBy: " + derivedBy);
161     output.println("Facets count: " + facet.size());
162 
163     for (int index = 0; index < facet.size(); index++) {
164       ((TypeProperty) (facet.elementAt(index))).Print(output);
165     }
166     output.println();
167   }
168 
169   /**
170    * To generate a {@link String} representing this class instance.
171    * 
172    * @see java.lang.Object#toString()
173    */
174   public String toString() {
175     StringBuilder sb = new StringBuilder().append("name: ").append(name).append(" code: ")
176         .append(code).append(" base: ").append(base).append(" impl: ").append(impl)
177         .append(" derivedBy: ").append(derivedBy).append('\n').append("Facets count: ")
178         .append(facet.size()).append('\n');
179     for (TypeProperty tp : facet) {
180       sb.append(tp);
181     }
182     sb.append('\n');
183     return sb.toString();
184   }
185 }