325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.tools.internal.ws.processor.util;
325N/A
325N/Aimport com.sun.tools.internal.ws.processor.model.*;
325N/Aimport com.sun.tools.internal.ws.processor.model.java.JavaInterface;
325N/Aimport com.sun.tools.internal.ws.processor.model.jaxb.JAXBType;
325N/Aimport com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeVisitor;
325N/Aimport com.sun.tools.internal.ws.processor.model.jaxb.RpcLitStructure;
325N/A
325N/Aimport javax.xml.namespace.QName;
325N/Aimport java.util.HashSet;
325N/Aimport java.util.Iterator;
325N/Aimport java.util.Set;
325N/A
325N/A/**
325N/A * This class writes out a Model as an XML document.
325N/A *
325N/A * @author WS Development Team
325N/A */
325N/Apublic class ClassNameCollector extends ExtendedModelVisitor
325N/A implements JAXBTypeVisitor {
325N/A
325N/A public ClassNameCollector() {
325N/A }
325N/A
325N/A public void process(Model model) {
325N/A try {
325N/A _allClassNames = new HashSet();
325N/A _exceptions = new HashSet();
325N/A _wsdlBindingNames = new HashSet();
325N/A _conflictingClassNames = new HashSet();
325N/A _seiClassNames = new HashSet<String>();
325N/A _jaxbGeneratedClassNames = new HashSet<String>();
325N/A _exceptionClassNames = new HashSet<String>();
325N/A _portTypeNames = new HashSet<QName>();
325N/A visit(model);
325N/A } catch (Exception e) {
325N/A e.printStackTrace();
325N/A // fail silently
325N/A } finally {
325N/A _allClassNames = null;
325N/A _exceptions = null;
325N/A }
325N/A }
325N/A
325N/A public Set getConflictingClassNames() {
325N/A return _conflictingClassNames;
325N/A }
325N/A
325N/A protected void postVisit(Model model) throws Exception {
325N/A for (Iterator iter = model.getExtraTypes(); iter.hasNext();) {
325N/A visitType((AbstractType)iter.next());
325N/A }
325N/A }
325N/A
325N/A protected void preVisit(Service service) throws Exception {
325N/A registerClassName(
325N/A ((JavaInterface)service.getJavaInterface()).getName());
325N/A // We don't generate Impl classes, commenting it out.
325N/A // Otherwise, it would cause naming conflicts
325N/A //registerClassName(
325N/A // ((JavaInterface)service.getJavaInterface()).getImpl());
325N/A }
325N/A
325N/A protected void processPort11x(Port port){
325N/A QName wsdlBindingName = (QName) port.getProperty(
325N/A ModelProperties.PROPERTY_WSDL_BINDING_NAME);
325N/A if (!_wsdlBindingNames.contains(wsdlBindingName)) {
325N/A
325N/A // multiple ports can share a binding without causing a conflict
325N/A registerClassName(port.getJavaInterface().getName());
325N/A }
325N/A registerClassName((String) port.getProperty(
325N/A ModelProperties.PROPERTY_STUB_CLASS_NAME));
325N/A registerClassName((String) port.getProperty(
325N/A ModelProperties.PROPERTY_TIE_CLASS_NAME));
325N/A }
325N/A
325N/A protected void preVisit(Port port) throws Exception {
325N/A QName portTypeName = (QName)port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
325N/A if(_portTypeNames.contains(portTypeName))
325N/A return;
325N/A
325N/A //in 2.0, stub/tie class are binding agnostic so they should be per port, that is multiple
325N/A // bindings can share the same port
325N/A
325N/A addSEIClassName(port.getJavaInterface().getName());
325N/A }
325N/A
325N/A private void addSEIClassName(String s) {
325N/A _seiClassNames.add(s);
325N/A registerClassName(s);
325N/A }
325N/A
325N/A protected void postVisit(Port port) throws Exception {
325N/A QName wsdlBindingName = (QName) port.getProperty(
325N/A ModelProperties.PROPERTY_WSDL_BINDING_NAME);
325N/A if (!_wsdlBindingNames.contains(wsdlBindingName)) {
325N/A _wsdlBindingNames.add(wsdlBindingName);
325N/A }
325N/A
325N/A QName portTypeName = (QName)port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
325N/A if(!_portTypeNames.contains(portTypeName)){
325N/A _portTypeNames.add(portTypeName);
325N/A }
325N/A }
325N/A
325N/A protected boolean shouldVisit(Port port) {
325N/A QName wsdlBindingName = (QName) port.getProperty(
325N/A ModelProperties.PROPERTY_WSDL_BINDING_NAME);
325N/A return !_wsdlBindingNames.contains(wsdlBindingName);
325N/A }
325N/A
325N/A protected void preVisit(Fault fault) throws Exception {
325N/A if (!_exceptions.contains(fault.getJavaException())) {
325N/A
325N/A /* the same exception can be used in several faults, but that
325N/A * doesn't mean that there is a conflict
325N/A */
325N/A _exceptions.add(fault.getJavaException());
325N/A addExceptionClassName(fault.getJavaException().getName());
325N/A
325N/A if (fault.getParentFault() != null) {
325N/A preVisit(fault.getParentFault());
325N/A }
325N/A for (Iterator iter = fault.getSubfaults();
325N/A iter != null && iter.hasNext();) {
325N/A
325N/A Fault subfault = (Fault) iter.next();
325N/A preVisit(subfault);
325N/A }
325N/A }
325N/A }
325N/A
325N/A private void addExceptionClassName(String name) {
325N/A if(_allClassNames.contains(name))
325N/A _exceptionClassNames.add(name);
325N/A registerClassName(name);
325N/A //To change body of created methods use File | Settings | File Templates.
325N/A }
325N/A
325N/A protected void visitBodyBlock(Block block) throws Exception {
325N/A visitBlock(block);
325N/A }
325N/A
325N/A protected void visitHeaderBlock(Block block) throws Exception {
325N/A visitBlock(block);
325N/A }
325N/A
325N/A protected void visitFaultBlock(Block block) throws Exception {
325N/A }
325N/A
325N/A protected void visitBlock(Block block) throws Exception {
325N/A visitType(block.getType());
325N/A }
325N/A
325N/A protected void visit(Parameter parameter) throws Exception {
325N/A visitType(parameter.getType());
325N/A }
325N/A
325N/A private void visitType(AbstractType type) throws Exception {
325N/A if (type != null) {
325N/A if (type instanceof JAXBType)
325N/A visitType((JAXBType)type);
325N/A else if (type instanceof RpcLitStructure)
325N/A visitType((RpcLitStructure)type);
325N/A }
325N/A }
325N/A
325N/A
325N/A private void visitType(JAXBType type) throws Exception {
325N/A type.accept(this);
325N/A }
325N/A
325N/A private void visitType(RpcLitStructure type) throws Exception {
325N/A type.accept(this);
325N/A }
325N/A private void registerClassName(String name) {
325N/A if (name == null || name.equals("")) {
325N/A return;
325N/A }
325N/A if (_allClassNames.contains(name)) {
325N/A _conflictingClassNames.add(name);
325N/A } else {
325N/A _allClassNames.add(name);
325N/A }
325N/A }
325N/A
325N/A public Set<String> getSeiClassNames() {
325N/A return _seiClassNames;
325N/A }
325N/A
325N/A private Set<String> _seiClassNames;
325N/A
325N/A public Set<String> getJaxbGeneratedClassNames() {
325N/A return _jaxbGeneratedClassNames;
325N/A }
325N/A
325N/A private Set<String> _jaxbGeneratedClassNames;
325N/A
325N/A
325N/A public Set<String> getExceptionClassNames() {
325N/A return _exceptionClassNames;
325N/A }
325N/A
325N/A private Set<String> _exceptionClassNames;
325N/A boolean doneVisitingJAXBModel = false;
325N/A public void visit(JAXBType type) throws Exception {
325N/A if(!doneVisitingJAXBModel && type.getJaxbModel() != null){
325N/A Set<String> classNames = type.getJaxbModel().getGeneratedClassNames();
325N/A for(String className : classNames){
325N/A addJAXBGeneratedClassName(className);
325N/A }
325N/A doneVisitingJAXBModel = true;
325N/A }
325N/A }
325N/A
325N/A public void visit(RpcLitStructure type) throws Exception {
325N/A if(!doneVisitingJAXBModel){
325N/A Set<String> classNames = type.getJaxbModel().getGeneratedClassNames();
325N/A for(String className : classNames){
325N/A addJAXBGeneratedClassName(className);
325N/A }
325N/A doneVisitingJAXBModel = true;
325N/A }
325N/A }
325N/A
325N/A
325N/A private void addJAXBGeneratedClassName(String name) {
325N/A _jaxbGeneratedClassNames.add(name);
325N/A registerClassName(name);
325N/A }
325N/A
325N/A private Set _allClassNames;
325N/A private Set _exceptions;
325N/A private Set _wsdlBindingNames;
325N/A private Set _conflictingClassNames;
325N/A private Set<QName> _portTypeNames;
325N/A}