001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.cxf.builder;
017:
018: import java.io.IOException;
019: import java.io.StringWriter;
020: import java.net.URI;
021: import java.util.Map;
022:
023: import javax.xml.namespace.QName;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.apache.geronimo.common.DeploymentException;
028: import org.apache.geronimo.cxf.client.CXFServiceReference;
029: import org.apache.geronimo.gbean.GBeanInfo;
030: import org.apache.geronimo.gbean.GBeanInfoBuilder;
031: import org.apache.geronimo.j2ee.deployment.Module;
032: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
033: import org.apache.geronimo.jaxws.builder.EndpointInfoBuilder;
034: import org.apache.geronimo.jaxws.builder.JAXWSServiceRefBuilder;
035: import org.apache.geronimo.jaxws.client.EndpointInfo;
036: import org.apache.geronimo.kernel.repository.Environment;
037: import org.apache.geronimo.naming.deployment.ServiceRefBuilder;
038: import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
039: import org.apache.geronimo.xbeans.javaee.PortComponentRefType;
040: import org.apache.geronimo.xbeans.javaee.ServiceRefHandlerChainsType;
041: import org.apache.geronimo.xbeans.javaee.ServiceRefType;
042: import org.apache.xmlbeans.XmlOptions;
043:
044: public class CXFServiceRefBuilder extends JAXWSServiceRefBuilder {
045:
046: private static final Log LOG = LogFactory
047: .getLog(CXFServiceRefBuilder.class);
048:
049: public CXFServiceRefBuilder(Environment defaultEnvironment,
050: String[] eeNamespaces) {
051: super (defaultEnvironment, eeNamespaces);
052: }
053:
054: public Object createService(ServiceRefType serviceRef,
055: GerServiceRefType gerServiceRef, Module module,
056: ClassLoader cl, Class serviceInterface, QName serviceQName,
057: URI wsdlURI, Class serviceReference,
058: Map<Class, PortComponentRefType> portComponentRefMap)
059: throws DeploymentException {
060: EndpointInfoBuilder builder = new EndpointInfoBuilder(
061: serviceInterface, gerServiceRef, portComponentRefMap,
062: module.getModuleFile(), wsdlURI, serviceQName);
063: builder.build();
064:
065: wsdlURI = builder.getWsdlURI();
066: serviceQName = builder.getServiceQName();
067: Map<Object, EndpointInfo> seiInfoMap = builder
068: .getEndpointInfo();
069:
070: String handlerChainsXML = null;
071: try {
072: handlerChainsXML = getHandlerChainAsString(serviceRef
073: .getHandlerChains());
074: } catch (IOException e) {
075: // this should not happen
076: LOG.warn("Failed to serialize handler chains", e);
077: }
078:
079: String serviceReferenceName = (serviceReference == null) ? null
080: : serviceReference.getName();
081:
082: return new CXFServiceReference(serviceInterface.getName(),
083: serviceReferenceName, wsdlURI, serviceQName, module
084: .getModuleName(), handlerChainsXML, seiInfoMap);
085: }
086:
087: private static String getHandlerChainAsString(
088: ServiceRefHandlerChainsType handlerChains)
089: throws IOException {
090: String xml = null;
091: if (handlerChains != null) {
092: StringWriter w = new StringWriter();
093: XmlOptions options = new XmlOptions();
094: options.setSaveSyntheticDocumentElement(new QName(
095: "http://java.sun.com/xml/ns/javaee",
096: "handler-chains"));
097: handlerChains.save(w, options);
098: xml = w.toString();
099: }
100: return xml;
101: }
102:
103: public static final GBeanInfo GBEAN_INFO;
104:
105: static {
106: GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
107: CXFServiceRefBuilder.class, NameFactory.MODULE_BUILDER);
108: infoBuilder.addInterface(ServiceRefBuilder.class);
109: infoBuilder.addAttribute("defaultEnvironment",
110: Environment.class, true, true);
111: infoBuilder.addAttribute("eeNamespaces", String[].class, true,
112: true);
113:
114: infoBuilder.setConstructor(new String[] { "defaultEnvironment",
115: "eeNamespaces" });
116:
117: GBEAN_INFO = infoBuilder.getBeanInfo();
118: }
119:
120: public static GBeanInfo getGBeanInfo() {
121: return GBEAN_INFO;
122: }
123: }
|