1 /* 2 * Copyright (c) 1997, 2012, 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 26 package com.sun.xml.internal.bind.v2.model.impl; 27 28 import java.util.HashMap; 29 import java.util.Map; 30 31 import javax.xml.namespace.QName; 32 33 import com.sun.xml.internal.bind.v2.model.core.BuiltinLeafInfo; 34 import com.sun.xml.internal.bind.v2.model.core.LeafInfo; 35 import com.sun.xml.internal.bind.v2.model.core.Element; 36 import com.sun.xml.internal.bind.v2.model.nav.Navigator; 37 38 /** 39 * JAXB spec designates a few Java classes to be mapped to XML types 40 * in a way that ignores restrictions placed on user-defined beans. 41 * 42 * @author Kohsuke Kawaguchi 43 */ 44 public class BuiltinLeafInfoImpl<TypeT,ClassDeclT> extends LeafInfoImpl<TypeT,ClassDeclT> implements BuiltinLeafInfo<TypeT,ClassDeclT> { 45 46 private final QName[] typeNames; 47 48 protected BuiltinLeafInfoImpl(TypeT type, QName... typeNames) { 49 super(type, typeNames.length>0?typeNames[0]:null); 50 this.typeNames = typeNames; 51 } 52 53 /** 54 * Returns all the type names recognized by this bean info. 55 * 56 * @return 57 * do not modify the returned array. 58 */ 59 public final QName[] getTypeNames() { 60 return typeNames; 61 } 62 63 /** 64 * @deprecated always return false at this level. 65 */ 66 public final boolean isElement() { 67 return false; 68 } 69 70 /** 71 * @deprecated always return null at this level. 72 */ 73 public final QName getElementName() { 74 return null; 75 } 76 77 /** 78 * @deprecated always return null at this level. 79 */ 80 public final Element<TypeT,ClassDeclT> asElement() { 81 return null; 82 } 83 84 /** 85 * Creates all the {@link BuiltinLeafInfoImpl}s as specified in the spec. 86 * 87 * {@link LeafInfo}s are all defined by the spec. 88 */ 89 public static <TypeT,ClassDeclT> 90 Map<TypeT,BuiltinLeafInfoImpl<TypeT,ClassDeclT>> createLeaves( Navigator<TypeT,ClassDeclT,?,?> nav ) { 91 Map<TypeT,BuiltinLeafInfoImpl<TypeT,ClassDeclT>> leaves = new HashMap<TypeT,BuiltinLeafInfoImpl<TypeT,ClassDeclT>>(); 92 93 for( RuntimeBuiltinLeafInfoImpl<?> leaf : RuntimeBuiltinLeafInfoImpl.builtinBeanInfos ) { 94 TypeT t = nav.ref(leaf.getClazz()); 95 leaves.put( t, new BuiltinLeafInfoImpl<TypeT,ClassDeclT>(t,leaf.getTypeNames()) ); 96 } 97 98 return leaves; 99 } 100 }