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

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/xjc/model/CReferencePropertyInfo.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,239 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.internal.xjc.model;
    1.30 +
    1.31 +import java.util.Collection;
    1.32 +import java.util.HashSet;
    1.33 +import java.util.Set;
    1.34 +import java.util.Map;
    1.35 +
    1.36 +import javax.activation.MimeType;
    1.37 +import javax.xml.bind.annotation.W3CDomHandler;
    1.38 +import javax.xml.namespace.QName;
    1.39 +
    1.40 +import com.sun.tools.internal.xjc.model.nav.NClass;
    1.41 +import com.sun.tools.internal.xjc.model.nav.NType;
    1.42 +import com.sun.tools.internal.xjc.model.nav.NavigatorImpl;
    1.43 +import com.sun.xml.internal.bind.v2.model.core.ID;
    1.44 +import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
    1.45 +import com.sun.xml.internal.bind.v2.model.core.ReferencePropertyInfo;
    1.46 +import com.sun.xml.internal.bind.v2.model.core.WildcardMode;
    1.47 +import com.sun.xml.internal.xsom.XSComponent;
    1.48 +
    1.49 +import org.xml.sax.Locator;
    1.50 +
    1.51 +/**
    1.52 + * {@link ReferencePropertyInfo} for the compiler.
    1.53 + *
    1.54 + * @author Kohsuke Kawaguchi
    1.55 + */
    1.56 +public final class CReferencePropertyInfo extends CPropertyInfo implements ReferencePropertyInfo<NType,NClass> {
    1.57 +
    1.58 +    /**
    1.59 +     * True if this property can never be absent legally.
    1.60 +     */
    1.61 +    private final boolean required;
    1.62 +
    1.63 +    /**
    1.64 +     * List of referenced elements.
    1.65 +     */
    1.66 +    private final Set<CElement> elements = new HashSet<CElement>();
    1.67 +
    1.68 +    private final boolean isMixed;
    1.69 +    private WildcardMode wildcard;
    1.70 +    private boolean dummy;
    1.71 +    private boolean content;
    1.72 +    private boolean isMixedExtendedCust = false;
    1.73 +
    1.74 +    public CReferencePropertyInfo(String name, boolean collection, boolean required, boolean isMixed, XSComponent source,
    1.75 +                                  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
    1.76 +        super(name, (collection||isMixed) && (!dummy), source, customizations, locator);
    1.77 +        this.isMixed = isMixed;
    1.78 +        this.required = required;
    1.79 +        this.dummy = dummy;
    1.80 +        this.content = content;
    1.81 +        this.isMixedExtendedCust = isMixedExtended;
    1.82 +    }
    1.83 +
    1.84 +    public Set<? extends CTypeInfo> ref() {
    1.85 +//        if(wildcard==null && !isMixed())
    1.86 +//            return getElements();
    1.87 +
    1.88 +        // ugly hack to get the signature right for substitution groups
    1.89 +        // when a class is generated for elements,they don't form a nice type hierarchy,
    1.90 +        // so the Java types of the substitution members need to be taken into account
    1.91 +        // when computing the signature
    1.92 +
    1.93 +        final class RefList extends HashSet<CTypeInfo> {
    1.94 +            RefList() {
    1.95 +                super(elements.size());
    1.96 +                addAll(elements);
    1.97 +            }
    1.98 +            @Override
    1.99 +            public boolean addAll( Collection<? extends CTypeInfo> col ) {
   1.100 +                boolean r = false;
   1.101 +                for (CTypeInfo e : col) {
   1.102 +                    if(e instanceof CElementInfo) {
   1.103 +                        // UGLY. element substitution is implemented in a way that
   1.104 +                        // the derived elements are not assignable to base elements.
   1.105 +                        // so when we compute the signature, we have to take derived types
   1.106 +                        // into account
   1.107 +                        r |= addAll( ((CElementInfo)e).getSubstitutionMembers());
   1.108 +                    }
   1.109 +                    r |= add(e);
   1.110 +                }
   1.111 +                return r;
   1.112 +            }
   1.113 +        }
   1.114 +
   1.115 +        RefList r = new RefList();
   1.116 +        if(wildcard!=null) {
   1.117 +            if(wildcard.allowDom)
   1.118 +                r.add(CWildcardTypeInfo.INSTANCE);
   1.119 +            if(wildcard.allowTypedObject)
   1.120 +                // we aren't really adding an AnyType.
   1.121 +                // this is a kind of hack to generate Object as a signature
   1.122 +                r.add(CBuiltinLeafInfo.ANYTYPE);
   1.123 +        }
   1.124 +        if(isMixed())
   1.125 +            r.add(CBuiltinLeafInfo.STRING);
   1.126 +
   1.127 +        return r;
   1.128 +    }
   1.129 +
   1.130 +    public Set<CElement> getElements() {
   1.131 +        return elements;
   1.132 +    }
   1.133 +
   1.134 +    public boolean isMixed() {
   1.135 +        return isMixed;
   1.136 +    }
   1.137 +
   1.138 +    public boolean isDummy() {
   1.139 +        return dummy;
   1.140 +    }
   1.141 +
   1.142 +    public boolean isContent() {
   1.143 +        return content;
   1.144 +    }
   1.145 +
   1.146 +    public boolean isMixedExtendedCust() {
   1.147 +        return isMixedExtendedCust;
   1.148 +    }
   1.149 +
   1.150 +    /**
   1.151 +     * We'll never use a wrapper element in XJC. Always return null.
   1.152 +     */
   1.153 +    @Deprecated
   1.154 +    public QName getXmlName() {
   1.155 +        return null;
   1.156 +    }
   1.157 +
   1.158 +    /**
   1.159 +     * Reference properties refer to elements, and none of the Java primitive type
   1.160 +     * maps to an element. Thus a reference property is always unboxable.
   1.161 +     */
   1.162 +    @Override
   1.163 +    public boolean isUnboxable() {
   1.164 +        return false;
   1.165 +    }
   1.166 +
   1.167 +    // the same as above
   1.168 +    @Override
   1.169 +    public boolean isOptionalPrimitive() {
   1.170 +        return false;
   1.171 +    }
   1.172 +
   1.173 +    public <V> V accept(CPropertyVisitor<V> visitor) {
   1.174 +        return visitor.onReference(this);
   1.175 +    }
   1.176 +
   1.177 +    public CAdapter getAdapter() {
   1.178 +        return null;
   1.179 +    }
   1.180 +
   1.181 +    public final PropertyKind kind() {
   1.182 +        return PropertyKind.REFERENCE;
   1.183 +    }
   1.184 +
   1.185 +    /**
   1.186 +     * A reference property can never be ID/IDREF because they always point to
   1.187 +     * other element classes.
   1.188 +     */
   1.189 +    public ID id() {
   1.190 +        return ID.NONE;
   1.191 +    }
   1.192 +
   1.193 +    public WildcardMode getWildcard() {
   1.194 +        return wildcard;
   1.195 +    }
   1.196 +
   1.197 +    public void setWildcard(WildcardMode mode) {
   1.198 +        this.wildcard = mode;
   1.199 +    }
   1.200 +
   1.201 +    public NClass getDOMHandler() {
   1.202 +        // TODO: support other DOM handlers
   1.203 +        if(getWildcard()!=null)
   1.204 +            return NavigatorImpl.create(W3CDomHandler.class);
   1.205 +        else
   1.206 +            return null;
   1.207 +    }
   1.208 +
   1.209 +    public MimeType getExpectedMimeType() {
   1.210 +        return null;
   1.211 +    }
   1.212 +
   1.213 +    public boolean isCollectionNillable() {
   1.214 +        // in XJC, we never recognize a nillable collection pattern, so this is always false.
   1.215 +        return false;
   1.216 +    }
   1.217 +
   1.218 +    public boolean isCollectionRequired() {
   1.219 +        // in XJC, we never recognize a nillable collection pattern, so this is always false.
   1.220 +        return false;
   1.221 +    }
   1.222 +
   1.223 +    // reference property cannot have a type.
   1.224 +    public QName getSchemaType() {
   1.225 +        return null;
   1.226 +    }
   1.227 +
   1.228 +    public boolean isRequired() {
   1.229 +        return required;
   1.230 +    }
   1.231 +
   1.232 +    @Override
   1.233 +    public QName collectElementNames(Map<QName, CPropertyInfo> table) {
   1.234 +        for (CElement e : elements) {
   1.235 +            QName n = e.getElementName();
   1.236 +            if(table.containsKey(n))
   1.237 +                return n;
   1.238 +            table.put(n,this);
   1.239 +        }
   1.240 +        return null;
   1.241 +    }
   1.242 +}

mercurial