001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.bind.v2.model.impl;
038:
039: import javax.xml.namespace.QName;
040:
041: import com.sun.xml.bind.v2.TODO;
042: import com.sun.xml.bind.v2.WellKnownNamespace;
043: import com.sun.xml.bind.v2.model.annotation.Locatable;
044: import com.sun.xml.bind.v2.model.core.ArrayInfo;
045: import com.sun.xml.bind.v2.model.core.NonElement;
046: import com.sun.xml.bind.v2.runtime.Location;
047: import com.sun.xml.bind.v2.runtime.IllegalAnnotationException;
048:
049: /**
050: *
051: * <p>
052: * Public because XJC needs to access it
053: *
054: * @author Kohsuke Kawaguchi
055: */
056: public class ArrayInfoImpl<TypeT, ClassDeclT, FieldT, MethodT> extends
057: TypeInfoImpl<TypeT, ClassDeclT, FieldT, MethodT> implements
058: ArrayInfo<TypeT, ClassDeclT>, Location {
059:
060: private final NonElement<TypeT, ClassDeclT> itemType;
061:
062: private final QName typeName;
063:
064: /**
065: * The representation of T[] in the underlying reflection library.
066: */
067: private final TypeT arrayType;
068:
069: public ArrayInfoImpl(
070: ModelBuilder<TypeT, ClassDeclT, FieldT, MethodT> builder,
071: Locatable upstream, TypeT arrayType) {
072: super (builder, upstream);
073: this .arrayType = arrayType;
074: TypeT componentType = nav().getComponentType(arrayType);
075: this .itemType = builder.getTypeInfo(componentType, this );
076:
077: QName n = itemType.getTypeName();
078: if (n == null) {
079: builder.reportError(new IllegalAnnotationException(
080: Messages.ANONYMOUS_ARRAY_ITEM.format(nav()
081: .getTypeName(componentType)), this ));
082: n = new QName("#dummy"); // for error recovery
083: }
084: this .typeName = calcArrayTypeName(n);
085: }
086:
087: /**
088: * Computes the type name of the array from that of the item type.
089: */
090: public static QName calcArrayTypeName(QName n) {
091: String uri;
092: if (n.getNamespaceURI().equals(WellKnownNamespace.XML_SCHEMA)) {
093: TODO.checkSpec("this URI");
094: uri = "http://jaxb.dev.java.net/array";
095: } else
096: uri = n.getNamespaceURI();
097: return new QName(uri, n.getLocalPart() + "Array");
098: }
099:
100: public NonElement<TypeT, ClassDeclT> getItemType() {
101: return itemType;
102: }
103:
104: public QName getTypeName() {
105: return typeName;
106: }
107:
108: public boolean isSimpleType() {
109: return false;
110: }
111:
112: public TypeT getType() {
113: return arrayType;
114: }
115:
116: /**
117: * Leaf-type cannot be referenced from IDREF.
118: *
119: * @deprecated
120: * why are you calling a method whose return value is always known?
121: */
122: public final boolean canBeReferencedByIDREF() {
123: return false;
124: }
125:
126: public Location getLocation() {
127: return this ;
128: }
129:
130: public String toString() {
131: return nav().getTypeName(arrayType);
132: }
133: }
|