src/share/jaxws_classes/com/sun/xml/internal/ws/spi/db/TypeInfo.java

Fri, 24 Oct 2014 15:02:28 +0200

author
mkos
date
Fri, 24 Oct 2014 15:02:28 +0200
changeset 786
a14efa699f0f
parent 450
b0c2840e2513
child 637
9c07ef4934dd
permissions
-rw-r--r--

8054367: More references for endpoints
Summary: fix also reviewed by Iaroslav.Savytskyi@oracle.com, Alexander.Fomin@oracle.com
Reviewed-by: mullan, skoivu

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.spi.db;
ohair@286 27
ohair@286 28 import java.lang.annotation.Annotation;
alanb@368 29 import java.lang.reflect.GenericArrayType;
ohair@286 30 import java.lang.reflect.Type;
ohair@286 31 import java.util.Collection;
ohair@286 32 import java.util.HashMap;
ohair@286 33 import java.util.Map;
ohair@286 34
ohair@286 35 import javax.xml.namespace.QName;
ohair@286 36
ohair@286 37 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
ohair@286 38
ohair@286 39 /**
ohair@286 40 * A reference to a JAXB-bound type.
ohair@286 41 *
ohair@286 42 * <p>
ohair@286 43 * <b>Subject to change without notice</b>.
ohair@286 44 *
ohair@286 45 * @since 2.0 EA1
ohair@286 46 * @author Kohsuke Kawaguchi
ohair@286 47 * @author shih-chang.chen@oracle.com
ohair@286 48 */
ohair@286 49 public final class TypeInfo {
ohair@286 50
ohair@286 51 /**
ohair@286 52 * The associated XML element name that the JAX-RPC uses with this type reference.
ohair@286 53 *
ohair@286 54 * Always non-null. Strings are interned.
ohair@286 55 */
ohair@286 56 public final QName tagName;
ohair@286 57
ohair@286 58 /**
ohair@286 59 * The Java type that's being referenced.
ohair@286 60 *
ohair@286 61 * Always non-null.
ohair@286 62 */
ohair@286 63 public Type type;
ohair@286 64
ohair@286 65 /**
ohair@286 66 * The annotations associated with the reference of this type.
ohair@286 67 *
ohair@286 68 * Always non-null.
ohair@286 69 */
ohair@286 70 public final Annotation[] annotations;
ohair@286 71
ohair@286 72 private Map<String, Object> properties = new HashMap<String, Object>();
ohair@286 73
ohair@286 74 private boolean isGlobalElement = true;
ohair@286 75
ohair@286 76 private TypeInfo parentCollectionType;
ohair@286 77
ohair@286 78 private Type genericType;
ohair@286 79
ohair@286 80 private boolean nillable = true;
ohair@286 81
ohair@286 82 public TypeInfo(QName tagName, Type type, Annotation... annotations) {
ohair@286 83 if(tagName==null || type==null || annotations==null) {
ohair@286 84 String nullArgs = "";
ohair@286 85
ohair@286 86 if(tagName == null) nullArgs = "tagName";
ohair@286 87 if(type == null) nullArgs += (nullArgs.length() > 0 ? ", type" : "type");
ohair@286 88 if(annotations == null) nullArgs += (nullArgs.length() > 0 ? ", annotations" : "annotations");
ohair@286 89
ohair@286 90 // Messages.ARGUMENT_CANT_BE_NULL.format(nullArgs);
ohair@286 91
ohair@286 92 throw new IllegalArgumentException( "Argument(s) \"" + nullArgs + "\" can''t be null.)");
ohair@286 93 }
ohair@286 94
ohair@286 95 this.tagName = new QName(tagName.getNamespaceURI().intern(), tagName.getLocalPart().intern(), tagName.getPrefix());
ohair@286 96 this.type = type;
ohair@286 97 if (type instanceof Class && ((Class<?>)type).isPrimitive()) nillable = false;
ohair@286 98 this.annotations = annotations;
ohair@286 99 }
ohair@286 100
ohair@286 101 /**
ohair@286 102 * Finds the specified annotation from the array and returns it.
ohair@286 103 * Null if not found.
ohair@286 104 */
ohair@286 105 public <A extends Annotation> A get( Class<A> annotationType ) {
ohair@286 106 for (Annotation a : annotations) {
ohair@286 107 if(a.annotationType()==annotationType)
ohair@286 108 return annotationType.cast(a);
ohair@286 109 }
ohair@286 110 return null;
ohair@286 111 }
ohair@286 112
ohair@286 113 /**
ohair@286 114 * Creates a {@link TypeInfo} for the item type,
ohair@286 115 * if this {@link TypeInfo} represents a collection type.
ohair@286 116 * Otherwise returns an identical type.
ohair@286 117 */
ohair@286 118 public TypeInfo toItemType() {
ohair@286 119 // if we are to reinstitute this check, check JAXB annotations only
ohair@286 120 // assert annotations.length==0; // not designed to work with adapters.
alanb@368 121 Type t = (genericType != null)? genericType : type;
mkos@450 122 Type base = Utils.REFLECTION_NAVIGATOR.getBaseClass(t, Collection.class);
ohair@286 123 if(base==null)
ohair@286 124 return this; // not a collection
ohair@286 125
mkos@450 126 return new TypeInfo(tagName, Utils.REFLECTION_NAVIGATOR.getTypeArgument(base,0));
ohair@286 127 }
ohair@286 128
ohair@286 129 public Map<String, Object> properties() {
ohair@286 130 return properties;
ohair@286 131 }
ohair@286 132
ohair@286 133 public boolean isGlobalElement() {
ohair@286 134 return isGlobalElement;
ohair@286 135 }
ohair@286 136
ohair@286 137 public void setGlobalElement(boolean isGlobalElement) {
ohair@286 138 this.isGlobalElement = isGlobalElement;
ohair@286 139 }
ohair@286 140
ohair@286 141 public TypeInfo getParentCollectionType() {
ohair@286 142 return parentCollectionType;
ohair@286 143 }
ohair@286 144
ohair@286 145 public void setParentCollectionType(TypeInfo parentCollectionType) {
ohair@286 146 this.parentCollectionType = parentCollectionType;
ohair@286 147 }
ohair@286 148
ohair@286 149 public boolean isRepeatedElement() {
ohair@286 150 return (parentCollectionType != null);
ohair@286 151 }
ohair@286 152
ohair@286 153 public Type getGenericType() {
ohair@286 154 return genericType;
ohair@286 155 }
ohair@286 156
ohair@286 157 public void setGenericType(Type genericType) {
ohair@286 158 this.genericType = genericType;
ohair@286 159 }
ohair@286 160
ohair@286 161 public boolean isNillable() {
ohair@286 162 return nillable;
ohair@286 163 }
ohair@286 164
ohair@286 165 public void setNillable(boolean nillable) {
ohair@286 166 this.nillable = nillable;
ohair@286 167 }
ohair@286 168
ohair@286 169 public String toString() {
ohair@286 170 return new StringBuilder("TypeInfo: Type = ").append(type)
ohair@286 171 .append(", tag = ").append(tagName).toString();
ohair@286 172 }
alanb@368 173
alanb@368 174 public TypeInfo getItemType() {
alanb@368 175 // System.out.println("????? TypeInfo " + type);
alanb@368 176 if (type instanceof Class && ((Class)type).isArray() && !byte[].class.equals(type)) {
alanb@368 177 Type componentType = ((Class)type).getComponentType();
alanb@368 178 Type genericComponentType = null;
alanb@368 179 if (genericType!= null && genericType instanceof GenericArrayType) {
alanb@368 180 GenericArrayType arrayType = (GenericArrayType) type;
alanb@368 181 genericComponentType = arrayType.getGenericComponentType();
alanb@368 182 componentType = arrayType.getGenericComponentType();
alanb@368 183 }
alanb@368 184 TypeInfo ti =new TypeInfo(tagName, componentType, annotations);
alanb@368 185 if (genericComponentType != null) ti.setGenericType(genericComponentType);
alanb@368 186 return ti;
alanb@368 187 }
alanb@368 188 // if (type instanceof Class && java.util.Collection.class.isAssignableFrom((Class)type)) {
alanb@368 189 Type t = (genericType != null)? genericType : type;
mkos@450 190 Type base = Utils.REFLECTION_NAVIGATOR.getBaseClass(t, Collection.class);
alanb@368 191 if ( base != null) {
mkos@450 192 return new TypeInfo(tagName, Utils.REFLECTION_NAVIGATOR.getTypeArgument(base,0), annotations);
alanb@368 193 }
alanb@368 194 return null;
alanb@368 195 }
ohair@286 196 }

mercurial