KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > deployment > rules > EjbJarRuleSet


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  *
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or 1any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  * USA
21  *
22  * Initial developer: JOnAS team
23  * --------------------------------------------------------------------------
24  * $Id: EjbJarRuleSet.java,v 1.5 2004/10/08 07:53:18 benoitf Exp $
25  * --------------------------------------------------------------------------
26  */

27 package org.objectweb.jonas_ejb.deployment.rules;
28
29 import java.lang.reflect.Method JavaDoc;
30
31 import org.apache.commons.digester.Digester;
32 import org.apache.commons.digester.Rule;
33 import org.objectweb.jonas_lib.deployment.rules.JRuleSetBase;
34 import org.xml.sax.Attributes JavaDoc;
35
36 /**
37  * This class defines the rules to analyze the element ejb-jar
38  *
39  * @author JOnAS team
40  */

41
42 public class EjbJarRuleSet extends JRuleSetBase {
43
44     /**
45      * Construct an object with a specific prefix
46      */

47     public EjbJarRuleSet() {
48         super("ejb-jar/");
49     }
50
51     /**
52      * Add a set of rules to the digester object
53      *
54      * @param digester Digester instance
55      */

56
57     public void addRuleInstances(Digester digester) {
58         digester.addRule("ejb-jar", new SetPublicIdRule("setPublicId"));
59         digester.addSetProperties("ejb-jar");
60         digester.addCallMethod(prefix + "description", "setDescription", 0);
61         digester.addCallMethod(prefix + "display-name", "setDisplayName", 0);
62         digester.addCallMethod(prefix + "small-icon", "setSmallIcon", 0);
63         digester.addCallMethod(prefix + "large-icon", "setLargeIcon", 0);
64         digester.addRuleSet(new EnterpriseBeansRuleSet(prefix));
65         digester.addRuleSet(new RelationshipsRuleSet(prefix));
66         digester.addRuleSet(new AssemblyDescriptorRuleSet(prefix));
67         digester.addCallMethod(prefix + "ejb-client-jar", "setEjbClientJar", 0);
68     }
69
70     /**
71      * Class that calls a property setter for the top object on the stack,
72      * passing the public ID of the entity we are currently processing.
73      */

74
75     private final class SetPublicIdRule extends Rule {
76
77         /**
78          * Construct a PublicId Setter object
79          *
80          * @param method method name
81          */

82         public SetPublicIdRule(String JavaDoc method) {
83             this.method = method;
84         }
85
86         /**
87          * method name
88          */

89         private String JavaDoc method = null;
90
91         /**
92          * Invoke the given method on the TopLevelElement
93          *
94          * @param attributes contains publicId value
95          *
96          * @throws Exception When invokation through reflection fail.
97          */

98         public void begin(Attributes JavaDoc attributes) throws Exception JavaDoc {
99             Object JavaDoc top = digester.peek();
100             Class JavaDoc[] paramClasses = new Class JavaDoc[1];
101             paramClasses[0] = "String".getClass();
102             String JavaDoc[] paramValues = new String JavaDoc[1];
103             paramValues[0] = digester.getPublicId();
104
105             Method JavaDoc m = null;
106             try {
107                 m = top.getClass().getMethod(method, paramClasses);
108             } catch (NoSuchMethodException JavaDoc e) {
109                 System.out.println("Can't find method " + method + " in " + top + " CLASS " + top.getClass());
110                 return;
111             }
112
113             m.invoke(top, (Object JavaDoc[]) paramValues);
114
115         }
116
117     }
118 }
Popular Tags