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.wsdl11;
019:
020: import java.net.URL;
021: import java.util.Iterator;
022: import java.util.List;
023: import java.util.logging.Logger;
024:
025: import javax.wsdl.Definition;
026: import javax.wsdl.WSDLException;
027: import javax.xml.namespace.QName;
028:
029: import org.apache.cxf.Bus;
030: import org.apache.cxf.common.i18n.Message;
031: import org.apache.cxf.common.logging.LogUtils;
032: import org.apache.cxf.service.Service;
033: import org.apache.cxf.service.ServiceImpl;
034: import org.apache.cxf.service.factory.AbstractServiceFactoryBean;
035: import org.apache.cxf.service.factory.ServiceConstructionException;
036: import org.apache.cxf.service.model.ServiceInfo;
037: import org.apache.cxf.wsdl.WSDLManager;
038: import org.apache.ws.commons.schema.XmlSchemaException;
039:
040: public class WSDLServiceFactory extends AbstractServiceFactoryBean {
041:
042: private static final Logger LOG = LogUtils
043: .getL7dLogger(WSDLServiceFactory.class);
044:
045: private URL wsdlUrl;
046: private QName serviceName;
047: private Definition definition;
048:
049: public WSDLServiceFactory(Bus b, Definition d) {
050: setBus(b);
051: definition = d;
052: }
053:
054: public WSDLServiceFactory(Bus b, Definition d, QName sn) {
055: this (b, d);
056: serviceName = sn;
057: }
058:
059: public WSDLServiceFactory(Bus b, URL url) {
060: setBus(b);
061: wsdlUrl = url;
062:
063: try {
064: // use wsdl manager to parse wsdl or get cached definition
065: definition = getBus().getExtension(WSDLManager.class)
066: .getDefinition(wsdlUrl);
067: } catch (WSDLException ex) {
068: throw new ServiceConstructionException(new Message(
069: "SERVICE_CREATION_MSG", LOG), ex);
070: }
071:
072: }
073:
074: public WSDLServiceFactory(Bus b, URL url, QName sn) {
075: this (b, url);
076: serviceName = sn;
077: }
078:
079: public WSDLServiceFactory(Bus b, String url, QName sn) {
080: setBus(b);
081: try {
082: // use wsdl manager to parse wsdl or get cached definition
083: definition = getBus().getExtension(WSDLManager.class)
084: .getDefinition(url);
085: } catch (WSDLException ex) {
086: throw new ServiceConstructionException(new Message(
087: "SERVICE_CREATION_MSG", LOG), ex);
088: }
089:
090: serviceName = sn;
091: }
092:
093: public Service create() {
094:
095: List<ServiceInfo> services;
096: if (serviceName == null) {
097: try {
098: services = new WSDLServiceBuilder(getBus())
099: .buildServices(definition);
100: } catch (XmlSchemaException ex) {
101: throw new ServiceConstructionException(new Message(
102: "SERVICE_CREATION_MSG", LOG), ex);
103: }
104: if (services.size() == 0) {
105: throw new ServiceConstructionException(new Message(
106: "NO_SERVICE_EXC", LOG));
107: } else {
108: //@@TODO - this isn't good, need to return all the services
109: serviceName = services.get(0).getName();
110: //get all the service info's that match that first one.
111: Iterator<ServiceInfo> it = services.iterator();
112: while (it.hasNext()) {
113: if (!it.next().getName().equals(serviceName)) {
114: it.remove();
115: }
116: }
117: }
118: } else {
119: javax.wsdl.Service wsdlService = definition
120: .getService(serviceName);
121: if (wsdlService == null) {
122: throw new ServiceConstructionException(new Message(
123: "NO_SUCH_SERVICE_EXC", LOG, serviceName));
124: }
125: try {
126: services = new WSDLServiceBuilder(getBus())
127: .buildServices(definition, wsdlService);
128: } catch (XmlSchemaException ex) {
129: throw new ServiceConstructionException(new Message(
130: "SERVICE_CREATION_MSG", LOG), ex);
131: }
132: }
133: ServiceImpl service = new ServiceImpl(services);
134: setService(service);
135: return service;
136: }
137:
138: }
|