git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1659 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2007-01-07 00:51:56 +00:00
1 parent 0fb0aad736
commit 1bd974b3f6
1 file changed
+37
@@ -0,0 +1,37 @@
package hudson.util;
import org.apache.commons.digester.Rule;
import org.apache.commons.digester.Digester;
import org.xml.sax.Attributes;
import java.lang.reflect.Constructor;
/**
* {@link Digester} rule to create instances of inner class.
*
* @author Kohsuke Kawaguchi
*/
public class InnerObjectCreateRule extends Rule {
private final Constructor ctr;
public InnerObjectCreateRule(Class clazz, Class outerClass) {
try {
this.ctr = clazz.getConstructor(outerClass);
} catch (NoSuchMethodException e) {
NoSuchMethodError x = new NoSuchMethodError();
x.initCause(e);
throw x;
}
}
@Override
public void begin(String namespace, String name, Attributes attributes) throws Exception {
Object instance = ctr.newInstance(digester.peek());
digester.push(instance);
}
@Override
public void end(String namespace, String name) throws Exception {
digester.pop();
}
}