Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
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 */
26 package com.sun.tools.internal.xjc.reader.xmlschema;
28 import java.util.HashMap;
29 import java.util.Map;
31 import javax.xml.bind.annotation.XmlAnyElement;
32 import javax.xml.namespace.QName;
34 import com.sun.tools.internal.xjc.reader.gbind.Choice;
35 import com.sun.tools.internal.xjc.reader.gbind.Element;
36 import com.sun.tools.internal.xjc.reader.gbind.Expression;
37 import com.sun.tools.internal.xjc.reader.gbind.OneOrMore;
38 import com.sun.tools.internal.xjc.reader.gbind.Sequence;
39 import com.sun.xml.internal.xsom.XSElementDecl;
40 import com.sun.xml.internal.xsom.XSModelGroup;
41 import com.sun.xml.internal.xsom.XSModelGroupDecl;
42 import com.sun.xml.internal.xsom.XSParticle;
43 import com.sun.xml.internal.xsom.XSWildcard;
44 import com.sun.xml.internal.xsom.visitor.XSTermFunction;
45 import java.math.BigInteger;
47 /**
48 * Visits {@link XSParticle} and creates a corresponding {@link Expression} tree.
49 * @author Kohsuke Kawaguchi
50 */
51 public final class ExpressionBuilder implements XSTermFunction<Expression> {
53 public static Expression createTree(XSParticle p) {
54 return new ExpressionBuilder().particle(p);
55 }
57 private ExpressionBuilder() {}
59 /**
60 * Wildcard instance needs to be consolidated to one,
61 * and this is such instance (if any.)
62 */
63 private GWildcardElement wildcard = null;
65 private final Map<QName,GElementImpl> decls = new HashMap<QName,GElementImpl>();
67 private XSParticle current;
69 /**
70 * We can only have one {@link XmlAnyElement} property,
71 * so all the wildcards need to be treated as one node.
72 */
73 public Expression wildcard(XSWildcard wc) {
74 if(wildcard==null)
75 wildcard = new GWildcardElement();
76 wildcard.merge(wc);
77 wildcard.particles.add(current);
78 return wildcard;
79 }
81 public Expression modelGroupDecl(XSModelGroupDecl decl) {
82 return modelGroup(decl.getModelGroup());
83 }
85 public Expression modelGroup(XSModelGroup group) {
86 XSModelGroup.Compositor comp = group.getCompositor();
87 if(comp==XSModelGroup.CHOICE) {
88 // empty choice is not epsilon, but empty set,
89 // so this initial value is incorrect. But this
90 // kinda works.
91 // properly handling empty set requires more work.
92 Expression e = Expression.EPSILON;
93 for (XSParticle p : group.getChildren()) {
94 if(e==null) e = particle(p);
95 else e = new Choice(e,particle(p));
96 }
97 return e;
98 } else {
99 Expression e = Expression.EPSILON;
100 for (XSParticle p : group.getChildren()) {
101 if(e==null) e = particle(p);
102 else e = new Sequence(e,particle(p));
103 }
104 return e;
105 }
106 }
108 public Element elementDecl(XSElementDecl decl) {
109 QName n = BGMBuilder.getName(decl);
111 GElementImpl e = decls.get(n);
112 if(e==null)
113 decls.put(n,e=new GElementImpl(n,decl));
115 e.particles.add(current);
116 assert current.getTerm()==decl;
118 return e;
119 }
121 public Expression particle(XSParticle p) {
122 current = p;
123 Expression e = p.getTerm().apply(this);
125 if(p.isRepeated())
126 e = new OneOrMore(e);
128 if (BigInteger.ZERO.equals(p.getMinOccurs()))
129 e = new Choice(e,Expression.EPSILON);
131 return e;
132 }
134 }