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.tools.internal.ws.processor.model.jaxb; 27 28 import com.sun.tools.internal.xjc.api.J2SJAXBModel; 29 import com.sun.tools.internal.xjc.api.Mapping; 30 import com.sun.tools.internal.xjc.api.S2JJAXBModel; 31 32 import javax.xml.namespace.QName; 33 import java.util.*; 34 35 /** 36 * Root of the JAXB Model. 37 * 38 * <p> 39 * This is just a wrapper around a list of {@link JAXBMapping}s. 40 * 41 * @author Kohsuke Kawaguchi, Vivek Pandey 42 */ 43 public class JAXBModel { 44 45 /** 46 * All the mappings known to this model. 47 */ 48 private List<JAXBMapping> mappings; 49 50 // index for faster access. 51 private final Map<QName,JAXBMapping> byQName = new HashMap<QName,JAXBMapping>(); 52 private final Map<String,JAXBMapping> byClassName = new HashMap<String,JAXBMapping>(); 53 54 private com.sun.tools.internal.xjc.api.JAXBModel rawJAXBModel; 55 56 public com.sun.tools.internal.xjc.api.JAXBModel getRawJAXBModel() { 57 return rawJAXBModel; 58 } 59 60 /** 61 * @return Schema to Java model 62 */ 63 public S2JJAXBModel getS2JJAXBModel(){ 64 if(rawJAXBModel instanceof S2JJAXBModel) 65 return (S2JJAXBModel)rawJAXBModel; 66 return null; 67 } 68 69 /** 70 * @return Java to Schema JAXBModel 71 */ 72 public J2SJAXBModel getJ2SJAXBModel(){ 73 if(rawJAXBModel instanceof J2SJAXBModel) 74 return (J2SJAXBModel)rawJAXBModel; 75 return null; 76 } 77 78 79 /** 80 * Default constructor for the persistence. 81 */ 82 public JAXBModel() {} 83 84 /** 85 * Constructor that fills in the values from the given raw model 86 */ 87 public JAXBModel( com.sun.tools.internal.xjc.api.JAXBModel rawModel ) { 88 this.rawJAXBModel = rawModel; 89 if(rawModel instanceof S2JJAXBModel){ 90 S2JJAXBModel model = (S2JJAXBModel)rawModel; 91 List<JAXBMapping> ms = new ArrayList<JAXBMapping>(model.getMappings().size()); 92 for( Mapping m : model.getMappings()) 93 ms.add(new JAXBMapping(m)); 94 setMappings(ms); 95 } 96 } 97 98 /** 99 */ 100 public List<JAXBMapping> getMappings() { 101 return mappings; 102 } 103 104 //public void setMappings(List<JAXBMapping> mappings) { 105 public void setMappings(List<JAXBMapping> mappings) { 106 this.mappings = mappings; 107 byQName.clear(); 108 byClassName.clear(); 109 for( JAXBMapping m : mappings ) { 110 byQName.put(m.getElementName(),m); 111 byClassName.put(m.getType().getName(),m); 112 } 113 } 114 115 /** 116 */ 117 public JAXBMapping get( QName elementName ) { 118 return byQName.get(elementName); 119 } 120 121 /** 122 */ 123 public JAXBMapping get( String className ) { 124 return byClassName.get(className); 125 } 126 127 128 /** 129 * 130 * @return set of full qualified class names that jaxb will generate 131 */ 132 public Set<String> getGeneratedClassNames() { 133 return generatedClassNames; 134 } 135 136 public void setGeneratedClassNames(Set<String> generatedClassNames) { 137 this.generatedClassNames = generatedClassNames; 138 } 139 140 private Set<String> generatedClassNames; 141 }