src/share/jaxws_classes/com/sun/tools/internal/ws/processor/util/ClassNameCollector.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, 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 for (Iterator iter = fault.getSubfaults();
ohair@286 148 iter != null && iter.hasNext();) {
ohair@286 149
ohair@286 150 Fault subfault = (Fault) iter.next();
ohair@286 151 preVisit(subfault);
ohair@286 152 }
ohair@286 153 }
ohair@286 154 }
ohair@286 155
ohair@286 156 private void addExceptionClassName(String name) {
ohair@286 157 if(_allClassNames.contains(name))
ohair@286 158 _exceptionClassNames.add(name);
ohair@286 159 registerClassName(name);
ohair@286 160 //To change body of created methods use File | Settings | File Templates.
ohair@286 161 }
ohair@286 162
ohair@286 163 protected void visitBodyBlock(Block block) throws Exception {
ohair@286 164 visitBlock(block);
ohair@286 165 }
ohair@286 166
ohair@286 167 protected void visitHeaderBlock(Block block) throws Exception {
ohair@286 168 visitBlock(block);
ohair@286 169 }
ohair@286 170
ohair@286 171 protected void visitFaultBlock(Block block) throws Exception {
ohair@286 172 }
ohair@286 173
ohair@286 174 protected void visitBlock(Block block) throws Exception {
ohair@286 175 visitType(block.getType());
ohair@286 176 }
ohair@286 177
ohair@286 178 protected void visit(Parameter parameter) throws Exception {
ohair@286 179 visitType(parameter.getType());
ohair@286 180 }
ohair@286 181
ohair@286 182 private void visitType(AbstractType type) throws Exception {
ohair@286 183 if (type != null) {
ohair@286 184 if (type instanceof JAXBType)
ohair@286 185 visitType((JAXBType)type);
ohair@286 186 else if (type instanceof RpcLitStructure)
ohair@286 187 visitType((RpcLitStructure)type);
ohair@286 188 }
ohair@286 189 }
ohair@286 190
ohair@286 191
ohair@286 192 private void visitType(JAXBType type) throws Exception {
ohair@286 193 type.accept(this);
ohair@286 194 }
ohair@286 195
ohair@286 196 private void visitType(RpcLitStructure type) throws Exception {
ohair@286 197 type.accept(this);
ohair@286 198 }
ohair@286 199 private void registerClassName(String name) {
ohair@286 200 if (name == null || name.equals("")) {
ohair@286 201 return;
ohair@286 202 }
ohair@286 203 if (_allClassNames.contains(name)) {
ohair@286 204 _conflictingClassNames.add(name);
ohair@286 205 } else {
ohair@286 206 _allClassNames.add(name);
ohair@286 207 }
ohair@286 208 }
ohair@286 209
ohair@286 210 public Set<String> getSeiClassNames() {
ohair@286 211 return _seiClassNames;
ohair@286 212 }
ohair@286 213
ohair@286 214 private Set<String> _seiClassNames;
ohair@286 215
ohair@286 216 public Set<String> getJaxbGeneratedClassNames() {
ohair@286 217 return _jaxbGeneratedClassNames;
ohair@286 218 }
ohair@286 219
ohair@286 220 private Set<String> _jaxbGeneratedClassNames;
ohair@286 221
ohair@286 222
ohair@286 223 public Set<String> getExceptionClassNames() {
ohair@286 224 return _exceptionClassNames;
ohair@286 225 }
ohair@286 226
ohair@286 227 private Set<String> _exceptionClassNames;
ohair@286 228 boolean doneVisitingJAXBModel = false;
ohair@286 229 public void visit(JAXBType type) throws Exception {
ohair@286 230 if(!doneVisitingJAXBModel && type.getJaxbModel() != null){
ohair@286 231 Set<String> classNames = type.getJaxbModel().getGeneratedClassNames();
ohair@286 232 for(String className : classNames){
ohair@286 233 addJAXBGeneratedClassName(className);
ohair@286 234 }
ohair@286 235 doneVisitingJAXBModel = true;
ohair@286 236 }
ohair@286 237 }
ohair@286 238
ohair@286 239 public void visit(RpcLitStructure type) throws Exception {
ohair@286 240 if(!doneVisitingJAXBModel){
ohair@286 241 Set<String> classNames = type.getJaxbModel().getGeneratedClassNames();
ohair@286 242 for(String className : classNames){
ohair@286 243 addJAXBGeneratedClassName(className);
ohair@286 244 }
ohair@286 245 doneVisitingJAXBModel = true;
ohair@286 246 }
ohair@286 247 }
ohair@286 248
ohair@286 249
ohair@286 250 private void addJAXBGeneratedClassName(String name) {
ohair@286 251 _jaxbGeneratedClassNames.add(name);
ohair@286 252 registerClassName(name);
ohair@286 253 }
ohair@286 254
ohair@286 255 private Set _allClassNames;
ohair@286 256 private Set _exceptions;
ohair@286 257 private Set _wsdlBindingNames;
ohair@286 258 private Set _conflictingClassNames;
ohair@286 259 private Set<QName> _portTypeNames;
ohair@286 260 }

mercurial