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 |
||
31 |
import com.sun.tools.internal.xjc.model.CClassInfo; |
|
32 |
import com.sun.tools.internal.xjc.model.CElementPropertyInfo; |
|
33 |
import com.sun.tools.internal.xjc.model.CReferencePropertyInfo; |
|
34 |
import com.sun.tools.internal.xjc.model.CTypeInfo; |
|
35 |
import com.sun.tools.internal.xjc.model.CTypeRef; |
|
36 |
import com.sun.tools.internal.xjc.model.Multiplicity; |
|
37 |
import com.sun.tools.internal.xjc.reader.RawTypeSet; |
|
38 |
import com.sun.xml.internal.bind.v2.model.core.ID; |
|
39 |
||
40 |
import com.sun.xml.internal.rngom.digested.DAttributePattern; |
|
41 |
import com.sun.xml.internal.rngom.digested.DElementPattern; |
|
42 |
import com.sun.xml.internal.rngom.digested.DOneOrMorePattern; |
|
43 |
import com.sun.xml.internal.rngom.digested.DPattern; |
|
44 |
import com.sun.xml.internal.rngom.digested.DPatternWalker; |
|
45 |
import com.sun.xml.internal.rngom.digested.DZeroOrMorePattern; |
|
46 |
||
47 |
/** |
|
48 |
* Builds {@link RawTypeSet} for RELAX NG. |
|
49 |
* |
|
50 |
* @author Kohsuke Kawaguchi |
|
51 |
*/ |
|
52 |
public final class RawTypeSetBuilder extends DPatternWalker { |
|
53 |
public static RawTypeSet build( RELAXNGCompiler compiler, DPattern contentModel, Multiplicity mul ) { |
|
54 |
RawTypeSetBuilder builder = new RawTypeSetBuilder(compiler,mul); |
|
55 |
contentModel.accept(builder); |
|
56 |
return builder.create(); |
|
57 |
} |
|
58 |
||
59 |
/** |
|
60 |
* Multiplicity of the property. |
|
61 |
*/ |
|
62 |
private Multiplicity mul; |
|
63 |
||
64 |
/** |
|
65 |
* Accumulates discovered {@link RawTypeSet.Ref}s. |
|
66 |
*/ |
|
67 |
private final Set<RawTypeSet.Ref> refs = new HashSet<RawTypeSet.Ref>(); |
|
68 |
||
69 |
private final RELAXNGCompiler compiler; |
|
70 |
||
71 |
public RawTypeSetBuilder(RELAXNGCompiler compiler,Multiplicity mul) { |
|
72 |
this.mul = mul; |
|
73 |
this.compiler = compiler; |
|
74 |
} |
|
75 |
||
76 |
private RawTypeSet create() { |
|
77 |
return new RawTypeSet(refs,mul); |
|
78 |
} |
|
79 |
||
80 |
public Void onAttribute(DAttributePattern p) { |
|
81 |
// attributes form their own properties |
|
82 |
return null; |
|
83 |
} |
|
84 |
||
85 |
public Void onElement(DElementPattern p) { |
|
86 |
CTypeInfo[] tis = compiler.classes.get(p); |
|
87 |
if(tis!=null) { |
|
88 |
for( CTypeInfo ti : tis ) |
|
89 |
refs.add(new CClassInfoRef((CClassInfo)ti)); |
|
90 |
} else { |
|
91 |
// TODO |
|
92 |
assert false; |
|
93 |
} |
|
94 |
return null; |
|
95 |
} |
|
96 |
||
97 |
public Void onZeroOrMore(DZeroOrMorePattern p) { |
|
98 |
mul = mul.makeRepeated(); |
|
99 |
return super.onZeroOrMore(p); |
|
100 |
} |
|
101 |
||
102 |
public Void onOneOrMore(DOneOrMorePattern p) { |
|
103 |
mul = mul.makeRepeated(); |
|
104 |
return super.onOneOrMore(p); |
|
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* For {@link CClassInfo}s that map to elements. |
|
109 |
*/ |
|
110 |
private static final class CClassInfoRef extends RawTypeSet.Ref { |
|
111 |
private final CClassInfo ci; |
|
112 |
CClassInfoRef(CClassInfo ci) { |
|
113 |
this.ci = ci; |
|
114 |
assert ci.isElement(); |
|
115 |
} |
|
116 |
||
117 |
protected ID id() { |
|
118 |
return ID.NONE; |
|
119 |
} |
|
120 |
||
121 |
protected boolean isListOfValues() { |
|
122 |
return false; |
|
123 |
} |
|
124 |
||
125 |
protected RawTypeSet.Mode canBeType(RawTypeSet parent) { |
|
126 |
return RawTypeSet.Mode.SHOULD_BE_TYPEREF; |
|
127 |
} |
|
128 |
||
129 |
protected void toElementRef(CReferencePropertyInfo prop) { |
|
130 |
prop.getElements().add(ci); |
|
131 |
} |
|
132 |
||
133 |
protected CTypeRef toTypeRef(CElementPropertyInfo ep) { |
|
134 |
return new CTypeRef(ci,ci.getElementName(),ci.getTypeName(),false,null); |
|
135 |
} |
|
136 |
} |
|
137 |
} |