KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > ServiceReferenceNode


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * ServiceReferenceNode.java
26  *
27  * Created on March 21, 2002, 2:38 PM
28  */

29
30 package com.sun.enterprise.deployment.node;
31
32 import java.util.*;
33 import java.util.logging.Level JavaDoc;
34 import org.w3c.dom.Node JavaDoc;
35
36 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
37 import com.sun.enterprise.deployment.xml.TagNames;
38 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
39 import com.sun.enterprise.deployment.ServiceRefPortInfo;
40 import com.sun.enterprise.deployment.InjectionTarget;
41 import com.sun.enterprise.deployment.util.DOLUtils;
42 import javax.xml.namespace.QName JavaDoc;
43
44 /**
45  * This node is responsible for loading web services
46  * reference information
47  *
48  * @author Kenneth Saks
49  */

50 public class ServiceReferenceNode extends DisplayableComponentNode {
51     // used for temporary storage during element processing
52
private String JavaDoc serviceEndpointInterface = null;
53     private ServiceRefPortInfo portInfo = null;
54
55     /** Creates a new instance of ServiceReferenceNode */
56     public ServiceReferenceNode() {
57         super();
58         registerElementHandler
59             (new XMLElement(WebServicesTagNames.HANDLER),
60              WebServiceHandlerNode.class, "addHandler");
61         registerElementHandler
62             (new XMLElement(WebServicesTagNames.HANDLER_CHAIN),
63              WebServiceHandlerChainNode.class, "addHandlerChain");
64         registerElementHandler
65             (new XMLElement(TagNames.INJECTION_TARGET),
66              InjectionTargetNode.class, "addInjectionTarget");
67     }
68     
69     /**
70      * all sub-implementation of this class can use a dispatch table
71      * to map xml element to method name on the descriptor class for
72      * setting the element value.
73      *
74      * @return map with the element name as a key, the setter method as a value
75      */

76     protected Map getDispatchTable() {
77         Map table = super.getDispatchTable();
78         table.put(WebServicesTagNames.SERVICE_REF_NAME, "setName");
79         table.put(WebServicesTagNames.SERVICE_INTERFACE, "setServiceInterface");
80         table.put(WebServicesTagNames.WSDL_FILE, "setWsdlFileUri");
81         table.put(WebServicesTagNames.JAXRPC_MAPPING_FILE, "setMappingFileUri");
82         table.put(WebServicesTagNames.MAPPED_NAME, "setMappedName");
83         table.put(WebServicesTagNames.SERVICE_REF_TYPE, "setInjectionTargetType");
84         return table;
85     }
86
87     private ServiceReferenceDescriptor getServiceReferenceDescriptor() {
88         return (ServiceReferenceDescriptor) getDescriptor();
89     }
90
91     /**
92      * receives notiification of the value for a particular tag
93      *
94      * @param element the xml element
95      * @param value it's associated value
96      */

97     public void setElementValue(XMLElement element, String JavaDoc value) {
98         String JavaDoc qname = element.getQName();
99         if (WebServicesTagNames.SERVICE_ENDPOINT_INTERFACE.equals(qname)) {
100             portInfo = getServiceReferenceDescriptor().getPortInfoBySEI(value);
101             if( portInfo == null ) {
102                 portInfo = getServiceReferenceDescriptor().
103                     addContainerManagedPort(value);
104             }
105         } else if( WebServicesTagNames.SERVICE_QNAME.equals(qname) ) {
106             String JavaDoc prefix = getPrefixFromQName(value);
107             String JavaDoc localPart = getLocalPartFromQName(value);
108             String JavaDoc namespaceUri = resolvePrefix(element, prefix);
109             if( namespaceUri == null) {
110                 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorMappingFailure",
111                     new Object JavaDoc[] { prefix , getServiceReferenceDescriptor().getName()});
112             } else {
113                 QName JavaDoc serviceName = new QName JavaDoc(namespaceUri, localPart);
114                 getServiceReferenceDescriptor().setServiceName
115                     (serviceName, prefix);
116             }
117         } else if(WebServicesTagNames.ENABLE_MTOM.equals(qname)) {
118             portInfo.setMtomEnabled(value);
119         } else if( WebServicesTagNames.PORT_COMPONENT_LINK.equals(qname) ) {
120             // set link name. link resolution will be performed during
121
// validation stage.
122
portInfo.setPortComponentLinkName(value);
123             portInfo = null;
124         } else {
125             super.setElementValue(element, value);
126         }
127     }
128     
129     /**
130      * write the method descriptor class to a query-method DOM tree and
131      * return it
132      *
133      * @param parent node in the DOM tree
134      * @param node name for the root element of this xml fragment
135      * @param the descriptor to write
136      * @return the DOM tree top node
137      */

138     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName,
139                                 ServiceReferenceDescriptor descriptor) {
140         Node JavaDoc serviceRefNode =
141             super.writeDescriptor(parent, nodeName, descriptor);
142
143         writeDisplayableComponentInfo(serviceRefNode, descriptor);
144         appendTextChild(serviceRefNode, WebServicesTagNames.SERVICE_REF_NAME,
145                         descriptor.getName());
146         appendTextChild(serviceRefNode, WebServicesTagNames.SERVICE_INTERFACE,
147                         descriptor.getServiceInterface());
148         appendTextChild(serviceRefNode, WebServicesTagNames.SERVICE_REF_TYPE,
149                 descriptor.getInjectionTargetType());
150         appendTextChild(serviceRefNode, WebServicesTagNames.WSDL_FILE,
151                         descriptor.getWsdlFileUri());
152         appendTextChild(serviceRefNode, WebServicesTagNames.JAXRPC_MAPPING_FILE,
153                         descriptor.getMappingFileUri());
154
155         if( descriptor.hasServiceName() ) {
156             QName JavaDoc serviceName = descriptor.getServiceName();
157             appendQNameChild(WebServicesTagNames.SERVICE_QNAME, serviceRefNode,
158                              serviceName.getNamespaceURI(),
159                              serviceName.getLocalPart(),
160                              descriptor.getServiceNameNamespacePrefix());
161         }
162
163         for(Iterator iter = descriptor.getPortsInfo().iterator();
164             iter.hasNext();) {
165             ServiceRefPortInfo next = (ServiceRefPortInfo) iter.next();
166             if( next.isContainerManaged() ) {
167                 String JavaDoc serviceEndpointInterface =
168                     next.getServiceEndpointInterface();
169                 Node JavaDoc portComponentRefNode = appendChild
170                     (serviceRefNode, WebServicesTagNames.PORT_COMPONENT_REF);
171                 appendTextChild(portComponentRefNode,
172                                 WebServicesTagNames.SERVICE_ENDPOINT_INTERFACE,
173                                 serviceEndpointInterface);
174                 appendTextChild(portComponentRefNode,
175                                 WebServicesTagNames.ENABLE_MTOM,
176                                 next.getMtomEnabled());
177                 appendTextChild(portComponentRefNode,
178                                 WebServicesTagNames.PORT_COMPONENT_LINK,
179                                 next.getPortComponentLinkName());
180             }
181         }
182
183         WebServiceHandlerNode handlerNode = new WebServiceHandlerNode();
184         handlerNode.writeWebServiceHandlers(serviceRefNode,
185                                             descriptor.getHandlers());
186
187         WebServiceHandlerChainNode handlerChainNode =
188                 new WebServiceHandlerChainNode();
189         handlerChainNode.writeWebServiceHandlerChains(serviceRefNode,
190                                             descriptor.getHandlerChain());
191                 
192         appendTextChild(serviceRefNode, WebServicesTagNames.MAPPED_NAME,
193                 descriptor.getMappedName());
194         
195         if (descriptor.isInjectable()) {
196             InjectionTargetNode ijNode = new InjectionTargetNode();
197             for (InjectionTarget target : descriptor.getInjectionTargets()) {
198                 ijNode.writeDescriptor(serviceRefNode, TagNames.INJECTION_TARGET, target);
199             }
200         }
201
202         return serviceRefNode;
203     }
204     
205 }
206
Popular Tags