View Javadoc
1   /*
2    * Copyright 2007 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.javasource.JArrayType;
17  import org.exolab.javasource.JSourceCode;
18  import org.exolab.javasource.JType;
19  
20  /**
21   * The xsd:hexBinary XML Schema datatype.
22   * 
23   * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
24   * @version $Revision: 6623 $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $
25   * @since 1.1
26   */
27  public final class XSHexBinary extends AbstractLengthFacet {
28    // --------------------------------------------------------------------------
29  
30    /** Name of this XSType. */
31    public static final String NAME = "hexBinary";
32  
33    /** Type number of this XSType. */
34    public static final short TYPE = XSType.HEXBINARY_TYPE;
35  
36    // --------------------------------------------------------------------------
37  
38    /** The JType represented by this XSType. */
39    private final JType _jType;
40  
41    // --------------------------------------------------------------------------
42  
43    /**
44     * Create a new XSHexBinary object.
45     *
46     * @param useJava50 If true, Java 5 code artifacts will be generated.
47     */
48    public XSHexBinary(final boolean useJava50) {
49      super();
50  
51      _jType = new JArrayType(JType.BYTE, useJava50);
52    }
53  
54    // --------------------------------------------------------------------------
55  
56    /**
57     * {@inheritDoc}
58     */
59    public String getName() {
60      return NAME;
61    }
62  
63    /**
64     * {@inheritDoc}
65     */
66    public short getType() {
67      return TYPE;
68    }
69  
70    /**
71     * {@inheritDoc}
72     */
73    public boolean isPrimitive() {
74      return false;
75    }
76  
77    /**
78     * {@inheritDoc}
79     */
80    public boolean isDateTime() {
81      return false;
82    }
83  
84    /**
85     * {@inheritDoc}
86     */
87    public JType getJType() {
88      return _jType;
89    }
90  
91    /**
92     * {@inheritDoc}
93     */
94    public String newInstanceCode() {
95      return "new byte[] {};";
96    }
97  
98    /**
99     * {@inheritDoc}
100    */
101   public String createToJavaObjectCode(final String variableName) {
102     return variableName;
103   }
104 
105   /**
106    * {@inheritDoc}
107    */
108   public String createFromJavaObjectCode(final String variableName) {
109     return "(" + getJType().toString() + ") " + variableName;
110   }
111 
112   // --------------------------------------------------------------------------
113 
114   /**
115    * {@inheritDoc}
116    */
117   public void validationCode(final JSourceCode jsc, final String fixedValue,
118       final String validatorInstanceName) {
119     // Not implemented
120   }
121 
122   // --------------------------------------------------------------------------
123 }