01: /*
02: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package com.sun.tools.internal.xjc.reader.xmlschema.ct;
27:
28: import com.sun.tools.internal.xjc.model.CBuiltinLeafInfo;
29: import com.sun.tools.internal.xjc.model.CPropertyInfo;
30: import com.sun.tools.internal.xjc.reader.RawTypeSet;
31: import com.sun.tools.internal.xjc.reader.xmlschema.RawTypeSetBuilder;
32: import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIProperty;
33: import static com.sun.tools.internal.xjc.reader.xmlschema.ct.ComplexTypeBindingMode.FALLBACK_CONTENT;
34: import com.sun.xml.internal.xsom.XSComplexType;
35: import com.sun.xml.internal.xsom.XSContentType;
36: import com.sun.xml.internal.xsom.XSType;
37:
38: /**
39: * @author Kohsuke Kawaguchi
40: */
41: final class MixedComplexTypeBuilder extends CTBuilder {
42:
43: public boolean isApplicable(XSComplexType ct) {
44: XSType bt = ct.getBaseType();
45: if (bt == schemas.getAnyType() && ct.isMixed())
46: return true; // fresh mixed complex type
47:
48: // see issue 148. handle complex type extended from another and added mixed=true.
49: // the current implementation only works when the base type doesn't define
50: // any elements, and we should ideally warn it.
51: if (bt.isComplexType() && !bt.asComplexType().isMixed()
52: && ct.isMixed()
53: && ct.getDerivationMethod() == XSType.EXTENSION)
54: return true;
55:
56: return false;
57: }
58:
59: public void build(XSComplexType ct) {
60: XSContentType contentType = ct.getContentType();
61:
62: // if mixed, we fallback immediately
63: builder.recordBindingMode(ct, FALLBACK_CONTENT);
64:
65: BIProperty prop = BIProperty.getCustomization(ct);
66:
67: CPropertyInfo p;
68:
69: if (contentType.asEmpty() != null) {
70: p = prop.createValueProperty("Content", false, ct,
71: CBuiltinLeafInfo.STRING);
72: } else {
73: RawTypeSet ts = RawTypeSetBuilder.build(contentType
74: .asParticle(), false);
75: p = prop.createReferenceProperty("Content", false, ct, ts,
76: true);
77: }
78:
79: selector.getCurrentBean().addProperty(p);
80:
81: // adds attributes and we are through.
82: green.attContainer(ct);
83: }
84:
85: }
|