|
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 java.util.HashMap; |
|
29 import java.util.Map; |
|
30 |
|
31 import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder; |
|
32 import com.sun.tools.internal.xjc.reader.xmlschema.BindingComponent; |
|
33 import com.sun.xml.internal.xsom.XSComplexType; |
|
34 |
|
35 /** |
|
36 * single entry point of building a field expression from a complex type. |
|
37 * |
|
38 * One object is created for one {@link BGMBuilder}. |
|
39 * |
|
40 * @author |
|
41 * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) |
|
42 */ |
|
43 public final class ComplexTypeFieldBuilder extends BindingComponent { |
|
44 |
|
45 /** |
|
46 * All installed available complex type builders. |
|
47 * |
|
48 * <p> |
|
49 * Builders are tried in this order, to put specific ones first. |
|
50 */ |
|
51 private final CTBuilder[] complexTypeBuilders = new CTBuilder[]{ |
|
52 new MultiWildcardComplexTypeBuilder(), |
|
53 new MixedExtendedComplexTypeBuilder(), |
|
54 new MixedComplexTypeBuilder(), |
|
55 new FreshComplexTypeBuilder(), |
|
56 new ExtendedComplexTypeBuilder(), |
|
57 new RestrictedComplexTypeBuilder(), |
|
58 new STDerivedComplexTypeBuilder() |
|
59 }; |
|
60 |
|
61 /** Records ComplexTypeBindingMode for XSComplexType. */ |
|
62 private final Map<XSComplexType,ComplexTypeBindingMode> complexTypeBindingModes = |
|
63 new HashMap<XSComplexType,ComplexTypeBindingMode>(); |
|
64 |
|
65 /** |
|
66 * Binds a complex type to a field expression. |
|
67 */ |
|
68 public void build( XSComplexType type ) { |
|
69 for( CTBuilder ctb : complexTypeBuilders ) |
|
70 if( ctb.isApplicable(type) ) { |
|
71 ctb.build(type); |
|
72 return; |
|
73 } |
|
74 |
|
75 assert false; // shall never happen |
|
76 } |
|
77 |
|
78 /** |
|
79 * Records the binding mode of the given complex type. |
|
80 * |
|
81 * <p> |
|
82 * Binding of a derived complex type often depends on that of the |
|
83 * base complex type. For example, when a base type is bound to |
|
84 * the getRest() method, all the derived complex types will be bound |
|
85 * in the same way. |
|
86 * |
|
87 * <p> |
|
88 * For this reason, we have to record how each complex type is being |
|
89 * bound. |
|
90 */ |
|
91 public void recordBindingMode( XSComplexType type, ComplexTypeBindingMode flag ) { |
|
92 // it is an error to override the flag. |
|
93 Object o = complexTypeBindingModes.put(type,flag); |
|
94 assert o==null; |
|
95 } |
|
96 |
|
97 /** |
|
98 * Obtains the binding mode recorded through |
|
99 * {@link #recordBindingMode(XSComplexType, ComplexTypeBindingMode)}. |
|
100 */ |
|
101 protected ComplexTypeBindingMode getBindingMode( XSComplexType type ) { |
|
102 ComplexTypeBindingMode r = complexTypeBindingModes.get(type); |
|
103 assert r!=null; |
|
104 return r; |
|
105 } |
|
106 } |