View Javadoc
1   /*
2    * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.  Oracle designates this
8    * particular file as subject to the "Classpath" exception as provided
9    * by Oracle in the LICENSE file that accompanied this code.
10   *
11   * This code is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   * version 2 for more details (a copy is included in the LICENSE file that
15   * accompanied this code).
16   *
17   * You should have received a copy of the GNU General Public License version
18   * 2 along with this work; if not, write to the Free Software Foundation,
19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20   *
21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22   * or visit www.oracle.com if you need additional information or have any
23   * questions.
24   */
25  
26  package com.sun.tools.internal.xjc.reader.xmlschema.bindinfo;
27  
28  import javax.xml.bind.annotation.XmlAttribute;
29  import javax.xml.bind.annotation.XmlElement;
30  import javax.xml.bind.annotation.XmlRootElement;
31  import javax.xml.namespace.QName;
32  
33  import com.sun.tools.internal.xjc.reader.Const;
34  import com.sun.xml.internal.bind.api.impl.NameConverter;
35  import com.sun.istack.internal.Nullable;
36  
37  /**
38   * Class declaration.
39   *
40   * This customization turns arbitrary schema component into a Java
41   * content interface.
42   *
43   * <p>
44   * This customization is acknowledged by the ClassSelector.
45   *
46   * @author
47   *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
48   */
49  @XmlRootElement(name="class")
50  public final class BIClass extends AbstractDeclarationImpl {
51      protected BIClass() {
52      }
53  
54      @XmlAttribute(name="name")
55      private String className;
56  
57      /**
58       * Gets the specified class name, or null if not specified.
59       * (Not a fully qualified name.)
60       *
61       * @return
62       *      Returns a class name. The caller should <em>NOT</em>
63       *      apply XML-to-Java name conversion to the name
64       *      returned from this method.
65       */
66      public @Nullable String getClassName() {
67          if( className==null )   return null;
68  
69          BIGlobalBinding gb = getBuilder().getGlobalBinding();
70          NameConverter nc = getBuilder().model.getNameConverter();
71  
72          if(gb.isJavaNamingConventionEnabled()) return nc.toClassName(className);
73          else
74              // don't change it
75              return className;
76      }
77  
78      @XmlAttribute(name="implClass")
79      private String userSpecifiedImplClass;
80  
81      /**
82       * Gets the fully qualified name of the
83       * user-specified implementation class, if any.
84       * Or null.
85       */
86      public String getUserSpecifiedImplClass() {
87          return userSpecifiedImplClass;
88      }
89  
90      @XmlAttribute(name="ref")
91      private String ref;
92  
93      @XmlAttribute(name="recursive", namespace=Const.XJC_EXTENSION_URI)
94      private String recursive;
95  
96      /**
97       * Reference to the existing class, or null.
98       * Fully qualified name.
99       *
100      * <p>
101      * Caller needs to perform error check on this.
102      */
103     public String getExistingClassRef() {
104         return ref;
105     }
106 
107     public String getRecursive() {
108         return recursive;
109     }
110 
111     @XmlElement
112     private String javadoc;
113     /**
114      * Gets the javadoc comment specified in the customization.
115      * Can be null if none is specified.
116      */
117     public String getJavadoc() { return javadoc; }
118 
119     public QName getName() { return NAME; }
120 
121     public void setParent(BindInfo p) {
122         super.setParent(p);
123         // if this specifies a reference to external class,
124         // then it's OK even if noone actually refers this class.
125         if(ref!=null)
126             markAsAcknowledged();
127     }
128 
129     /** Name of this declaration. */
130     public static final QName NAME = new QName( Const.JAXB_NSURI, "class" );
131 }