Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
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; |
alanb@368 | 122 | Type base = Navigator.REFLECTION.getBaseClass(t, Collection.class); |
ohair@286 | 123 | if(base==null) |
ohair@286 | 124 | return this; // not a collection |
ohair@286 | 125 | |
ohair@286 | 126 | return new TypeInfo(tagName, |
ohair@286 | 127 | Navigator.REFLECTION.getTypeArgument(base,0)); |
ohair@286 | 128 | } |
ohair@286 | 129 | |
ohair@286 | 130 | public Map<String, Object> properties() { |
ohair@286 | 131 | return properties; |
ohair@286 | 132 | } |
ohair@286 | 133 | |
ohair@286 | 134 | public boolean isGlobalElement() { |
ohair@286 | 135 | return isGlobalElement; |
ohair@286 | 136 | } |
ohair@286 | 137 | |
ohair@286 | 138 | public void setGlobalElement(boolean isGlobalElement) { |
ohair@286 | 139 | this.isGlobalElement = isGlobalElement; |
ohair@286 | 140 | } |
ohair@286 | 141 | |
ohair@286 | 142 | public TypeInfo getParentCollectionType() { |
ohair@286 | 143 | return parentCollectionType; |
ohair@286 | 144 | } |
ohair@286 | 145 | |
ohair@286 | 146 | public void setParentCollectionType(TypeInfo parentCollectionType) { |
ohair@286 | 147 | this.parentCollectionType = parentCollectionType; |
ohair@286 | 148 | } |
ohair@286 | 149 | |
ohair@286 | 150 | public boolean isRepeatedElement() { |
ohair@286 | 151 | return (parentCollectionType != null); |
ohair@286 | 152 | } |
ohair@286 | 153 | |
ohair@286 | 154 | public Type getGenericType() { |
ohair@286 | 155 | return genericType; |
ohair@286 | 156 | } |
ohair@286 | 157 | |
ohair@286 | 158 | public void setGenericType(Type genericType) { |
ohair@286 | 159 | this.genericType = genericType; |
ohair@286 | 160 | } |
ohair@286 | 161 | |
ohair@286 | 162 | public boolean isNillable() { |
ohair@286 | 163 | return nillable; |
ohair@286 | 164 | } |
ohair@286 | 165 | |
ohair@286 | 166 | public void setNillable(boolean nillable) { |
ohair@286 | 167 | this.nillable = nillable; |
ohair@286 | 168 | } |
ohair@286 | 169 | |
ohair@286 | 170 | public String toString() { |
ohair@286 | 171 | return new StringBuilder("TypeInfo: Type = ").append(type) |
ohair@286 | 172 | .append(", tag = ").append(tagName).toString(); |
ohair@286 | 173 | } |
alanb@368 | 174 | |
alanb@368 | 175 | public TypeInfo getItemType() { |
alanb@368 | 176 | // System.out.println("????? TypeInfo " + type); |
alanb@368 | 177 | if (type instanceof Class && ((Class)type).isArray() && !byte[].class.equals(type)) { |
alanb@368 | 178 | Type componentType = ((Class)type).getComponentType(); |
alanb@368 | 179 | Type genericComponentType = null; |
alanb@368 | 180 | if (genericType!= null && genericType instanceof GenericArrayType) { |
alanb@368 | 181 | GenericArrayType arrayType = (GenericArrayType) type; |
alanb@368 | 182 | genericComponentType = arrayType.getGenericComponentType(); |
alanb@368 | 183 | componentType = arrayType.getGenericComponentType(); |
alanb@368 | 184 | } |
alanb@368 | 185 | TypeInfo ti =new TypeInfo(tagName, componentType, annotations); |
alanb@368 | 186 | if (genericComponentType != null) ti.setGenericType(genericComponentType); |
alanb@368 | 187 | return ti; |
alanb@368 | 188 | } |
alanb@368 | 189 | // if (type instanceof Class && java.util.Collection.class.isAssignableFrom((Class)type)) { |
alanb@368 | 190 | Type t = (genericType != null)? genericType : type; |
alanb@368 | 191 | Type base = Navigator.REFLECTION.getBaseClass(t, Collection.class); |
alanb@368 | 192 | if ( base != null) { |
alanb@368 | 193 | return new TypeInfo(tagName, Navigator.REFLECTION.getTypeArgument(base,0), annotations); |
alanb@368 | 194 | } |
alanb@368 | 195 | return null; |
alanb@368 | 196 | } |
ohair@286 | 197 | } |