001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.internal.xjc.reader.xmlschema.bindinfo;
027:
028: import javax.xml.bind.annotation.XmlAttribute;
029: import javax.xml.bind.annotation.XmlElement;
030: import javax.xml.bind.annotation.XmlRootElement;
031: import javax.xml.bind.annotation.XmlType;
032: import javax.xml.namespace.QName;
033:
034: import com.sun.tools.internal.xjc.reader.Const;
035: import com.sun.xml.internal.xsom.XSAttributeDecl;
036: import com.sun.xml.internal.xsom.XSComponent;
037: import com.sun.xml.internal.xsom.XSElementDecl;
038: import com.sun.xml.internal.xsom.XSModelGroup;
039: import com.sun.xml.internal.xsom.XSModelGroupDecl;
040: import com.sun.xml.internal.xsom.XSType;
041:
042: /**
043: * Schema-wide binding customization.
044: *
045: * @author
046: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
047: */
048: @XmlRootElement(name="schemaBindings")
049: public final class BISchemaBinding extends AbstractDeclarationImpl {
050:
051: /**
052: * Name conversion rules. All defaults to {@link BISchemaBinding#defaultNamingRule}.
053: */
054: @XmlType(propOrder={})
055: private static final class NameRules {
056: @XmlElement
057: NamingRule typeName = defaultNamingRule;
058: @XmlElement
059: NamingRule elementName = defaultNamingRule;
060: @XmlElement
061: NamingRule attributeName = defaultNamingRule;
062: @XmlElement
063: NamingRule modelGroupName = defaultNamingRule;
064: @XmlElement
065: NamingRule anonymousTypeName = defaultNamingRule;
066: }
067:
068: @XmlElement
069: private NameRules nameXmlTransform = new NameRules();
070:
071: private static final class PackageInfo {
072: @XmlAttribute
073: String name;
074: @XmlElement
075: String javadoc;
076: }
077:
078: @XmlElement(name="package")
079: private PackageInfo packageInfo = new PackageInfo();
080:
081: /**
082: * Default naming rule, that doesn't change the name.
083: */
084: private static final NamingRule defaultNamingRule = new NamingRule(
085: "", "");
086:
087: /**
088: * Default naming rules of the generated interfaces.
089: *
090: * It simply adds prefix and suffix to the name, but
091: * the caller shouldn't care how the name mangling is
092: * done.
093: */
094: public static final class NamingRule {
095: @XmlAttribute
096: private String prefix = "";
097: @XmlAttribute
098: private String suffix = "";
099:
100: public NamingRule(String _prefix, String _suffix) {
101: this .prefix = _prefix;
102: this .suffix = _suffix;
103: }
104:
105: public NamingRule() {
106: }
107:
108: /** Changes the name according to the rule. */
109: public String mangle(String originalName) {
110: return prefix + originalName + suffix;
111: }
112: }
113:
114: /**
115: * Transforms the default name produced from XML name
116: * by following the customization.
117: *
118: * This shouldn't be applied to a class name specified
119: * by a customization.
120: *
121: * @param cmp
122: * The schema component from which the default name is derived.
123: */
124: public String mangleClassName(String name, XSComponent cmp) {
125: if (cmp instanceof XSType)
126: return nameXmlTransform.typeName.mangle(name);
127: if (cmp instanceof XSElementDecl)
128: return nameXmlTransform.elementName.mangle(name);
129: if (cmp instanceof XSAttributeDecl)
130: return nameXmlTransform.attributeName.mangle(name);
131: if (cmp instanceof XSModelGroup
132: || cmp instanceof XSModelGroupDecl)
133: return nameXmlTransform.modelGroupName.mangle(name);
134:
135: // otherwise no modification
136: return name;
137: }
138:
139: public String mangleAnonymousTypeClassName(String name) {
140: return nameXmlTransform.anonymousTypeName.mangle(name);
141: }
142:
143: public String getPackageName() {
144: return packageInfo.name;
145: }
146:
147: public String getJavadoc() {
148: return packageInfo.javadoc;
149: }
150:
151: public QName getName() {
152: return NAME;
153: }
154:
155: public static final QName NAME = new QName(Const.JAXB_NSURI,
156: "schemaBinding");
157: }
|