src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/xmlschema/BindPurple.java

changeset 0
373ffda63c9a
equal deleted inserted replaced
-1:000000000000 0:373ffda63c9a
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;
27
28 import com.sun.tools.internal.xjc.model.CClassInfo;
29 import com.sun.tools.internal.xjc.model.CDefaultValue;
30 import com.sun.tools.internal.xjc.model.CPropertyInfo;
31 import com.sun.tools.internal.xjc.model.TypeUse;
32 import com.sun.tools.internal.xjc.model.CClass;
33 import com.sun.tools.internal.xjc.reader.Ring;
34 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIProperty;
35 import com.sun.xml.internal.xsom.XSAttGroupDecl;
36 import com.sun.xml.internal.xsom.XSAttributeDecl;
37 import com.sun.xml.internal.xsom.XSAttributeUse;
38 import com.sun.xml.internal.xsom.XSComplexType;
39 import com.sun.xml.internal.xsom.XSContentType;
40 import com.sun.xml.internal.xsom.XSElementDecl;
41 import com.sun.xml.internal.xsom.XSModelGroup;
42 import com.sun.xml.internal.xsom.XSModelGroupDecl;
43 import com.sun.xml.internal.xsom.XSParticle;
44 import com.sun.xml.internal.xsom.XSSimpleType;
45 import com.sun.xml.internal.xsom.XSWildcard;
46
47 /**
48 * @author Kohsuke Kawaguchi
49 */
50 public class BindPurple extends ColorBinder {
51 public void attGroupDecl(XSAttGroupDecl xsAttGroupDecl) {
52 // TODO
53 throw new UnsupportedOperationException();
54 }
55
56 public void attributeDecl(XSAttributeDecl xsAttributeDecl) {
57 // TODO
58 throw new UnsupportedOperationException();
59 }
60
61 /**
62 * Attribute use always becomes a property.
63 */
64 public void attributeUse(XSAttributeUse use) {
65 boolean hasFixedValue = use.getFixedValue()!=null;
66 BIProperty pc = BIProperty.getCustomization(use);
67
68 // map to a constant property ?
69 boolean toConstant = pc.isConstantProperty() && hasFixedValue;
70 TypeUse attType = bindAttDecl(use.getDecl());
71
72 CPropertyInfo prop = pc.createAttributeProperty( use, attType );
73
74 if(toConstant) {
75 prop.defaultValue = CDefaultValue.create(attType,use.getFixedValue());
76 prop.realization = builder.fieldRendererFactory.getConst(prop.realization);
77 } else
78 if(!attType.isCollection() && (prop.baseType == null ? true : !prop.baseType.isPrimitive())) {
79 // don't support a collection default value. That's difficult to do.
80 // primitive types default value is problematic too - we can't check whether it has been set or no ( ==null) isn't possible TODO: emit a waring in these cases
81
82 if(use.getDefaultValue()!=null) {
83 // this attribute use has a default value.
84 // the item type is guaranteed to be a leaf type... or TODO: is it really so?
85 // don't support default values if it's a list
86 prop.defaultValue = CDefaultValue.create(attType,use.getDefaultValue());
87 } else
88 if(use.getFixedValue()!=null) {
89 prop.defaultValue = CDefaultValue.create(attType,use.getFixedValue());
90 }
91 } else if(prop.baseType != null && prop.baseType.isPrimitive()) {
92 ErrorReporter errorReporter = Ring.get(ErrorReporter.class);
93
94 errorReporter.warning(prop.getLocator(), Messages.WARN_DEFAULT_VALUE_PRIMITIVE_TYPE, prop.baseType.name());
95 }
96
97 getCurrentBean().addProperty(prop);
98 }
99
100 private TypeUse bindAttDecl(XSAttributeDecl decl) {
101 SimpleTypeBuilder stb = Ring.get(SimpleTypeBuilder.class);
102 stb.refererStack.push( decl );
103 try {
104 return stb.build(decl.getType());
105 } finally {
106 stb.refererStack.pop();
107 }
108 }
109
110
111 public void complexType(XSComplexType ct) {
112 CClass ctBean = selector.bindToType(ct,null,false);
113 if(getCurrentBean()!=ctBean)
114 // in some case complex type and element binds to the same class
115 // don't make it has-a. Just make it is-a.
116 getCurrentBean().setBaseClass(ctBean);
117 }
118
119 public void wildcard(XSWildcard xsWildcard) {
120 // element wildcards are processed by particle binders,
121 // so this one is for attribute wildcard.
122
123 getCurrentBean().hasAttributeWildcard(true);
124 }
125
126 public void modelGroupDecl(XSModelGroupDecl xsModelGroupDecl) {
127 // TODO
128 throw new UnsupportedOperationException();
129 }
130
131 public void modelGroup(XSModelGroup xsModelGroup) {
132 // TODO
133 throw new UnsupportedOperationException();
134 }
135
136 public void elementDecl(XSElementDecl xsElementDecl) {
137 // TODO
138 throw new UnsupportedOperationException();
139 }
140
141 public void simpleType(XSSimpleType type) {
142 createSimpleTypeProperty(type,"Value");
143 }
144
145 public void particle(XSParticle xsParticle) {
146 // TODO
147 throw new UnsupportedOperationException();
148 }
149
150 public void empty(XSContentType ct) {
151 // empty generates nothing
152 }
153 }

mercurial