001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.tools.xjc.reader.xmlschema.bindinfo;
037:
038: import javax.xml.bind.annotation.XmlAttribute;
039: import javax.xml.bind.annotation.XmlElement;
040: import javax.xml.bind.annotation.XmlRootElement;
041: import javax.xml.bind.annotation.XmlType;
042: import javax.xml.namespace.QName;
043:
044: import com.sun.tools.xjc.reader.Const;
045: import com.sun.xml.xsom.XSAttributeDecl;
046: import com.sun.xml.xsom.XSComponent;
047: import com.sun.xml.xsom.XSElementDecl;
048: import com.sun.xml.xsom.XSModelGroup;
049: import com.sun.xml.xsom.XSModelGroupDecl;
050: import com.sun.xml.xsom.XSType;
051:
052: /**
053: * Schema-wide binding customization.
054: *
055: * @author
056: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
057: */
058: @XmlRootElement(name="schemaBindings")
059: public final class BISchemaBinding extends AbstractDeclarationImpl {
060:
061: /**
062: * Name conversion rules. All defaults to {@link BISchemaBinding#defaultNamingRule}.
063: */
064: @XmlType(propOrder={})
065: private static final class NameRules {
066: @XmlElement
067: NamingRule typeName = defaultNamingRule;
068: @XmlElement
069: NamingRule elementName = defaultNamingRule;
070: @XmlElement
071: NamingRule attributeName = defaultNamingRule;
072: @XmlElement
073: NamingRule modelGroupName = defaultNamingRule;
074: @XmlElement
075: NamingRule anonymousTypeName = defaultNamingRule;
076: }
077:
078: @XmlElement
079: private NameRules nameXmlTransform = new NameRules();
080:
081: private static final class PackageInfo {
082: @XmlAttribute
083: String name;
084: @XmlElement
085: String javadoc;
086: }
087:
088: @XmlElement(name="package")
089: private PackageInfo packageInfo = new PackageInfo();
090:
091: /**
092: * If false, it means not to generate any classes from this namespace.
093: * No ObjectFactory, no classes (the only way to bind them is by using
094: * <jaxb:class ref="..."/>)
095: */
096: @XmlAttribute(name="map")
097: public boolean map = true;
098:
099: /**
100: * Default naming rule, that doesn't change the name.
101: */
102: private static final NamingRule defaultNamingRule = new NamingRule(
103: "", "");
104:
105: /**
106: * Default naming rules of the generated interfaces.
107: *
108: * It simply adds prefix and suffix to the name, but
109: * the caller shouldn't care how the name mangling is
110: * done.
111: */
112: public static final class NamingRule {
113: @XmlAttribute
114: private String prefix = "";
115: @XmlAttribute
116: private String suffix = "";
117:
118: public NamingRule(String _prefix, String _suffix) {
119: this .prefix = _prefix;
120: this .suffix = _suffix;
121: }
122:
123: public NamingRule() {
124: }
125:
126: /** Changes the name according to the rule. */
127: public String mangle(String originalName) {
128: return prefix + originalName + suffix;
129: }
130: }
131:
132: /**
133: * Transforms the default name produced from XML name
134: * by following the customization.
135: *
136: * This shouldn't be applied to a class name specified
137: * by a customization.
138: *
139: * @param cmp
140: * The schema component from which the default name is derived.
141: */
142: public String mangleClassName(String name, XSComponent cmp) {
143: if (cmp instanceof XSType)
144: return nameXmlTransform.typeName.mangle(name);
145: if (cmp instanceof XSElementDecl)
146: return nameXmlTransform.elementName.mangle(name);
147: if (cmp instanceof XSAttributeDecl)
148: return nameXmlTransform.attributeName.mangle(name);
149: if (cmp instanceof XSModelGroup
150: || cmp instanceof XSModelGroupDecl)
151: return nameXmlTransform.modelGroupName.mangle(name);
152:
153: // otherwise no modification
154: return name;
155: }
156:
157: public String mangleAnonymousTypeClassName(String name) {
158: return nameXmlTransform.anonymousTypeName.mangle(name);
159: }
160:
161: public String getPackageName() {
162: return packageInfo.name;
163: }
164:
165: public String getJavadoc() {
166: return packageInfo.javadoc;
167: }
168:
169: public QName getName() {
170: return NAME;
171: }
172:
173: public static final QName NAME = new QName(Const.JAXB_NSURI,
174: "schemaBinding");
175: }
|