001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.List;
023: import java.util.logging.Level;
024:
025: import javax.xml.namespace.QName;
026:
027: import org.w3c.dom.Element;
028:
029: import org.apache.cxf.service.model.InterfaceInfo;
030: import org.apache.cxf.service.model.OperationInfo;
031: import org.apache.cxf.service.model.ServiceInfo;
032: import org.apache.cxf.tools.common.ToolConstants;
033: import org.apache.cxf.tools.common.ToolContext;
034: import org.apache.cxf.tools.common.ToolException;
035: import org.apache.cxf.tools.common.model.JavaInterface;
036: import org.apache.cxf.tools.common.model.JavaModel;
037: import org.apache.cxf.tools.util.ClassCollector;
038: import org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding;
039: import org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.mapper.InterfaceMapper;
040:
041: public class PortTypeProcessor extends AbstractProcessor {
042: private List<QName> operationMap = new ArrayList<QName>();
043:
044: public PortTypeProcessor(ToolContext c) {
045: super (c);
046: }
047:
048: public void processClassNames(ServiceInfo serviceInfo)
049: throws ToolException {
050: InterfaceInfo interfaceInfo = serviceInfo.getInterface();
051: if (interfaceInfo == null) {
052: return;
053: }
054:
055: JavaInterface intf = new InterfaceMapper(context)
056: .map(interfaceInfo);
057:
058: JAXWSBinding jaxwsBinding = serviceInfo.getDescription()
059: .getExtensor(JAXWSBinding.class);
060: JAXWSBinding infBinding = interfaceInfo
061: .getExtensor(JAXWSBinding.class);
062: if (infBinding != null && infBinding.getPackage() != null) {
063: intf.setPackageName(infBinding.getPackage());
064: } else if (jaxwsBinding != null
065: && jaxwsBinding.getPackage() != null) {
066: intf.setPackageName(jaxwsBinding.getPackage());
067: }
068:
069: String name = intf.getName();
070: if (infBinding != null && infBinding.getJaxwsClass() != null
071: && infBinding.getJaxwsClass().getClassName() != null) {
072: name = infBinding.getJaxwsClass().getClassName();
073: }
074: intf.setName(name);
075:
076: ClassCollector collector = context.get(ClassCollector.class);
077: collector.addSeiClassName(intf.getPackageName(),
078: intf.getName(), intf.getPackageName() + "."
079: + intf.getName());
080: }
081:
082: public void process(ServiceInfo serviceInfo) throws ToolException {
083: operationMap.clear();
084: JavaModel jmodel = context.get(JavaModel.class);
085:
086: InterfaceInfo interfaceInfo = serviceInfo.getInterface();
087:
088: if (interfaceInfo == null) {
089: return;
090: }
091:
092: JavaInterface intf = new InterfaceMapper(context)
093: .map(interfaceInfo);
094: intf.setJavaModel(jmodel);
095:
096: JAXWSBinding jaxwsBinding = serviceInfo.getDescription()
097: .getExtensor(JAXWSBinding.class);
098: JAXWSBinding infBinding = interfaceInfo
099: .getExtensor(JAXWSBinding.class);
100: if (infBinding != null && infBinding.getPackage() != null) {
101: intf.setPackageName(infBinding.getPackage());
102: } else if (jaxwsBinding != null
103: && jaxwsBinding.getPackage() != null) {
104: intf.setPackageName(jaxwsBinding.getPackage());
105: }
106:
107: String name = intf.getName();
108: if (infBinding != null && infBinding.getJaxwsClass() != null
109: && infBinding.getJaxwsClass().getClassName() != null) {
110: name = infBinding.getJaxwsClass().getClassName();
111: }
112: intf.setName(name);
113:
114: Element handler = (Element) context
115: .get(ToolConstants.HANDLER_CHAIN);
116: intf.setHandlerChains(handler);
117:
118: Collection<OperationInfo> operations = interfaceInfo
119: .getOperations();
120:
121: for (OperationInfo operation : operations) {
122: if (isOverloading(operation.getName())) {
123: LOG.log(Level.WARNING, "SKIP_OVERLOADED_OPERATION",
124: operation.getName());
125: continue;
126: }
127: OperationProcessor operationProcessor = new OperationProcessor(
128: context);
129: operationProcessor.process(intf, operation);
130: }
131:
132: jmodel.setLocation(intf.getLocation());
133: jmodel.addInterface(intf.getName(), intf);
134: }
135:
136: private boolean isOverloading(QName operationName) {
137: if (operationMap.contains(operationName)) {
138: return true;
139: } else {
140: operationMap.add(operationName);
141: }
142: return false;
143: }
144:
145: }
|