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:
037: package com.sun.tools.xjc.reader.xmlschema;
038:
039: import com.sun.tools.xjc.model.CClassInfo;
040: import com.sun.tools.xjc.model.CDefaultValue;
041: import com.sun.tools.xjc.model.CPropertyInfo;
042: import com.sun.tools.xjc.model.TypeUse;
043: import com.sun.tools.xjc.model.CClass;
044: import com.sun.tools.xjc.reader.Ring;
045: import com.sun.tools.xjc.reader.xmlschema.bindinfo.BIProperty;
046: import com.sun.xml.xsom.XSAttGroupDecl;
047: import com.sun.xml.xsom.XSAttributeDecl;
048: import com.sun.xml.xsom.XSAttributeUse;
049: import com.sun.xml.xsom.XSComplexType;
050: import com.sun.xml.xsom.XSContentType;
051: import com.sun.xml.xsom.XSElementDecl;
052: import com.sun.xml.xsom.XSModelGroup;
053: import com.sun.xml.xsom.XSModelGroupDecl;
054: import com.sun.xml.xsom.XSParticle;
055: import com.sun.xml.xsom.XSSimpleType;
056: import com.sun.xml.xsom.XSWildcard;
057:
058: /**
059: * @author Kohsuke Kawaguchi
060: */
061: public class BindPurple extends ColorBinder {
062: public void attGroupDecl(XSAttGroupDecl xsAttGroupDecl) {
063: // TODO
064: throw new UnsupportedOperationException();
065: }
066:
067: public void attributeDecl(XSAttributeDecl xsAttributeDecl) {
068: // TODO
069: throw new UnsupportedOperationException();
070: }
071:
072: /**
073: * Attribute use always becomes a property.
074: */
075: public void attributeUse(XSAttributeUse use) {
076: boolean hasFixedValue = use.getFixedValue() != null;
077: BIProperty pc = BIProperty.getCustomization(use);
078:
079: // map to a constant property ?
080: boolean toConstant = pc.isConstantProperty() && hasFixedValue;
081: TypeUse attType = bindAttDecl(use.getDecl());
082:
083: CPropertyInfo prop = pc.createAttributeProperty(use, attType);
084:
085: if (toConstant) {
086: prop.defaultValue = CDefaultValue.create(attType, use
087: .getFixedValue());
088: prop.realization = builder.fieldRendererFactory
089: .getConst(prop.realization);
090: } else if (!attType.isCollection()) {
091: // don't support a collection default value. That's difficult to do.
092:
093: if (use.getDefaultValue() != null) {
094: // this attribute use has a default value.
095: // the item type is guaranteed to be a leaf type... or TODO: is it really so?
096: // don't support default values if it's a list
097: prop.defaultValue = CDefaultValue.create(attType, use
098: .getDefaultValue());
099: } else if (use.getFixedValue() != null) {
100: prop.defaultValue = CDefaultValue.create(attType, use
101: .getFixedValue());
102: }
103: }
104:
105: getCurrentBean().addProperty(prop);
106: }
107:
108: private TypeUse bindAttDecl(XSAttributeDecl decl) {
109: SimpleTypeBuilder stb = Ring.get(SimpleTypeBuilder.class);
110: stb.refererStack.push(decl);
111: try {
112: return stb.build(decl.getType());
113: } finally {
114: stb.refererStack.pop();
115: }
116: }
117:
118: public void complexType(XSComplexType ct) {
119: CClass ctBean = selector.bindToType(ct, null, false);
120: if (getCurrentBean() != ctBean)
121: // in some case complex type and element binds to the same class
122: // don't make it has-a. Just make it is-a.
123: getCurrentBean().setBaseClass(ctBean);
124: }
125:
126: public void wildcard(XSWildcard xsWildcard) {
127: // element wildcards are processed by particle binders,
128: // so this one is for attribute wildcard.
129:
130: getCurrentBean().hasAttributeWildcard(true);
131: }
132:
133: public void modelGroupDecl(XSModelGroupDecl xsModelGroupDecl) {
134: // TODO
135: throw new UnsupportedOperationException();
136: }
137:
138: public void modelGroup(XSModelGroup xsModelGroup) {
139: // TODO
140: throw new UnsupportedOperationException();
141: }
142:
143: public void elementDecl(XSElementDecl xsElementDecl) {
144: // TODO
145: throw new UnsupportedOperationException();
146: }
147:
148: public void simpleType(XSSimpleType type) {
149: createSimpleTypeProperty(type, "Value");
150: }
151:
152: public void particle(XSParticle xsParticle) {
153: // TODO
154: throw new UnsupportedOperationException();
155: }
156:
157: public void empty(XSContentType ct) {
158: // empty generates nothing
159: }
160: }
|