src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/xmlschema/ExpressionParticleBinder.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.internal.xjc.reader.xmlschema;
aoqi@0 27
aoqi@0 28 import java.util.Collection;
aoqi@0 29
aoqi@0 30 import com.sun.tools.internal.xjc.model.CPropertyInfo;
aoqi@0 31 import com.sun.tools.internal.xjc.model.Multiplicity;
aoqi@0 32 import com.sun.tools.internal.xjc.reader.RawTypeSet;
aoqi@0 33 import com.sun.tools.internal.xjc.reader.gbind.ConnectedComponent;
aoqi@0 34 import com.sun.tools.internal.xjc.reader.gbind.Element;
aoqi@0 35 import com.sun.tools.internal.xjc.reader.gbind.Expression;
aoqi@0 36 import com.sun.tools.internal.xjc.reader.gbind.Graph;
aoqi@0 37 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIProperty;
aoqi@0 38 import com.sun.xml.internal.bind.v2.model.core.WildcardMode;
aoqi@0 39 import com.sun.xml.internal.xsom.XSParticle;
aoqi@0 40
aoqi@0 41 /**
aoqi@0 42 * {@link ParticleBinder} that uses {@link ExpressionBuilder} et al
aoqi@0 43 * for better, more intuitive (but non spec-conforming) binding.
aoqi@0 44 *
aoqi@0 45 * @author Kohsuke Kawaguchi
aoqi@0 46 */
aoqi@0 47 final class ExpressionParticleBinder extends ParticleBinder {
aoqi@0 48 public void build(XSParticle p, Collection<XSParticle> forcedProps) {
aoqi@0 49 // this class isn't about spec conformance, but
aoqi@0 50 // for the ease of use.
aoqi@0 51 // so we don't give a damn about 'forcedProps'.
aoqi@0 52 // although, for a future note, it's conceivable to expand
aoqi@0 53 // the binding algorithm to cover this notion.
aoqi@0 54
aoqi@0 55 Expression tree = ExpressionBuilder.createTree(p);
aoqi@0 56 Graph g = new Graph(tree);
aoqi@0 57 for (ConnectedComponent cc : g) {
aoqi@0 58 buildProperty(cc);
aoqi@0 59 }
aoqi@0 60 }
aoqi@0 61
aoqi@0 62 /**
aoqi@0 63 * Builds a property ouf ot a connected component.
aoqi@0 64 */
aoqi@0 65 private void buildProperty(ConnectedComponent cc) {
aoqi@0 66 StringBuilder propName = new StringBuilder(); // property name
aoqi@0 67 int nameTokenCount = 0; // combine only up to 3
aoqi@0 68
aoqi@0 69 RawTypeSetBuilder rtsb = new RawTypeSetBuilder();
aoqi@0 70 for (Element e : cc) {
aoqi@0 71 GElement ge = (GElement)e;
aoqi@0 72
aoqi@0 73 if(nameTokenCount<3) {
aoqi@0 74 if(nameTokenCount!=0)
aoqi@0 75 propName.append("And");
aoqi@0 76 propName.append(makeJavaName(cc.isCollection(),ge.getPropertyNameSeed()));
aoqi@0 77 nameTokenCount++;
aoqi@0 78 }
aoqi@0 79
aoqi@0 80 if(e instanceof GElementImpl) {
aoqi@0 81 GElementImpl ei = (GElementImpl) e;
aoqi@0 82 rtsb.elementDecl(ei.decl);
aoqi@0 83 continue;
aoqi@0 84 }
aoqi@0 85 if(e instanceof GWildcardElement) {
aoqi@0 86 GWildcardElement w = (GWildcardElement)e;
aoqi@0 87 rtsb.getRefs().add(new RawTypeSetBuilder.WildcardRef(
aoqi@0 88 w.isStrict() ? WildcardMode.STRICT : WildcardMode.SKIP));
aoqi@0 89 continue;
aoqi@0 90 }
aoqi@0 91 assert false : e; // no other kind should be here
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 Multiplicity m = Multiplicity.ONE;
aoqi@0 95 if(cc.isCollection())
aoqi@0 96 m = m.makeRepeated();
aoqi@0 97 if(!cc.isRequired())
aoqi@0 98 m = m.makeOptional();
aoqi@0 99
aoqi@0 100 RawTypeSet rts = new RawTypeSet(rtsb.getRefs(),m);
aoqi@0 101
aoqi@0 102 XSParticle p = findSourceParticle(cc);
aoqi@0 103
aoqi@0 104 BIProperty cust = BIProperty.getCustomization(p);
aoqi@0 105 CPropertyInfo prop = cust.createElementOrReferenceProperty(
aoqi@0 106 propName.toString(), false, p, rts );
aoqi@0 107 getCurrentBean().addProperty(prop);
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 /**
aoqi@0 111 * Finds a {@link XSParticle} that can serve as the representative property of
aoqi@0 112 * the given {@link ConnectedComponent}.
aoqi@0 113 *
aoqi@0 114 * The representative property is used for reporting an error location and
aoqi@0 115 * taking {@link BIProperty} customization. Right now, the algorithm is just pick
aoqi@0 116 * the first one with {@link BIProperty}, but one can think of a better algorithm,
aoqi@0 117 * such as taking a choice of (A|B) if CC={A,B}.
aoqi@0 118 */
aoqi@0 119 private XSParticle findSourceParticle(ConnectedComponent cc) {
aoqi@0 120 XSParticle first = null;
aoqi@0 121
aoqi@0 122 for (Element e : cc) {
aoqi@0 123 GElement ge = (GElement)e;
aoqi@0 124 for (XSParticle p : ge.particles) {
aoqi@0 125 if(first==null)
aoqi@0 126 first = p;
aoqi@0 127 if(getLocalPropCustomization(p)!=null)
aoqi@0 128 return p;
aoqi@0 129 }
aoqi@0 130 // if there are multiple property customizations,
aoqi@0 131 // all but one will be left unused, which will be detected as an error
aoqi@0 132 // later, so no need to check that now.
aoqi@0 133 }
aoqi@0 134
aoqi@0 135 // if no customization was found, just use the first one.
aoqi@0 136 return first;
aoqi@0 137 }
aoqi@0 138
aoqi@0 139 public boolean checkFallback(XSParticle p) {
aoqi@0 140 // this algorithm never falls back to 'getContent'.
aoqi@0 141 return false;
aoqi@0 142 }
aoqi@0 143 }

mercurial