001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * 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, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.tomcat.common;
018:
019: import org.apache.naming.ResourceRef;
020: import org.apache.openejb.Injection;
021: import org.apache.openejb.core.ivm.naming.JaxWsServiceReference;
022: import org.apache.openejb.core.webservices.HandlerChainData;
023: import org.apache.openejb.core.webservices.PortRefData;
024: import static org.apache.openejb.tomcat.common.NamingUtil.JNDI_NAME;
025: import static org.apache.openejb.tomcat.common.NamingUtil.WSDL_URL;
026: import static org.apache.openejb.tomcat.common.NamingUtil.WS_CLASS;
027: import static org.apache.openejb.tomcat.common.NamingUtil.WS_ID;
028: import static org.apache.openejb.tomcat.common.NamingUtil.WS_PORT_QNAME;
029: import static org.apache.openejb.tomcat.common.NamingUtil.WS_QNAME;
030: import static org.apache.openejb.tomcat.common.NamingUtil.getProperty;
031: import static org.apache.openejb.tomcat.common.NamingUtil.getStaticValue;
032: import static org.apache.openejb.tomcat.common.NamingUtil.loadClass;
033:
034: import javax.naming.Context;
035: import javax.naming.Name;
036: import javax.naming.NamingException;
037: import javax.naming.Reference;
038: import javax.xml.namespace.QName;
039: import javax.xml.ws.Service;
040: import java.net.URL;
041: import java.util.Collections;
042: import java.util.Hashtable;
043: import java.util.List;
044:
045: public class WsFactory extends AbstractObjectFactory {
046: public Object getObjectInstance(Object object, Name name,
047: Context context, Hashtable environment) throws Exception {
048: // ignore non resource-refs
049: if (!(object instanceof ResourceRef)) {
050: return null;
051: }
052:
053: Reference ref = (Reference) object;
054:
055: Object value;
056: if (getProperty(ref, JNDI_NAME) != null) {
057: // lookup the value in JNDI
058: value = super .getObjectInstance(object, name, context,
059: environment);
060: } else {
061: // load service class which is used to construct the port
062: String serviceClassName = getProperty(ref, WS_CLASS);
063: Class<? extends Service> serviceClass = Service.class;
064: if (serviceClassName != null) {
065: serviceClass = loadClass(serviceClassName).asSubclass(
066: Service.class);
067: if (serviceClass == null) {
068: throw new NamingException(
069: "Could not load service type class "
070: + serviceClassName);
071: }
072: }
073:
074: // load the reference class which is the ultimate type of the port
075: Class<?> referenceClass = loadClass(ref.getClassName());
076:
077: // if ref class is a subclass of Service, use it for the service class
078: if (referenceClass != null
079: && Service.class.isAssignableFrom(referenceClass)) {
080: serviceClass = referenceClass.asSubclass(Service.class);
081: }
082:
083: // PORT ID
084: String serviceId = getProperty(ref, WS_ID);
085:
086: // Service QName
087: QName serviceQName = null;
088: if (getProperty(ref, WS_QNAME) != null) {
089: serviceQName = QName
090: .valueOf(getProperty(ref, WS_QNAME));
091: }
092:
093: // WSDL URL
094: URL wsdlUrl = null;
095: if (getProperty(ref, WSDL_URL) != null) {
096: wsdlUrl = new URL(getProperty(ref, WSDL_URL));
097: }
098:
099: // Port QName
100: QName portQName = null;
101: if (getProperty(ref, WS_PORT_QNAME) != null) {
102: portQName = QName.valueOf(getProperty(ref,
103: WS_PORT_QNAME));
104: }
105:
106: // port refs
107: List<PortRefData> portRefs = getStaticValue(ref,
108: "port-refs");
109: if (portRefs == null)
110: portRefs = Collections.emptyList();
111:
112: // HandlerChain
113: List<HandlerChainData> handlerChains = getStaticValue(ref,
114: "handler-chains");
115: if (handlerChains == null)
116: handlerChains = Collections.emptyList();
117: List<Injection> injections = getStaticValue(ref,
118: "injections");
119: if (injections == null)
120: injections = Collections.emptyList();
121:
122: JaxWsServiceReference serviceReference = new JaxWsServiceReference(
123: serviceId, serviceQName, serviceClass, portQName,
124: referenceClass, wsdlUrl, portRefs, handlerChains,
125: injections);
126: value = serviceReference.getObject();
127: }
128:
129: return value;
130: }
131:
132: protected String buildJndiName(Reference reference)
133: throws NamingException {
134: throw new UnsupportedOperationException();
135: }
136: }
|