01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: *
08: * modify it under the terms of the GNU Lesser General Public
09: * 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: * --------------------------------------------------------------------------
23: * $Id: ClusterRuleSet.java 7757 2005-12-08 15:24:55Z danesa $
24: * --------------------------------------------------------------------------
25: */package org.objectweb.jonas_domain.rules;
26:
27: import org.apache.commons.digester.Digester;
28: import org.objectweb.jonas_lib.deployment.rules.JRuleSetBase;
29:
30: /**
31: * This class defines the rules to analyze the cluster element.
32: * A Cluster element may contain another cluster element.
33: *
34: * @author Adriana Danes
35: */
36:
37: public class ClusterRuleSet extends JRuleSetBase {
38:
39: private String CLUSTER = "cluster";
40:
41: /**
42: * If greater than 0 it gives the level of an inner cluster element
43: */
44: int indentLevel = 0;
45:
46: /**
47: * Maximum sub-elements
48: */
49: int maxLevel = 3;
50:
51: /**
52: * Construct an object with the given prefix
53: * @param prefix prefix to use during the parsing
54: */
55: public ClusterRuleSet(String prefix) {
56: super (prefix);
57: int previousIndex = 0;
58: int index;
59: while (true) {
60: index = prefix.indexOf(CLUSTER, previousIndex);
61: if (index < 0) {
62: break;
63: } else {
64: indentLevel++;
65: previousIndex = index + CLUSTER.length();
66: }
67: }
68: }
69:
70: /**
71: * Add a set of rules to the digester object
72: * @param digester Digester instance
73: */
74: public void addRuleInstances(Digester digester) {
75: digester.addObjectCreate(prefix + "cluster",
76: "org.objectweb.jonas_domain.xml.Cluster");
77: digester.addSetNext(prefix + "cluster", "addCluster",
78: "org.objectweb.jonas_domain.xml.Cluster");
79: digester.addCallMethod(prefix + "cluster/name", "setName", 0);
80: digester.addCallMethod(prefix + "cluster/description",
81: "setDescription", 0);
82: digester.addRuleSet(new ServerRuleSet(prefix + "cluster/"));
83: if (indentLevel < maxLevel) {
84: digester
85: .addRuleSet(new ClusterRuleSet(prefix + "cluster/"));
86: }
87: }
88:
89: }
|