001: /*
002: * Copyright 2007 Keith Visco, Ralf Joachim
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package org.exolab.castor.builder.types;
017:
018: import org.exolab.castor.xml.schema.Facet;
019: import org.exolab.javasource.JClass;
020: import org.exolab.javasource.JSourceCode;
021: import org.exolab.javasource.JType;
022:
023: /**
024: * The XML Schema user-defined archetype.
025: *
026: * @author <a href="mailto:keith AT kvisco DOT com">Keith Visco</a>
027: * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
028: * @version $Revision: 6907 $ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
029: */
030: public final class XSClass extends XSType {
031: //--------------------------------------------------------------------------
032:
033: /** Type number of this XSType. */
034: public static final short TYPE = XSType.CLASS;
035:
036: //--------------------------------------------------------------------------
037:
038: /** Name of this type. */
039: private final String _name;
040:
041: /** The JClass represented by this type. */
042: private final JClass _jClass;
043:
044: //--------------------------------------------------------------------------
045:
046: /**
047: * Creates a new XSClass with the given JClass reference.
048: *
049: * @param jClass The JClass type of this XSClass.
050: */
051: public XSClass(final JClass jClass) {
052: this (jClass, null);
053: }
054:
055: /**
056: * Creates a new XSClass with the given JClass reference.
057: *
058: * @param jClass The JClass associated with this XSType.
059: * @param schemaTypeName The XML Schema type name.
060: */
061: public XSClass(final JClass jClass, final String schemaTypeName) {
062: super ();
063:
064: _jClass = jClass;
065: if (schemaTypeName != null) {
066: _name = schemaTypeName;
067: } else {
068: _name = jClass.getName();
069: }
070: }
071:
072: //--------------------------------------------------------------------------
073:
074: /**
075: * {@inheritDoc}
076: */
077: public String getName() {
078: return _name;
079: }
080:
081: /**
082: * {@inheritDoc}
083: */
084: public short getType() {
085: return TYPE;
086: }
087:
088: /**
089: * {@inheritDoc}
090: */
091: public boolean isPrimitive() {
092: return false;
093: }
094:
095: /**
096: * {@inheritDoc}
097: */
098: public boolean isDateTime() {
099: return false;
100: }
101:
102: /**
103: * {@inheritDoc}
104: */
105: public JType getJType() {
106: return _jClass;
107: }
108:
109: /**
110: * {@inheritDoc}
111: */
112: public String newInstanceCode() {
113: return "new " + getJType().getName() + "();";
114: }
115:
116: /**
117: * {@inheritDoc}
118: */
119: public String createToJavaObjectCode(final String variableName) {
120: return variableName;
121: }
122:
123: /**
124: * {@inheritDoc}
125: */
126: public String createFromJavaObjectCode(final String variableName) {
127: return "(" + getJType().getName() + ") " + variableName;
128: }
129:
130: //--------------------------------------------------------------------------
131:
132: /**
133: * {@inheritDoc}
134: */
135: protected void setFacet(final Facet facet) {
136: // Not implemented
137: }
138:
139: /**
140: * {@inheritDoc}
141: */
142: public void validationCode(final JSourceCode jsc,
143: final String fixedValue, final String validatorInstanceName) {
144: // Not implemented
145: }
146:
147: //--------------------------------------------------------------------------
148: }
|