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

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

ohair@286 1 /*
ohair@286 2 * Copyright (c) 1997, 2011, 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;
ohair@286 29 import java.lang.reflect.Type;
ohair@286 30 import java.util.Collection;
ohair@286 31 import java.util.HashMap;
ohair@286 32 import java.util.Map;
ohair@286 33
ohair@286 34 import javax.xml.namespace.QName;
ohair@286 35
ohair@286 36 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
ohair@286 37
ohair@286 38 /**
ohair@286 39 * A reference to a JAXB-bound type.
ohair@286 40 *
ohair@286 41 * <p>
ohair@286 42 * <b>Subject to change without notice</b>.
ohair@286 43 *
ohair@286 44 * @since 2.0 EA1
ohair@286 45 * @author Kohsuke Kawaguchi
ohair@286 46 * @author shih-chang.chen@oracle.com
ohair@286 47 */
ohair@286 48 public final class TypeInfo {
ohair@286 49
ohair@286 50 /**
ohair@286 51 * The associated XML element name that the JAX-RPC uses with this type reference.
ohair@286 52 *
ohair@286 53 * Always non-null. Strings are interned.
ohair@286 54 */
ohair@286 55 public final QName tagName;
ohair@286 56
ohair@286 57 /**
ohair@286 58 * The Java type that's being referenced.
ohair@286 59 *
ohair@286 60 * Always non-null.
ohair@286 61 */
ohair@286 62 public Type type;
ohair@286 63
ohair@286 64 /**
ohair@286 65 * The annotations associated with the reference of this type.
ohair@286 66 *
ohair@286 67 * Always non-null.
ohair@286 68 */
ohair@286 69 public final Annotation[] annotations;
ohair@286 70
ohair@286 71 private Map<String, Object> properties = new HashMap<String, Object>();
ohair@286 72
ohair@286 73 private boolean isGlobalElement = true;
ohair@286 74
ohair@286 75 private TypeInfo parentCollectionType;
ohair@286 76
ohair@286 77 private Type genericType;
ohair@286 78
ohair@286 79 private boolean nillable = true;
ohair@286 80
ohair@286 81 public TypeInfo(QName tagName, Type type, Annotation... annotations) {
ohair@286 82 if(tagName==null || type==null || annotations==null) {
ohair@286 83 String nullArgs = "";
ohair@286 84
ohair@286 85 if(tagName == null) nullArgs = "tagName";
ohair@286 86 if(type == null) nullArgs += (nullArgs.length() > 0 ? ", type" : "type");
ohair@286 87 if(annotations == null) nullArgs += (nullArgs.length() > 0 ? ", annotations" : "annotations");
ohair@286 88
ohair@286 89 // Messages.ARGUMENT_CANT_BE_NULL.format(nullArgs);
ohair@286 90
ohair@286 91 throw new IllegalArgumentException( "Argument(s) \"" + nullArgs + "\" can''t be null.)");
ohair@286 92 }
ohair@286 93
ohair@286 94 this.tagName = new QName(tagName.getNamespaceURI().intern(), tagName.getLocalPart().intern(), tagName.getPrefix());
ohair@286 95 this.type = type;
ohair@286 96 if (type instanceof Class && ((Class<?>)type).isPrimitive()) nillable = false;
ohair@286 97 this.annotations = annotations;
ohair@286 98 }
ohair@286 99
ohair@286 100 /**
ohair@286 101 * Finds the specified annotation from the array and returns it.
ohair@286 102 * Null if not found.
ohair@286 103 */
ohair@286 104 public <A extends Annotation> A get( Class<A> annotationType ) {
ohair@286 105 for (Annotation a : annotations) {
ohair@286 106 if(a.annotationType()==annotationType)
ohair@286 107 return annotationType.cast(a);
ohair@286 108 }
ohair@286 109 return null;
ohair@286 110 }
ohair@286 111
ohair@286 112 /**
ohair@286 113 * Creates a {@link TypeInfo} for the item type,
ohair@286 114 * if this {@link TypeInfo} represents a collection type.
ohair@286 115 * Otherwise returns an identical type.
ohair@286 116 */
ohair@286 117 public TypeInfo toItemType() {
ohair@286 118 // if we are to reinstitute this check, check JAXB annotations only
ohair@286 119 // assert annotations.length==0; // not designed to work with adapters.
ohair@286 120
ohair@286 121 Type base = Navigator.REFLECTION.getBaseClass(type, Collection.class);
ohair@286 122 if(base==null)
ohair@286 123 return this; // not a collection
ohair@286 124
ohair@286 125 return new TypeInfo(tagName,
ohair@286 126 Navigator.REFLECTION.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 }
ohair@286 173 }

mercurial