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