KickJava   Java API By Example, From Geeks To Geeks.

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


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;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Set JavaDoc;
29 import org.w3c.dom.Node JavaDoc;
30
31 import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
32 import com.sun.enterprise.deployment.Descriptor;
33 import com.sun.enterprise.deployment.EjbDescriptor;
34 import com.sun.enterprise.deployment.EjbInterceptor;
35 import com.sun.enterprise.deployment.ApplicationClientDescriptor;
36 import com.sun.enterprise.deployment.xml.TagNames;
37
38
39 /**
40  * This node handles all information relative to injection-complete xml tag
41  */

42 public class LifecycleCallbackNode extends DeploymentDescriptorNode {
43
44     private LifecycleCallbackDescriptor descriptor;
45     
46    /**
47     * @return the descriptor instance to associate with this XMLNode
48     */

49     public Object JavaDoc getDescriptor() {
50         
51        if (descriptor==null) {
52             descriptor = new LifecycleCallbackDescriptor();
53             Descriptor parentDesc = (Descriptor)getParentNode().getDescriptor();
54             if (parentDesc instanceof EjbDescriptor) {
55                 EjbDescriptor ejbDesc = (EjbDescriptor)parentDesc;
56                 descriptor.setDefaultLifecycleCallbackClass(
57                     ejbDesc.getEjbClassName());
58             } else if (parentDesc instanceof EjbInterceptor) {
59                 EjbInterceptor ejbInterceptor =
60                     (EjbInterceptor)parentDesc;
61                 descriptor.setDefaultLifecycleCallbackClass(
62                     ejbInterceptor.getInterceptorClassName());
63             }
64             // we set the default lifecycle callback class for appclient
65
// later in validate since the appclient Main class is not
66
// available at this point
67
}
68         return descriptor;
69     }
70     
71     /**
72      * all sub-implementation of this class can use a dispatch table to map xml element to
73      * method name on the descriptor class for setting the element value.
74      *
75      * @return the map with the element name as a key, the setter method as a value
76      */

77     protected Map JavaDoc getDispatchTable() {
78         Map JavaDoc table = super.getDispatchTable();
79         table.put(TagNames.LIFECYCLE_CALLBACK_CLASS,
80             "setLifecycleCallbackClass");
81         table.put(TagNames.LIFECYCLE_CALLBACK_METHOD,
82             "setLifecycleCallbackMethod");
83         return table;
84     }
85     
86     /**
87      * write the descriptor class to a DOM tree and return it
88      *
89      * @param parent node in the DOM tree
90      * @param node name for the root element of this xml fragment
91      * @param the descriptor to write
92      * @return the DOM tree top node
93      */

94     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, LifecycleCallbackDescriptor descriptor) {
95         Node JavaDoc myNode = appendChild(parent, nodeName);
96         appendTextChild(myNode, TagNames.LIFECYCLE_CALLBACK_CLASS,
97             descriptor.getLifecycleCallbackClass());
98         appendTextChild(myNode, TagNames.LIFECYCLE_CALLBACK_METHOD,
99             descriptor.getLifecycleCallbackMethod());
100         return myNode;
101     }
102 }
103
Popular Tags