src/share/jaxws_classes/com/sun/tools/internal/xjc/model/CReferencePropertyInfo.java

Wed, 27 Apr 2016 01:27:09 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:27:09 +0800
changeset 0
373ffda63c9a
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17

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.model;
aoqi@0 27
aoqi@0 28 import java.util.Collection;
aoqi@0 29 import java.util.HashSet;
aoqi@0 30 import java.util.Set;
aoqi@0 31 import java.util.Map;
aoqi@0 32
aoqi@0 33 import javax.activation.MimeType;
aoqi@0 34 import javax.xml.bind.annotation.W3CDomHandler;
aoqi@0 35 import javax.xml.namespace.QName;
aoqi@0 36
aoqi@0 37 import com.sun.tools.internal.xjc.model.nav.NClass;
aoqi@0 38 import com.sun.tools.internal.xjc.model.nav.NType;
aoqi@0 39 import com.sun.tools.internal.xjc.model.nav.NavigatorImpl;
aoqi@0 40 import com.sun.xml.internal.bind.v2.model.core.ID;
aoqi@0 41 import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
aoqi@0 42 import com.sun.xml.internal.bind.v2.model.core.ReferencePropertyInfo;
aoqi@0 43 import com.sun.xml.internal.bind.v2.model.core.WildcardMode;
aoqi@0 44 import com.sun.xml.internal.xsom.XSComponent;
aoqi@0 45
aoqi@0 46 import org.xml.sax.Locator;
aoqi@0 47
aoqi@0 48 /**
aoqi@0 49 * {@link ReferencePropertyInfo} for the compiler.
aoqi@0 50 *
aoqi@0 51 * @author Kohsuke Kawaguchi
aoqi@0 52 */
aoqi@0 53 public final class CReferencePropertyInfo extends CPropertyInfo implements ReferencePropertyInfo<NType,NClass> {
aoqi@0 54
aoqi@0 55 /**
aoqi@0 56 * True if this property can never be absent legally.
aoqi@0 57 */
aoqi@0 58 private final boolean required;
aoqi@0 59
aoqi@0 60 /**
aoqi@0 61 * List of referenced elements.
aoqi@0 62 */
aoqi@0 63 private final Set<CElement> elements = new HashSet<CElement>();
aoqi@0 64
aoqi@0 65 private final boolean isMixed;
aoqi@0 66 private WildcardMode wildcard;
aoqi@0 67 private boolean dummy;
aoqi@0 68 private boolean content;
aoqi@0 69 private boolean isMixedExtendedCust = false;
aoqi@0 70
aoqi@0 71 public CReferencePropertyInfo(String name, boolean collection, boolean required, boolean isMixed, XSComponent source,
aoqi@0 72 CCustomizations customizations, Locator locator, boolean dummy, boolean content, boolean isMixedExtended) { // 'dummy' and 'content' here for NHIN fix - a hack in order to be able to handle extended mixed types better
aoqi@0 73 super(name, (collection||isMixed) && (!dummy), source, customizations, locator);
aoqi@0 74 this.isMixed = isMixed;
aoqi@0 75 this.required = required;
aoqi@0 76 this.dummy = dummy;
aoqi@0 77 this.content = content;
aoqi@0 78 this.isMixedExtendedCust = isMixedExtended;
aoqi@0 79 }
aoqi@0 80
aoqi@0 81 public Set<? extends CTypeInfo> ref() {
aoqi@0 82 // if(wildcard==null && !isMixed())
aoqi@0 83 // return getElements();
aoqi@0 84
aoqi@0 85 // ugly hack to get the signature right for substitution groups
aoqi@0 86 // when a class is generated for elements,they don't form a nice type hierarchy,
aoqi@0 87 // so the Java types of the substitution members need to be taken into account
aoqi@0 88 // when computing the signature
aoqi@0 89
aoqi@0 90 final class RefList extends HashSet<CTypeInfo> {
aoqi@0 91 RefList() {
aoqi@0 92 super(elements.size());
aoqi@0 93 addAll(elements);
aoqi@0 94 }
aoqi@0 95 @Override
aoqi@0 96 public boolean addAll( Collection<? extends CTypeInfo> col ) {
aoqi@0 97 boolean r = false;
aoqi@0 98 for (CTypeInfo e : col) {
aoqi@0 99 if(e instanceof CElementInfo) {
aoqi@0 100 // UGLY. element substitution is implemented in a way that
aoqi@0 101 // the derived elements are not assignable to base elements.
aoqi@0 102 // so when we compute the signature, we have to take derived types
aoqi@0 103 // into account
aoqi@0 104 r |= addAll( ((CElementInfo)e).getSubstitutionMembers());
aoqi@0 105 }
aoqi@0 106 r |= add(e);
aoqi@0 107 }
aoqi@0 108 return r;
aoqi@0 109 }
aoqi@0 110 }
aoqi@0 111
aoqi@0 112 RefList r = new RefList();
aoqi@0 113 if(wildcard!=null) {
aoqi@0 114 if(wildcard.allowDom)
aoqi@0 115 r.add(CWildcardTypeInfo.INSTANCE);
aoqi@0 116 if(wildcard.allowTypedObject)
aoqi@0 117 // we aren't really adding an AnyType.
aoqi@0 118 // this is a kind of hack to generate Object as a signature
aoqi@0 119 r.add(CBuiltinLeafInfo.ANYTYPE);
aoqi@0 120 }
aoqi@0 121 if(isMixed())
aoqi@0 122 r.add(CBuiltinLeafInfo.STRING);
aoqi@0 123
aoqi@0 124 return r;
aoqi@0 125 }
aoqi@0 126
aoqi@0 127 public Set<CElement> getElements() {
aoqi@0 128 return elements;
aoqi@0 129 }
aoqi@0 130
aoqi@0 131 public boolean isMixed() {
aoqi@0 132 return isMixed;
aoqi@0 133 }
aoqi@0 134
aoqi@0 135 public boolean isDummy() {
aoqi@0 136 return dummy;
aoqi@0 137 }
aoqi@0 138
aoqi@0 139 public boolean isContent() {
aoqi@0 140 return content;
aoqi@0 141 }
aoqi@0 142
aoqi@0 143 public boolean isMixedExtendedCust() {
aoqi@0 144 return isMixedExtendedCust;
aoqi@0 145 }
aoqi@0 146
aoqi@0 147 /**
aoqi@0 148 * We'll never use a wrapper element in XJC. Always return null.
aoqi@0 149 */
aoqi@0 150 @Deprecated
aoqi@0 151 public QName getXmlName() {
aoqi@0 152 return null;
aoqi@0 153 }
aoqi@0 154
aoqi@0 155 /**
aoqi@0 156 * Reference properties refer to elements, and none of the Java primitive type
aoqi@0 157 * maps to an element. Thus a reference property is always unboxable.
aoqi@0 158 */
aoqi@0 159 @Override
aoqi@0 160 public boolean isUnboxable() {
aoqi@0 161 return false;
aoqi@0 162 }
aoqi@0 163
aoqi@0 164 // the same as above
aoqi@0 165 @Override
aoqi@0 166 public boolean isOptionalPrimitive() {
aoqi@0 167 return false;
aoqi@0 168 }
aoqi@0 169
aoqi@0 170 public <V> V accept(CPropertyVisitor<V> visitor) {
aoqi@0 171 return visitor.onReference(this);
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 public CAdapter getAdapter() {
aoqi@0 175 return null;
aoqi@0 176 }
aoqi@0 177
aoqi@0 178 public final PropertyKind kind() {
aoqi@0 179 return PropertyKind.REFERENCE;
aoqi@0 180 }
aoqi@0 181
aoqi@0 182 /**
aoqi@0 183 * A reference property can never be ID/IDREF because they always point to
aoqi@0 184 * other element classes.
aoqi@0 185 */
aoqi@0 186 public ID id() {
aoqi@0 187 return ID.NONE;
aoqi@0 188 }
aoqi@0 189
aoqi@0 190 public WildcardMode getWildcard() {
aoqi@0 191 return wildcard;
aoqi@0 192 }
aoqi@0 193
aoqi@0 194 public void setWildcard(WildcardMode mode) {
aoqi@0 195 this.wildcard = mode;
aoqi@0 196 }
aoqi@0 197
aoqi@0 198 public NClass getDOMHandler() {
aoqi@0 199 // TODO: support other DOM handlers
aoqi@0 200 if(getWildcard()!=null)
aoqi@0 201 return NavigatorImpl.create(W3CDomHandler.class);
aoqi@0 202 else
aoqi@0 203 return null;
aoqi@0 204 }
aoqi@0 205
aoqi@0 206 public MimeType getExpectedMimeType() {
aoqi@0 207 return null;
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 public boolean isCollectionNillable() {
aoqi@0 211 // in XJC, we never recognize a nillable collection pattern, so this is always false.
aoqi@0 212 return false;
aoqi@0 213 }
aoqi@0 214
aoqi@0 215 public boolean isCollectionRequired() {
aoqi@0 216 // in XJC, we never recognize a nillable collection pattern, so this is always false.
aoqi@0 217 return false;
aoqi@0 218 }
aoqi@0 219
aoqi@0 220 // reference property cannot have a type.
aoqi@0 221 public QName getSchemaType() {
aoqi@0 222 return null;
aoqi@0 223 }
aoqi@0 224
aoqi@0 225 public boolean isRequired() {
aoqi@0 226 return required;
aoqi@0 227 }
aoqi@0 228
aoqi@0 229 @Override
aoqi@0 230 public QName collectElementNames(Map<QName, CPropertyInfo> table) {
aoqi@0 231 for (CElement e : elements) {
aoqi@0 232 QName n = e.getElementName();
aoqi@0 233 if(table.containsKey(n))
aoqi@0 234 return n;
aoqi@0 235 table.put(n,this);
aoqi@0 236 }
aoqi@0 237 return null;
aoqi@0 238 }
aoqi@0 239 }

mercurial