1/* 2 * Copyright (c) 1997, 2013, 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 */ 25 26package com.sun.xml.internal.bind.v2.model.impl; 27 28import javax.xml.namespace.QName; 29 30import com.sun.xml.internal.bind.v2.model.annotation.Locatable; 31import com.sun.xml.internal.bind.v2.model.core.ArrayInfo; 32import com.sun.xml.internal.bind.v2.model.core.NonElement; 33import com.sun.xml.internal.bind.v2.model.util.ArrayInfoUtil; 34import com.sun.xml.internal.bind.v2.runtime.Location; 35import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException; 36 37/** 38 * 39 * <p> 40 * Public because XJC needs to access it 41 * 42 * @author Kohsuke Kawaguchi 43 */ 44public class ArrayInfoImpl<TypeT,ClassDeclT,FieldT,MethodT> 45 extends TypeInfoImpl<TypeT,ClassDeclT,FieldT,MethodT> 46 implements ArrayInfo<TypeT,ClassDeclT>, Location { 47 48 private final NonElement<TypeT,ClassDeclT> itemType; 49 50 private final QName typeName; 51 52 /** 53 * The representation of T[] in the underlying reflection library. 54 */ 55 private final TypeT arrayType; 56 57 public ArrayInfoImpl(ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder, 58 Locatable upstream, TypeT arrayType) { 59 super(builder, upstream); 60 this.arrayType = arrayType; 61 TypeT componentType = nav().getComponentType(arrayType); 62 this.itemType = builder.getTypeInfo(componentType, this); 63 64 QName n = itemType.getTypeName(); 65 if(n==null) { 66 builder.reportError(new IllegalAnnotationException(Messages.ANONYMOUS_ARRAY_ITEM.format( 67 nav().getTypeName(componentType)),this)); 68 n = new QName("#dummy"); // for error recovery 69 } 70 this.typeName = ArrayInfoUtil.calcArrayTypeName(n); 71 } 72 73 public NonElement<TypeT, ClassDeclT> getItemType() { 74 return itemType; 75 } 76 77 public QName getTypeName() { 78 return typeName; 79 } 80 81 public boolean isSimpleType() { 82 return false; 83 } 84 85 public TypeT getType() { 86 return arrayType; 87 } 88 89 /** 90 * Leaf-type cannot be referenced from IDREF. 91 * 92 * @deprecated 93 * why are you calling a method whose return value is always known? 94 */ 95 public final boolean canBeReferencedByIDREF() { 96 return false; 97 } 98 99 public Location getLocation() { 100 return this; 101 } 102 public String toString() { 103 return nav().getTypeName(arrayType); 104 } 105} 106