001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.xml.internal.bind.v2.model.impl;
027:
028: import javax.xml.namespace.QName;
029:
030: import com.sun.xml.internal.bind.v2.TODO;
031: import com.sun.xml.internal.bind.v2.WellKnownNamespace;
032: import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
033: import com.sun.xml.internal.bind.v2.model.core.ArrayInfo;
034: import com.sun.xml.internal.bind.v2.model.core.NonElement;
035: import com.sun.xml.internal.bind.v2.runtime.Location;
036:
037: /**
038: *
039: * <p>
040: * Public because XJC needs to access it
041: *
042: * @author Kohsuke Kawaguchi
043: */
044: public class ArrayInfoImpl<TypeT, ClassDeclT, FieldT, MethodT> extends
045: TypeInfoImpl<TypeT, ClassDeclT, FieldT, MethodT> implements
046: ArrayInfo<TypeT, ClassDeclT>, Location {
047:
048: private final NonElement<TypeT, ClassDeclT> itemType;
049:
050: private final QName typeName;
051:
052: /**
053: * The representation of T[] in the underlying reflection library.
054: */
055: private final TypeT arrayType;
056:
057: public ArrayInfoImpl(
058: ModelBuilder<TypeT, ClassDeclT, FieldT, MethodT> builder,
059: Locatable upstream, TypeT arrayType) {
060: super (builder, upstream);
061: this .arrayType = arrayType;
062: this .itemType = builder.getTypeInfo(nav().getComponentType(
063: arrayType), this );
064:
065: // TODO: check itemType.getTypeName()!=null and report an error
066: QName n = itemType.getTypeName();
067: this .typeName = calcArrayTypeName(n);
068: }
069:
070: /**
071: * Computes the type name of the array from that of the item type.
072: */
073: public static final QName calcArrayTypeName(QName n) {
074: String uri;
075: if (n.getNamespaceURI().equals(WellKnownNamespace.XML_SCHEMA)) {
076: TODO.checkSpec("this URI");
077: uri = "http://jaxb.dev.java.net/array";
078: } else
079: uri = n.getNamespaceURI();
080: return new QName(uri, n.getLocalPart() + "Array");
081: }
082:
083: public NonElement<TypeT, ClassDeclT> getItemType() {
084: return itemType;
085: }
086:
087: public QName getTypeName() {
088: return typeName;
089: }
090:
091: public boolean isSimpleType() {
092: return false;
093: }
094:
095: public TypeT getType() {
096: return arrayType;
097: }
098:
099: /**
100: * Leaf-type cannot be referenced from IDREF.
101: *
102: * @deprecated
103: * why are you calling a method whose return value is always known?
104: */
105: public final boolean canBeReferencedByIDREF() {
106: return false;
107: }
108:
109: public Location getLocation() {
110: return this ;
111: }
112:
113: public String toString() {
114: return nav().getTypeName(arrayType);
115: }
116: }
|