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