author | mkos |
Sun, 30 Dec 2012 00:00:00 +0100 | |
changeset 22678 | ac1ea46be942 |
parent 12009 | 4abb694f273a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22678
ac1ea46be942
8029237: Update copyright year to match last edit in jaxws repository for 2012
mkos
parents:
12009
diff
changeset
|
2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
12009 | 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.relaxng; |
|
27 |
||
28 |
import java.util.HashSet; |
|
29 |
import java.util.Set; |
|
30 |
import java.util.Stack; |
|
31 |
||
32 |
import com.sun.xml.internal.rngom.digested.DAttributePattern; |
|
33 |
import com.sun.xml.internal.rngom.digested.DChoicePattern; |
|
34 |
import com.sun.xml.internal.rngom.digested.DDefine; |
|
35 |
import com.sun.xml.internal.rngom.digested.DListPattern; |
|
36 |
import com.sun.xml.internal.rngom.digested.DMixedPattern; |
|
37 |
import com.sun.xml.internal.rngom.digested.DOneOrMorePattern; |
|
38 |
import com.sun.xml.internal.rngom.digested.DOptionalPattern; |
|
39 |
import com.sun.xml.internal.rngom.digested.DPatternWalker; |
|
40 |
import com.sun.xml.internal.rngom.digested.DRefPattern; |
|
41 |
import com.sun.xml.internal.rngom.digested.DZeroOrMorePattern; |
|
42 |
||
43 |
/** |
|
44 |
* Fumigate the named patterns that can be bound to inheritance. |
|
45 |
* |
|
46 |
* @author Kohsuke Kawaguchi |
|
47 |
*/ |
|
48 |
final class TypePatternBinder extends DPatternWalker { |
|
49 |
private boolean canInherit; |
|
50 |
private final Stack<Boolean> stack = new Stack<Boolean>(); |
|
51 |
||
52 |
/** |
|
53 |
* Patterns that are determined not to be bindable to inheritance. |
|
54 |
*/ |
|
55 |
private final Set<DDefine> cannotBeInherited = new HashSet<DDefine>(); |
|
56 |
||
57 |
||
58 |
void reset() { |
|
59 |
canInherit = true; |
|
60 |
stack.clear(); |
|
61 |
} |
|
62 |
||
63 |
public Void onRef(DRefPattern p) { |
|
64 |
if(!canInherit) { |
|
65 |
cannotBeInherited.add(p.getTarget()); |
|
66 |
} else { |
|
67 |
// if the whole pattern is like "A,B", we can only inherit from |
|
68 |
// either A or B. For now, always derive from A. |
|
69 |
// it might be worthwhile to have a smarter binding logic where |
|
70 |
// we pick A and B based on their 'usefulness' --- by taking into |
|
71 |
// account how many other paterns are derived from those. |
|
72 |
canInherit = false; |
|
73 |
} |
|
74 |
return null; |
|
75 |
} |
|
76 |
||
77 |
/* |
|
78 |
Set the flag to false if we hit a pattern that cannot include |
|
79 |
a <ref> to be bound as an inheritance. |
|
80 |
||
81 |
All the following code are the same |
|
82 |
*/ |
|
83 |
public Void onChoice(DChoicePattern p) { |
|
84 |
push(false); |
|
85 |
super.onChoice(p); |
|
86 |
pop(); |
|
87 |
return null; |
|
88 |
} |
|
89 |
||
90 |
public Void onAttribute(DAttributePattern p) { |
|
91 |
push(false); |
|
92 |
super.onAttribute(p); |
|
93 |
pop(); |
|
94 |
return null; |
|
95 |
} |
|
96 |
||
97 |
public Void onList(DListPattern p) { |
|
98 |
push(false); |
|
99 |
super.onList(p); |
|
100 |
pop(); |
|
101 |
return null; |
|
102 |
} |
|
103 |
||
104 |
public Void onMixed(DMixedPattern p) { |
|
105 |
push(false); |
|
106 |
super.onMixed(p); |
|
107 |
pop(); |
|
108 |
return null; |
|
109 |
} |
|
110 |
||
111 |
public Void onOneOrMore(DOneOrMorePattern p) { |
|
112 |
push(false); |
|
113 |
super.onOneOrMore(p); |
|
114 |
pop(); |
|
115 |
return null; |
|
116 |
} |
|
117 |
||
118 |
public Void onZeroOrMore(DZeroOrMorePattern p) { |
|
119 |
push(false); |
|
120 |
super.onZeroOrMore(p); |
|
121 |
pop(); |
|
122 |
return null; |
|
123 |
} |
|
124 |
||
125 |
public Void onOptional(DOptionalPattern p) { |
|
126 |
push(false); |
|
127 |
super.onOptional(p); |
|
128 |
pop(); |
|
129 |
return null; |
|
130 |
} |
|
131 |
||
132 |
private void push(boolean v) { |
|
133 |
stack.push(canInherit); |
|
134 |
canInherit = v; |
|
135 |
} |
|
136 |
||
137 |
private void pop() { |
|
138 |
canInherit = stack.pop(); |
|
139 |
} |
|
140 |
} |