src/share/jaxws_classes/com/sun/tools/internal/xjc/model/CElementPropertyInfo.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.AbstractList;
aoqi@0 29 import java.util.ArrayList;
aoqi@0 30 import java.util.List;
aoqi@0 31 import java.util.Map;
aoqi@0 32
aoqi@0 33 import javax.activation.MimeType;
aoqi@0 34 import javax.xml.namespace.QName;
aoqi@0 35
aoqi@0 36 import com.sun.tools.internal.xjc.model.nav.NClass;
aoqi@0 37 import com.sun.tools.internal.xjc.model.nav.NType;
aoqi@0 38 import com.sun.tools.internal.xjc.reader.RawTypeSet;
aoqi@0 39 import com.sun.xml.internal.bind.v2.model.core.ElementPropertyInfo;
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.xsom.XSComponent;
aoqi@0 43
aoqi@0 44 import org.xml.sax.Locator;
aoqi@0 45
aoqi@0 46 /**
aoqi@0 47 * {@link ElementPropertyInfo} for the compiler.
aoqi@0 48 *
aoqi@0 49 * @author Kohsuke Kawaguchi
aoqi@0 50 */
aoqi@0 51 public final class CElementPropertyInfo extends CPropertyInfo implements ElementPropertyInfo<NType,NClass> {
aoqi@0 52
aoqi@0 53 /**
aoqi@0 54 * True if this property can never be absent legally.
aoqi@0 55 */
aoqi@0 56 private final boolean required;
aoqi@0 57
aoqi@0 58 private final MimeType expectedMimeType;
aoqi@0 59 /**
aoqi@0 60 *
aoqi@0 61 * <p>
aoqi@0 62 * Currently, this is set inside {@link RawTypeSet} in a very ugly way.
aoqi@0 63 */
aoqi@0 64 private CAdapter adapter;
aoqi@0 65
aoqi@0 66 private final boolean isValueList;
aoqi@0 67
aoqi@0 68 private ID id;
aoqi@0 69
aoqi@0 70
aoqi@0 71 /**
aoqi@0 72 * List of referenced types.
aoqi@0 73 */
aoqi@0 74 private final List<CTypeRef> types = new ArrayList<CTypeRef>();
aoqi@0 75
aoqi@0 76 private final List<CNonElement> ref = new AbstractList<CNonElement>() {
aoqi@0 77 public CNonElement get(int index) {
aoqi@0 78 return getTypes().get(index).getTarget();
aoqi@0 79 }
aoqi@0 80 public int size() {
aoqi@0 81 return getTypes().size();
aoqi@0 82 }
aoqi@0 83 };
aoqi@0 84
aoqi@0 85 // TODO: shouldn't they get id and expectedMimeType from TypeUses of CTypeRef?
aoqi@0 86 public CElementPropertyInfo(String name, CollectionMode collection, ID id, MimeType expectedMimeType, XSComponent source,
aoqi@0 87 CCustomizations customizations, Locator locator, boolean required) {
aoqi@0 88 super(name, collection.col, source, customizations, locator);
aoqi@0 89 this.required = required;
aoqi@0 90 this.id = id;
aoqi@0 91 this.expectedMimeType = expectedMimeType;
aoqi@0 92 this.isValueList = collection.val;
aoqi@0 93 }
aoqi@0 94
aoqi@0 95 public ID id() {
aoqi@0 96 return id;
aoqi@0 97 }
aoqi@0 98
aoqi@0 99 public List<CTypeRef> getTypes() {
aoqi@0 100 return types;
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 public List<CNonElement> ref() {
aoqi@0 104 return ref;
aoqi@0 105 }
aoqi@0 106
aoqi@0 107 public QName getSchemaType() {
aoqi@0 108 if(types.size()!=1)
aoqi@0 109 // if more than one kind is here, can't produce @XmlSchemaType.
aoqi@0 110 // TODO: is it allowed to have one generated if types
aoqi@0 111 return null;
aoqi@0 112
aoqi@0 113 CTypeRef t = types.get(0);
aoqi@0 114 if(needsExplicitTypeName(t.getTarget(),t.typeName))
aoqi@0 115 return t.typeName;
aoqi@0 116 else
aoqi@0 117 return null;
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 /**
aoqi@0 121 * XJC never uses the wrapper element. Always return null.
aoqi@0 122 */
aoqi@0 123 @Deprecated
aoqi@0 124 public QName getXmlName() {
aoqi@0 125 return null;
aoqi@0 126 }
aoqi@0 127
aoqi@0 128 public boolean isCollectionRequired() {
aoqi@0 129 // in XJC, we never recognize a nillable collection pattern, so this is always false.
aoqi@0 130 return false;
aoqi@0 131 }
aoqi@0 132
aoqi@0 133 public boolean isCollectionNillable() {
aoqi@0 134 // in XJC, we never recognize a nillable collection pattern, so this is always false.
aoqi@0 135 return false;
aoqi@0 136 }
aoqi@0 137
aoqi@0 138 public boolean isRequired() {
aoqi@0 139 return required;
aoqi@0 140 }
aoqi@0 141
aoqi@0 142 public boolean isValueList() {
aoqi@0 143 return isValueList;
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 public boolean isUnboxable() {
aoqi@0 147 if(!isCollection() && !required)
aoqi@0 148 // if the property can be legally absent, it's not unboxable
aoqi@0 149 return false;
aoqi@0 150 // we need to have null to represent the absence of value. not unboxable.
aoqi@0 151 for (CTypeRef t : getTypes()) {
aoqi@0 152 if(t.isNillable())
aoqi@0 153 return false;
aoqi@0 154 }
aoqi@0 155 return super.isUnboxable();
aoqi@0 156 }
aoqi@0 157
aoqi@0 158 @Override
aoqi@0 159 public boolean isOptionalPrimitive() {
aoqi@0 160 // we need to have null to represent the absence of value. not unboxable.
aoqi@0 161 for (CTypeRef t : getTypes()) {
aoqi@0 162 if(t.isNillable())
aoqi@0 163 return false;
aoqi@0 164 }
aoqi@0 165 return !isCollection() && !required && super.isUnboxable();
aoqi@0 166 }
aoqi@0 167
aoqi@0 168 public <V> V accept(CPropertyVisitor<V> visitor) {
aoqi@0 169 return visitor.onElement(this);
aoqi@0 170 }
aoqi@0 171
aoqi@0 172 public CAdapter getAdapter() {
aoqi@0 173 return adapter;
aoqi@0 174 }
aoqi@0 175
aoqi@0 176 public void setAdapter(CAdapter a) {
aoqi@0 177 assert adapter==null;
aoqi@0 178 adapter = a;
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 public final PropertyKind kind() {
aoqi@0 182 return PropertyKind.ELEMENT;
aoqi@0 183 }
aoqi@0 184
aoqi@0 185 public MimeType getExpectedMimeType() {
aoqi@0 186 return expectedMimeType;
aoqi@0 187 }
aoqi@0 188
aoqi@0 189 public static enum CollectionMode {
aoqi@0 190 NOT_REPEATED(false,false),
aoqi@0 191 REPEATED_ELEMENT(true,false),
aoqi@0 192 REPEATED_VALUE(true,true);
aoqi@0 193
aoqi@0 194 private final boolean col,val;
aoqi@0 195
aoqi@0 196 CollectionMode(boolean col,boolean val) {
aoqi@0 197 this.col = col;
aoqi@0 198 this.val = val;
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 public boolean isRepeated() { return col; }
aoqi@0 202 }
aoqi@0 203
aoqi@0 204 @Override
aoqi@0 205 public QName collectElementNames(Map<QName, CPropertyInfo> table) {
aoqi@0 206 for (CTypeRef t : types) {
aoqi@0 207 QName n = t.getTagName();
aoqi@0 208 if(table.containsKey(n)) return n;
aoqi@0 209 table.put(n, this);
aoqi@0 210 }
aoqi@0 211 return null;
aoqi@0 212 }
aoqi@0 213 }

mercurial