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

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

mercurial