|
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.ct; |
|
27 |
|
28 import com.sun.tools.internal.xjc.model.CClass; |
|
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.BIGlobalBinding; |
|
33 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIProperty; |
|
34 import com.sun.xml.internal.xsom.XSComplexType; |
|
35 import com.sun.xml.internal.xsom.XSParticle; |
|
36 import com.sun.xml.internal.xsom.XSType; |
|
37 |
|
38 /** |
|
39 * Binds a complex type derived from another complex type |
|
40 * by restriction. |
|
41 * |
|
42 * @author |
|
43 * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) |
|
44 */ |
|
45 final class RestrictedComplexTypeBuilder extends CTBuilder { |
|
46 |
|
47 public boolean isApplicable(XSComplexType ct) { |
|
48 XSType baseType = ct.getBaseType(); |
|
49 return baseType!=schemas.getAnyType() |
|
50 && baseType.isComplexType() |
|
51 && ct.getDerivationMethod()==XSType.RESTRICTION; |
|
52 } |
|
53 |
|
54 public void build(XSComplexType ct) { |
|
55 |
|
56 if (bgmBuilder.getGlobalBinding().isRestrictionFreshType()) { |
|
57 // handle derivation-by-restriction like a whole new type |
|
58 new FreshComplexTypeBuilder().build(ct); |
|
59 return; |
|
60 } |
|
61 |
|
62 XSComplexType baseType = ct.getBaseType().asComplexType(); |
|
63 |
|
64 // build the base class |
|
65 CClass baseClass = selector.bindToType(baseType,ct,true); |
|
66 assert baseClass!=null; // global complex type must map to a class |
|
67 |
|
68 selector.getCurrentBean().setBaseClass(baseClass); |
|
69 |
|
70 if (bgmBuilder.isGenerateMixedExtensions()) { |
|
71 boolean forceFallbackInExtension = baseType.isMixed() && |
|
72 ct.isMixed() && |
|
73 (ct.getExplicitContent() != null) && |
|
74 bgmBuilder.inExtensionMode; |
|
75 if (forceFallbackInExtension) { |
|
76 builder.recordBindingMode(ct, ComplexTypeBindingMode.NORMAL); |
|
77 |
|
78 BIProperty prop = BIProperty.getCustomization(ct); |
|
79 CPropertyInfo p; |
|
80 |
|
81 XSParticle particle = ct.getContentType().asParticle(); |
|
82 if (particle != null) { |
|
83 RawTypeSet ts = RawTypeSetBuilder.build(particle, false); |
|
84 p = prop.createDummyExtendedMixedReferenceProperty("Content", ct, ts); |
|
85 selector.getCurrentBean().addProperty(p); |
|
86 } |
|
87 } else { |
|
88 // determine the binding of this complex type. |
|
89 builder.recordBindingMode(ct,builder.getBindingMode(baseType)); |
|
90 } |
|
91 } else { |
|
92 builder.recordBindingMode(ct,builder.getBindingMode(baseType)); |
|
93 } |
|
94 } |
|
95 } |