Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
ohair@286 | 1 | /* |
ohair@286 | 2 | * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package com.sun.tools.internal.ws.processor.util; |
ohair@286 | 27 | |
ohair@286 | 28 | import com.sun.tools.internal.ws.processor.model.*; |
ohair@286 | 29 | import com.sun.tools.internal.ws.processor.model.java.JavaInterface; |
ohair@286 | 30 | import com.sun.tools.internal.ws.processor.model.jaxb.JAXBType; |
ohair@286 | 31 | import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeVisitor; |
ohair@286 | 32 | import com.sun.tools.internal.ws.processor.model.jaxb.RpcLitStructure; |
ohair@286 | 33 | |
ohair@286 | 34 | import javax.xml.namespace.QName; |
ohair@286 | 35 | import java.util.HashSet; |
ohair@286 | 36 | import java.util.Iterator; |
ohair@286 | 37 | import java.util.Set; |
ohair@286 | 38 | |
ohair@286 | 39 | /** |
ohair@286 | 40 | * This class writes out a Model as an XML document. |
ohair@286 | 41 | * |
ohair@286 | 42 | * @author WS Development Team |
ohair@286 | 43 | */ |
ohair@286 | 44 | public class ClassNameCollector extends ExtendedModelVisitor |
ohair@286 | 45 | implements JAXBTypeVisitor { |
ohair@286 | 46 | |
ohair@286 | 47 | public ClassNameCollector() { |
ohair@286 | 48 | } |
ohair@286 | 49 | |
ohair@286 | 50 | public void process(Model model) { |
ohair@286 | 51 | try { |
ohair@286 | 52 | _allClassNames = new HashSet(); |
ohair@286 | 53 | _exceptions = new HashSet(); |
ohair@286 | 54 | _wsdlBindingNames = new HashSet(); |
ohair@286 | 55 | _conflictingClassNames = new HashSet(); |
ohair@286 | 56 | _seiClassNames = new HashSet<String>(); |
ohair@286 | 57 | _jaxbGeneratedClassNames = new HashSet<String>(); |
ohair@286 | 58 | _exceptionClassNames = new HashSet<String>(); |
ohair@286 | 59 | _portTypeNames = new HashSet<QName>(); |
ohair@286 | 60 | visit(model); |
ohair@286 | 61 | } catch (Exception e) { |
ohair@286 | 62 | e.printStackTrace(); |
ohair@286 | 63 | // fail silently |
ohair@286 | 64 | } finally { |
ohair@286 | 65 | _allClassNames = null; |
ohair@286 | 66 | _exceptions = null; |
ohair@286 | 67 | } |
ohair@286 | 68 | } |
ohair@286 | 69 | |
ohair@286 | 70 | public Set getConflictingClassNames() { |
ohair@286 | 71 | return _conflictingClassNames; |
ohair@286 | 72 | } |
ohair@286 | 73 | |
ohair@286 | 74 | protected void postVisit(Model model) throws Exception { |
ohair@286 | 75 | for (Iterator iter = model.getExtraTypes(); iter.hasNext();) { |
ohair@286 | 76 | visitType((AbstractType)iter.next()); |
ohair@286 | 77 | } |
ohair@286 | 78 | } |
ohair@286 | 79 | |
ohair@286 | 80 | protected void preVisit(Service service) throws Exception { |
ohair@286 | 81 | registerClassName( |
ohair@286 | 82 | ((JavaInterface)service.getJavaInterface()).getName()); |
ohair@286 | 83 | // We don't generate Impl classes, commenting it out. |
ohair@286 | 84 | // Otherwise, it would cause naming conflicts |
ohair@286 | 85 | //registerClassName( |
ohair@286 | 86 | // ((JavaInterface)service.getJavaInterface()).getImpl()); |
ohair@286 | 87 | } |
ohair@286 | 88 | |
ohair@286 | 89 | protected void processPort11x(Port port){ |
ohair@286 | 90 | QName wsdlBindingName = (QName) port.getProperty( |
ohair@286 | 91 | ModelProperties.PROPERTY_WSDL_BINDING_NAME); |
ohair@286 | 92 | if (!_wsdlBindingNames.contains(wsdlBindingName)) { |
ohair@286 | 93 | |
ohair@286 | 94 | // multiple ports can share a binding without causing a conflict |
ohair@286 | 95 | registerClassName(port.getJavaInterface().getName()); |
ohair@286 | 96 | } |
ohair@286 | 97 | registerClassName((String) port.getProperty( |
ohair@286 | 98 | ModelProperties.PROPERTY_STUB_CLASS_NAME)); |
ohair@286 | 99 | registerClassName((String) port.getProperty( |
ohair@286 | 100 | ModelProperties.PROPERTY_TIE_CLASS_NAME)); |
ohair@286 | 101 | } |
ohair@286 | 102 | |
ohair@286 | 103 | protected void preVisit(Port port) throws Exception { |
ohair@286 | 104 | QName portTypeName = (QName)port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME); |
ohair@286 | 105 | if(_portTypeNames.contains(portTypeName)) |
ohair@286 | 106 | return; |
ohair@286 | 107 | |
ohair@286 | 108 | //in 2.0, stub/tie class are binding agnostic so they should be per port, that is multiple |
ohair@286 | 109 | // bindings can share the same port |
ohair@286 | 110 | |
ohair@286 | 111 | addSEIClassName(port.getJavaInterface().getName()); |
ohair@286 | 112 | } |
ohair@286 | 113 | |
ohair@286 | 114 | private void addSEIClassName(String s) { |
ohair@286 | 115 | _seiClassNames.add(s); |
ohair@286 | 116 | registerClassName(s); |
ohair@286 | 117 | } |
ohair@286 | 118 | |
ohair@286 | 119 | protected void postVisit(Port port) throws Exception { |
ohair@286 | 120 | QName wsdlBindingName = (QName) port.getProperty( |
ohair@286 | 121 | ModelProperties.PROPERTY_WSDL_BINDING_NAME); |
ohair@286 | 122 | if (!_wsdlBindingNames.contains(wsdlBindingName)) { |
ohair@286 | 123 | _wsdlBindingNames.add(wsdlBindingName); |
ohair@286 | 124 | } |
ohair@286 | 125 | |
ohair@286 | 126 | QName portTypeName = (QName)port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME); |
ohair@286 | 127 | if(!_portTypeNames.contains(portTypeName)){ |
ohair@286 | 128 | _portTypeNames.add(portTypeName); |
ohair@286 | 129 | } |
ohair@286 | 130 | } |
ohair@286 | 131 | |
ohair@286 | 132 | protected boolean shouldVisit(Port port) { |
ohair@286 | 133 | QName wsdlBindingName = (QName) port.getProperty( |
ohair@286 | 134 | ModelProperties.PROPERTY_WSDL_BINDING_NAME); |
ohair@286 | 135 | return !_wsdlBindingNames.contains(wsdlBindingName); |
ohair@286 | 136 | } |
ohair@286 | 137 | |
ohair@286 | 138 | protected void preVisit(Fault fault) throws Exception { |
ohair@286 | 139 | if (!_exceptions.contains(fault.getJavaException())) { |
ohair@286 | 140 | |
ohair@286 | 141 | /* the same exception can be used in several faults, but that |
ohair@286 | 142 | * doesn't mean that there is a conflict |
ohair@286 | 143 | */ |
ohair@286 | 144 | _exceptions.add(fault.getJavaException()); |
ohair@286 | 145 | addExceptionClassName(fault.getJavaException().getName()); |
ohair@286 | 146 | |
ohair@286 | 147 | if (fault.getParentFault() != null) { |
ohair@286 | 148 | preVisit(fault.getParentFault()); |
ohair@286 | 149 | } |
ohair@286 | 150 | for (Iterator iter = fault.getSubfaults(); |
ohair@286 | 151 | iter != null && iter.hasNext();) { |
ohair@286 | 152 | |
ohair@286 | 153 | Fault subfault = (Fault) iter.next(); |
ohair@286 | 154 | preVisit(subfault); |
ohair@286 | 155 | } |
ohair@286 | 156 | } |
ohair@286 | 157 | } |
ohair@286 | 158 | |
ohair@286 | 159 | private void addExceptionClassName(String name) { |
ohair@286 | 160 | if(_allClassNames.contains(name)) |
ohair@286 | 161 | _exceptionClassNames.add(name); |
ohair@286 | 162 | registerClassName(name); |
ohair@286 | 163 | //To change body of created methods use File | Settings | File Templates. |
ohair@286 | 164 | } |
ohair@286 | 165 | |
ohair@286 | 166 | protected void visitBodyBlock(Block block) throws Exception { |
ohair@286 | 167 | visitBlock(block); |
ohair@286 | 168 | } |
ohair@286 | 169 | |
ohair@286 | 170 | protected void visitHeaderBlock(Block block) throws Exception { |
ohair@286 | 171 | visitBlock(block); |
ohair@286 | 172 | } |
ohair@286 | 173 | |
ohair@286 | 174 | protected void visitFaultBlock(Block block) throws Exception { |
ohair@286 | 175 | } |
ohair@286 | 176 | |
ohair@286 | 177 | protected void visitBlock(Block block) throws Exception { |
ohair@286 | 178 | visitType(block.getType()); |
ohair@286 | 179 | } |
ohair@286 | 180 | |
ohair@286 | 181 | protected void visit(Parameter parameter) throws Exception { |
ohair@286 | 182 | visitType(parameter.getType()); |
ohair@286 | 183 | } |
ohair@286 | 184 | |
ohair@286 | 185 | private void visitType(AbstractType type) throws Exception { |
ohair@286 | 186 | if (type != null) { |
ohair@286 | 187 | if (type instanceof JAXBType) |
ohair@286 | 188 | visitType((JAXBType)type); |
ohair@286 | 189 | else if (type instanceof RpcLitStructure) |
ohair@286 | 190 | visitType((RpcLitStructure)type); |
ohair@286 | 191 | } |
ohair@286 | 192 | } |
ohair@286 | 193 | |
ohair@286 | 194 | |
ohair@286 | 195 | private void visitType(JAXBType type) throws Exception { |
ohair@286 | 196 | type.accept(this); |
ohair@286 | 197 | } |
ohair@286 | 198 | |
ohair@286 | 199 | private void visitType(RpcLitStructure type) throws Exception { |
ohair@286 | 200 | type.accept(this); |
ohair@286 | 201 | } |
ohair@286 | 202 | private void registerClassName(String name) { |
ohair@286 | 203 | if (name == null || name.equals("")) { |
ohair@286 | 204 | return; |
ohair@286 | 205 | } |
ohair@286 | 206 | if (_allClassNames.contains(name)) { |
ohair@286 | 207 | _conflictingClassNames.add(name); |
ohair@286 | 208 | } else { |
ohair@286 | 209 | _allClassNames.add(name); |
ohair@286 | 210 | } |
ohair@286 | 211 | } |
ohair@286 | 212 | |
ohair@286 | 213 | public Set<String> getSeiClassNames() { |
ohair@286 | 214 | return _seiClassNames; |
ohair@286 | 215 | } |
ohair@286 | 216 | |
ohair@286 | 217 | private Set<String> _seiClassNames; |
ohair@286 | 218 | |
ohair@286 | 219 | public Set<String> getJaxbGeneratedClassNames() { |
ohair@286 | 220 | return _jaxbGeneratedClassNames; |
ohair@286 | 221 | } |
ohair@286 | 222 | |
ohair@286 | 223 | private Set<String> _jaxbGeneratedClassNames; |
ohair@286 | 224 | |
ohair@286 | 225 | |
ohair@286 | 226 | public Set<String> getExceptionClassNames() { |
ohair@286 | 227 | return _exceptionClassNames; |
ohair@286 | 228 | } |
ohair@286 | 229 | |
ohair@286 | 230 | private Set<String> _exceptionClassNames; |
ohair@286 | 231 | boolean doneVisitingJAXBModel = false; |
ohair@286 | 232 | public void visit(JAXBType type) throws Exception { |
ohair@286 | 233 | if(!doneVisitingJAXBModel && type.getJaxbModel() != null){ |
ohair@286 | 234 | Set<String> classNames = type.getJaxbModel().getGeneratedClassNames(); |
ohair@286 | 235 | for(String className : classNames){ |
ohair@286 | 236 | addJAXBGeneratedClassName(className); |
ohair@286 | 237 | } |
ohair@286 | 238 | doneVisitingJAXBModel = true; |
ohair@286 | 239 | } |
ohair@286 | 240 | } |
ohair@286 | 241 | |
ohair@286 | 242 | public void visit(RpcLitStructure type) throws Exception { |
ohair@286 | 243 | if(!doneVisitingJAXBModel){ |
ohair@286 | 244 | Set<String> classNames = type.getJaxbModel().getGeneratedClassNames(); |
ohair@286 | 245 | for(String className : classNames){ |
ohair@286 | 246 | addJAXBGeneratedClassName(className); |
ohair@286 | 247 | } |
ohair@286 | 248 | doneVisitingJAXBModel = true; |
ohair@286 | 249 | } |
ohair@286 | 250 | } |
ohair@286 | 251 | |
ohair@286 | 252 | |
ohair@286 | 253 | private void addJAXBGeneratedClassName(String name) { |
ohair@286 | 254 | _jaxbGeneratedClassNames.add(name); |
ohair@286 | 255 | registerClassName(name); |
ohair@286 | 256 | } |
ohair@286 | 257 | |
ohair@286 | 258 | private Set _allClassNames; |
ohair@286 | 259 | private Set _exceptions; |
ohair@286 | 260 | private Set _wsdlBindingNames; |
ohair@286 | 261 | private Set _conflictingClassNames; |
ohair@286 | 262 | private Set<QName> _portTypeNames; |
ohair@286 | 263 | } |