001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: *
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or 1any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
020: * USA
021: *
022: * Initial developer: JOnAS team
023: * --------------------------------------------------------------------------
024: * $Id: EjbJarRuleSet.java 5578 2004-10-08 07:53:18Z benoitf $
025: * --------------------------------------------------------------------------
026: */package org.objectweb.jonas_ejb.deployment.rules;
027:
028: import java.lang.reflect.Method;
029:
030: import org.apache.commons.digester.Digester;
031: import org.apache.commons.digester.Rule;
032: import org.objectweb.jonas_lib.deployment.rules.JRuleSetBase;
033: import org.xml.sax.Attributes;
034:
035: /**
036: * This class defines the rules to analyze the element ejb-jar
037: *
038: * @author JOnAS team
039: */
040:
041: public class EjbJarRuleSet extends JRuleSetBase {
042:
043: /**
044: * Construct an object with a specific prefix
045: */
046: public EjbJarRuleSet() {
047: super ("ejb-jar/");
048: }
049:
050: /**
051: * Add a set of rules to the digester object
052: *
053: * @param digester Digester instance
054: */
055:
056: public void addRuleInstances(Digester digester) {
057: digester.addRule("ejb-jar", new SetPublicIdRule("setPublicId"));
058: digester.addSetProperties("ejb-jar");
059: digester.addCallMethod(prefix + "description",
060: "setDescription", 0);
061: digester.addCallMethod(prefix + "display-name",
062: "setDisplayName", 0);
063: digester
064: .addCallMethod(prefix + "small-icon", "setSmallIcon", 0);
065: digester
066: .addCallMethod(prefix + "large-icon", "setLargeIcon", 0);
067: digester.addRuleSet(new EnterpriseBeansRuleSet(prefix));
068: digester.addRuleSet(new RelationshipsRuleSet(prefix));
069: digester.addRuleSet(new AssemblyDescriptorRuleSet(prefix));
070: digester.addCallMethod(prefix + "ejb-client-jar",
071: "setEjbClientJar", 0);
072: }
073:
074: /**
075: * Class that calls a property setter for the top object on the stack,
076: * passing the public ID of the entity we are currently processing.
077: */
078:
079: private final class SetPublicIdRule extends Rule {
080:
081: /**
082: * Construct a PublicId Setter object
083: *
084: * @param method method name
085: */
086: public SetPublicIdRule(String method) {
087: this .method = method;
088: }
089:
090: /**
091: * method name
092: */
093: private String method = null;
094:
095: /**
096: * Invoke the given method on the TopLevelElement
097: *
098: * @param attributes contains publicId value
099: *
100: * @throws Exception When invokation through reflection fail.
101: */
102: public void begin(Attributes attributes) throws Exception {
103: Object top = digester.peek();
104: Class[] paramClasses = new Class[1];
105: paramClasses[0] = "String".getClass();
106: String[] paramValues = new String[1];
107: paramValues[0] = digester.getPublicId();
108:
109: Method m = null;
110: try {
111: m = top.getClass().getMethod(method, paramClasses);
112: } catch (NoSuchMethodException e) {
113: System.out.println("Can't find method " + method
114: + " in " + top + " CLASS " + top.getClass());
115: return;
116: }
117:
118: m.invoke(top, (Object[]) paramValues);
119:
120: }
121:
122: }
123: }
|