KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > admin > importexport > SetParentRule


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/SetParentRule.java,v 1.6 2006/04/14 17:36:29 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.6 $
5  * $Date: 2006/04/14 17:36:29 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Igor Manic
39  */

40 package com.mvnforum.admin.importexport;
41
42 import org.apache.commons.beanutils.MethodUtils;
43 import org.apache.commons.digester.Digester;
44 import org.apache.commons.digester.Rule;
45 import org.xml.sax.Attributes JavaDoc;
46
47 /**
48  * @author Igor Manic
49  * @version $Revision: 1.6 $, $Date: 2006/04/14 17:36:29 $
50  * <br/>
51  * <code>SetParentRule</code> implements a digester rule that calls a "set parent"
52  * method on the top (child) object, passing the (top-1) (parent) object as an argument.
53  * This is same as in <code>SetTopRule</code>, except that this rule is calling
54  * the desired method at the XML element begin (not at the end).
55  */

56 public class SetParentRule extends Rule {
57
58     protected String JavaDoc methodName = null;
59     protected String JavaDoc paramType = null;
60     protected boolean useExactMatch = false;
61
62     public SetParentRule(Digester digester, String JavaDoc methodName) {
63         this(methodName);
64     }
65
66     public SetParentRule(Digester digester, String JavaDoc methodName, String JavaDoc paramType) {
67         this(methodName, paramType);
68     }
69
70     public SetParentRule(String JavaDoc methodName) {
71         this(methodName, null);
72     }
73
74     public SetParentRule(String JavaDoc methodName, String JavaDoc paramType) {
75         this.methodName = methodName;
76         this.paramType = paramType;
77     }
78
79     public boolean isExactMatch() {
80         return useExactMatch;
81     }
82
83     public void setExactMatch(boolean useExactMatch) {
84         this.useExactMatch = useExactMatch;
85     }
86
87     public String JavaDoc toString() {
88         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("SetParentRule[");
89         sb.append("methodName=");
90         sb.append(methodName);
91         sb.append(", paramType=");
92         sb.append(paramType);
93         sb.append("]");
94         return (sb.toString());
95     }
96
97     public void begin(String JavaDoc namespace, String JavaDoc name, Attributes JavaDoc attributes)
98     throws Exception JavaDoc {
99         begin(attributes);
100     }
101
102     public void begin(Attributes JavaDoc attributes) throws Exception JavaDoc {
103         // Identify the objects to be used
104
Object JavaDoc child = digester.peek(0);
105         Object JavaDoc parent = digester.peek(1);
106
107         /*
108         if (digester.log.isDebugEnabled()) {
109             if (child == null) {
110                 digester.log.debug("[SetParentRule]{" + digester.match +
111                         "} Call [NULL CHILD]." +
112                         methodName + "(" + parent + ")");
113             } else {
114                 digester.log.debug("[SetParentRule]{" + digester.match +
115                         "} Call " + child.getClass().getName() + "." +
116                         methodName + "(" + parent + ")");
117             }
118         }*/

119
120         // Call the specified method
121
Class JavaDoc paramTypes[] = new Class JavaDoc[1];
122         if (paramType != null) {
123             paramTypes[0] =
124                     digester.getClassLoader().loadClass(paramType);
125         } else {
126             paramTypes[0] = parent.getClass();
127         }
128
129         if (useExactMatch) {
130             MethodUtils.invokeExactMethod(child, methodName,
131                 new Object JavaDoc[]{ parent }, paramTypes);
132         } else {
133             MethodUtils.invokeMethod(child, methodName,
134                 new Object JavaDoc[]{ parent }, paramTypes);
135         }
136     }
137
138
139 }
140
141
Free Books   Free Magazines  
Popular Tags