KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > connector > MessageListenerNode


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 package com.sun.enterprise.deployment.node.connector;
25
26 import java.util.*;
27 import org.xml.sax.Attributes JavaDoc;
28 import com.sun.enterprise.deployment.Descriptor;
29 import com.sun.enterprise.deployment.ConnectorDescriptor;
30 import com.sun.enterprise.deployment.InboundResourceAdapter;
31 import com.sun.enterprise.deployment.xml.ConnectorTagNames;
32 import com.sun.enterprise.deployment.xml.TagNames;
33 import com.sun.enterprise.deployment.EnvironmentProperty;
34 import com.sun.enterprise.deployment.node.DescriptorFactory;
35 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
36 import com.sun.enterprise.deployment.node.ConfigurableNode;
37 import com.sun.enterprise.deployment.node.XMLElement;
38 import com.sun.enterprise.deployment.MessageListener;
39 import com.sun.enterprise.deployment.node.connector.ActivationSpecNode;
40
41 import org.xml.sax.Attributes JavaDoc;
42 import org.w3c.dom.Node JavaDoc;
43
44 /**
45  * This node is responsible for handling the Connector DTD related message-listener XML tag
46  *
47  * @author Sheetal Vartak
48  * @version
49  */

50 public class MessageListenerNode extends DeploymentDescriptorNode {
51     
52     private MessageListener msgListener = null;
53     
54     public MessageListenerNode() {
55     registerElementHandler(new XMLElement(ConnectorTagNames.ACTIVATION_SPEC),
56                    ActivationSpecNode.class);
57     
58     }
59
60    /**
61      * all sub-implementation of this class can use a dispatch table to map xml element to
62      * method name on the descriptor class for setting the element value.
63      *
64      * @return the map with the element name as a key, the setter method as a value
65      */

66
67     protected Map getDispatchTable() {
68         Map table = super.getDispatchTable();
69         table.put(ConnectorTagNames.MSG_LISTENER_TYPE, "setMessageListenerType");
70     return table;
71     }
72
73     /**
74     * @return the descriptor instance to associate with this XMLNode
75     */

76     public Object JavaDoc getDescriptor() {
77         if (msgListener == null) {
78             msgListener = (MessageListener) DescriptorFactory.getDescriptor(getXMLPath());
79         }
80         return msgListener;
81     }
82
83     /**
84      * write the descriptor class to a DOM tree and return it
85      *
86      * @param parent node for the DOM tree
87      * @param the descriptor to write
88      * @return the DOM tree top node
89      */

90     public Node writeDescriptor(Node parent, Descriptor descriptor) {
91
92         if (! (descriptor instanceof InboundResourceAdapter)) {
93             throw new IllegalArgumentException JavaDoc(getClass() + " cannot handle descriptors of type " + descriptor.getClass());
94         }
95     Iterator msgListeners = ((InboundResourceAdapter)descriptor).getMessageListeners().iterator();
96     if (!msgListeners.hasNext()) {
97         throw new RuntimeException JavaDoc("There must be at least one messagelistener for this inbound resource adapter");
98     }
99     //message listeners
100
for (;msgListeners.hasNext();) {
101         MessageListener msgListener = (MessageListener) msgListeners.next();
102         Node msgListenerNode = appendChild(parent, ConnectorTagNames.MSG_LISTENER);
103         appendTextChild(msgListenerNode, ConnectorTagNames.MSG_LISTENER_TYPE, msgListener.getMessageListenerType());
104     
105         //activation spec node
106
ActivationSpecNode actSpecNode = new ActivationSpecNode();
107         msgListenerNode = actSpecNode.writeDescriptor(msgListenerNode, msgListener);
108     }
109     return parent;
110     }
111 }
112
Popular Tags