src/share/jaxws_classes/com/sun/tools/internal/xjc/model/CElementPropertyInfo.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/CElementPropertyInfo.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,213 @@
     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.AbstractList;
    1.32 +import java.util.ArrayList;
    1.33 +import java.util.List;
    1.34 +import java.util.Map;
    1.35 +
    1.36 +import javax.activation.MimeType;
    1.37 +import javax.xml.namespace.QName;
    1.38 +
    1.39 +import com.sun.tools.internal.xjc.model.nav.NClass;
    1.40 +import com.sun.tools.internal.xjc.model.nav.NType;
    1.41 +import com.sun.tools.internal.xjc.reader.RawTypeSet;
    1.42 +import com.sun.xml.internal.bind.v2.model.core.ElementPropertyInfo;
    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.xsom.XSComponent;
    1.46 +
    1.47 +import org.xml.sax.Locator;
    1.48 +
    1.49 +/**
    1.50 + * {@link ElementPropertyInfo} for the compiler.
    1.51 + *
    1.52 + * @author Kohsuke Kawaguchi
    1.53 + */
    1.54 +public final class CElementPropertyInfo extends CPropertyInfo implements ElementPropertyInfo<NType,NClass> {
    1.55 +
    1.56 +    /**
    1.57 +     * True if this property can never be absent legally.
    1.58 +     */
    1.59 +    private final boolean required;
    1.60 +
    1.61 +    private final MimeType expectedMimeType;
    1.62 +    /**
    1.63 +     *
    1.64 +     * <p>
    1.65 +     * Currently, this is set inside {@link RawTypeSet} in a very ugly way.
    1.66 +     */
    1.67 +    private CAdapter adapter;
    1.68 +
    1.69 +    private final boolean isValueList;
    1.70 +
    1.71 +    private ID id;
    1.72 +
    1.73 +
    1.74 +    /**
    1.75 +     * List of referenced types.
    1.76 +     */
    1.77 +    private final List<CTypeRef> types = new ArrayList<CTypeRef>();
    1.78 +
    1.79 +    private final List<CNonElement> ref = new AbstractList<CNonElement>() {
    1.80 +        public CNonElement get(int index) {
    1.81 +            return getTypes().get(index).getTarget();
    1.82 +        }
    1.83 +        public int size() {
    1.84 +            return getTypes().size();
    1.85 +        }
    1.86 +    };
    1.87 +
    1.88 +    // TODO: shouldn't they get id and expectedMimeType from TypeUses of CTypeRef?
    1.89 +    public CElementPropertyInfo(String name, CollectionMode collection, ID id, MimeType expectedMimeType, XSComponent source,
    1.90 +                                CCustomizations customizations, Locator locator, boolean required) {
    1.91 +        super(name, collection.col, source, customizations, locator);
    1.92 +        this.required = required;
    1.93 +        this.id = id;
    1.94 +        this.expectedMimeType = expectedMimeType;
    1.95 +        this.isValueList = collection.val;
    1.96 +    }
    1.97 +
    1.98 +    public ID id() {
    1.99 +        return id;
   1.100 +    }
   1.101 +
   1.102 +    public List<CTypeRef> getTypes() {
   1.103 +        return types;
   1.104 +    }
   1.105 +
   1.106 +    public List<CNonElement> ref() {
   1.107 +        return ref;
   1.108 +    }
   1.109 +
   1.110 +    public QName getSchemaType() {
   1.111 +        if(types.size()!=1)
   1.112 +            // if more than one kind is here, can't produce @XmlSchemaType.
   1.113 +            // TODO: is it allowed to have one generated if types
   1.114 +            return null;
   1.115 +
   1.116 +        CTypeRef t = types.get(0);
   1.117 +        if(needsExplicitTypeName(t.getTarget(),t.typeName))
   1.118 +            return t.typeName;
   1.119 +        else
   1.120 +            return null;
   1.121 +    }
   1.122 +
   1.123 +    /**
   1.124 +     * XJC never uses the wrapper element. Always return null.
   1.125 +     */
   1.126 +    @Deprecated
   1.127 +    public QName getXmlName() {
   1.128 +        return null;
   1.129 +    }
   1.130 +
   1.131 +    public boolean isCollectionRequired() {
   1.132 +        // in XJC, we never recognize a nillable collection pattern, so this is always false.
   1.133 +        return false;
   1.134 +    }
   1.135 +
   1.136 +    public boolean isCollectionNillable() {
   1.137 +        // in XJC, we never recognize a nillable collection pattern, so this is always false.
   1.138 +        return false;
   1.139 +    }
   1.140 +
   1.141 +    public boolean isRequired() {
   1.142 +        return required;
   1.143 +    }
   1.144 +
   1.145 +    public boolean isValueList() {
   1.146 +        return isValueList;
   1.147 +    }
   1.148 +
   1.149 +    public boolean isUnboxable() {
   1.150 +        if(!isCollection() && !required)
   1.151 +            // if the property can be legally absent, it's not unboxable
   1.152 +            return false;
   1.153 +        // we need to have null to represent the absence of value. not unboxable.
   1.154 +        for (CTypeRef t : getTypes()) {
   1.155 +            if(t.isNillable())
   1.156 +                return false;
   1.157 +        }
   1.158 +        return super.isUnboxable();
   1.159 +    }
   1.160 +
   1.161 +    @Override
   1.162 +    public boolean isOptionalPrimitive() {
   1.163 +        // we need to have null to represent the absence of value. not unboxable.
   1.164 +        for (CTypeRef t : getTypes()) {
   1.165 +            if(t.isNillable())
   1.166 +                return false;
   1.167 +        }
   1.168 +        return !isCollection() && !required && super.isUnboxable();
   1.169 +    }
   1.170 +
   1.171 +    public <V> V accept(CPropertyVisitor<V> visitor) {
   1.172 +        return visitor.onElement(this);
   1.173 +    }
   1.174 +
   1.175 +    public CAdapter getAdapter() {
   1.176 +        return adapter;
   1.177 +    }
   1.178 +
   1.179 +    public void setAdapter(CAdapter a) {
   1.180 +        assert adapter==null;
   1.181 +        adapter = a;
   1.182 +    }
   1.183 +
   1.184 +    public final PropertyKind kind() {
   1.185 +        return PropertyKind.ELEMENT;
   1.186 +    }
   1.187 +
   1.188 +    public MimeType getExpectedMimeType() {
   1.189 +        return expectedMimeType;
   1.190 +    }
   1.191 +
   1.192 +    public static enum CollectionMode {
   1.193 +        NOT_REPEATED(false,false),
   1.194 +        REPEATED_ELEMENT(true,false),
   1.195 +        REPEATED_VALUE(true,true);
   1.196 +
   1.197 +        private final boolean col,val;
   1.198 +
   1.199 +        CollectionMode(boolean col,boolean val) {
   1.200 +            this.col = col;
   1.201 +            this.val = val;
   1.202 +        }
   1.203 +
   1.204 +        public boolean isRepeated() { return col; }
   1.205 +    }
   1.206 +
   1.207 +    @Override
   1.208 +    public QName collectElementNames(Map<QName, CPropertyInfo> table) {
   1.209 +        for (CTypeRef t : types) {
   1.210 +            QName n = t.getTagName();
   1.211 +            if(table.containsKey(n))    return n;
   1.212 +            table.put(n, this);
   1.213 +        }
   1.214 +        return null;
   1.215 +    }
   1.216 +}

mercurial