/** * {@inheritDoc} */ public CallMethodRule get() { return new CallMethodRule(this.methodName, this.parameterTypes.length, this.parameterTypes); }
/** * Checks if the optional attribute is set. * * @param attrs the attributes * @throws Exception if an error occurs */ @Override public void begin(Attributes attrs) throws Exception { optional = attrs.getValue(ATTR_OPTIONAL) != null && PropertyConverter.toBoolean( attrs.getValue(ATTR_OPTIONAL)).booleanValue(); super.begin(attrs); }
/** * Calls the method. If the optional attribute was set, occurring * exceptions will be ignored. * * @throws Exception if an error occurs */ @Override public void end() throws Exception { try { super.end(); } catch (Exception ex) { if (optional) { log.warn("Could not create optional configuration!", ex); } else { throw ex; } } } }
/** * Checks if the optional attribute is set. * * @param attrs the attributes * @throws Exception if an error occurs */ @Override public void begin(Attributes attrs) throws Exception { optional = attrs.getValue(ATTR_OPTIONAL) != null && PropertyConverter.toBoolean( attrs.getValue(ATTR_OPTIONAL)).booleanValue(); super.begin(attrs); }
/** * Calls the method. If the optional attribute was set, occurring * exceptions will be ignored. * * @throws Exception if an error occurs */ @Override public void end() throws Exception { try { super.end(); } catch (Exception ex) { if (optional) { log.warn("Could not create optional configuration!", ex); } else { throw ex; } } } }
/** * Add an "call method" rule for a method which accepts no arguments. * * @param pattern Element matching pattern * @param methodName Method name to be called * @see CallMethodRule */ public void addCallMethod(String pattern, String methodName) { addRule( pattern, new CallMethodRule(methodName)); }
/** * Add an "call method" rule for the specified parameters. * * @param pattern Element matching pattern * @param methodName Method name to be called * @param paramCount Number of expected parameters (or zero * for a single parameter from the body of this element) * @see CallMethodRule */ public void addCallMethod(String pattern, String methodName, int paramCount) { addRule(pattern, new CallMethodRule(methodName, paramCount)); }
@Override public Object createObject(Attributes attributes) { Rule callMethodRule = null; String methodName = attributes.getValue("methodname"); // Select which element is to be the target. Default to zero, // ie the top object on the stack. int targetOffset = 0; String targetOffsetStr = attributes.getValue("targetoffset"); if (targetOffsetStr != null) { targetOffset = Integer.parseInt(targetOffsetStr); } if (attributes.getValue("paramcount") == null) { // call against empty method callMethodRule = new CallMethodRule(targetOffset, methodName); } else { int paramCount = Integer.parseInt(attributes.getValue("paramcount")); String paramTypesAttr = attributes.getValue("paramtypes"); if (paramTypesAttr == null || paramTypesAttr.length() == 0) { callMethodRule = new CallMethodRule(targetOffset, methodName, paramCount); } else { String[] paramTypes = getParamTypes(paramTypesAttr); callMethodRule = new CallMethodRule( targetOffset, methodName, paramCount, paramTypes); } } return callMethodRule; }
/** * Add an "call method" rule for the specified parameters. * If <code>paramCount</code> is set to zero the rule will use * the body of the matched element as the single argument of the * method, unless <code>paramTypes</code> is null or empty, in this * case the rule will call the specified method with no arguments. * * @param pattern Element matching pattern * @param methodName Method name to be called * @param paramCount Number of expected parameters (or zero * for a single parameter from the body of this element) * @param paramTypes Set of Java class names for the types * of the expected parameters * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as <code>java.lang.Boolean</code> * for a <code>boolean</code> parameter) * @see CallMethodRule */ public void addCallMethod(String pattern, String methodName, int paramCount, String paramTypes[]) { addRule(pattern, new CallMethodRule( methodName, paramCount, paramTypes)); }
/** * Add an "call method" rule for the specified parameters. * If <code>paramCount</code> is set to zero the rule will use * the body of the matched element as the single argument of the * method, unless <code>paramTypes</code> is null or empty, in this * case the rule will call the specified method with no arguments. * * @param pattern Element matching pattern * @param methodName Method name to be called * @param paramCount Number of expected parameters (or zero * for a single parameter from the body of this element) * @param paramTypes The Java class names of the arguments * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as <code>java.lang.Boolean</code> * for a <code>boolean</code> parameter) * @see CallMethodRule */ public void addCallMethod(String pattern, String methodName, int paramCount, Class<?> paramTypes[]) { addRule(pattern, new CallMethodRule( methodName, paramCount, paramTypes)); }
/** * Add an "call method" rule for a method which accepts no arguments. * * @param pattern Element matching pattern * @param methodName Method name to be called * @see CallMethodRule */ public void addCallMethod(String pattern, String methodName) { addRule( pattern, new CallMethodRule(methodName)); }
/** * Add an "call method" rule for the specified parameters. * * @param pattern Element matching pattern * @param methodName Method name to be called * @param paramCount Number of expected parameters (or zero * for a single parameter from the body of this element) * @see CallMethodRule */ public void addCallMethod(String pattern, String methodName, int paramCount) { addRule(pattern, new CallMethodRule(methodName, paramCount)); }
public Object createObject(Attributes attributes) { Rule callMethodRule = null; String methodName = attributes.getValue("methodname"); // Select which element is to be the target. Default to zero, // ie the top object on the stack. int targetOffset = 0; String targetOffsetStr = attributes.getValue("targetoffset"); if (targetOffsetStr != null) { targetOffset = Integer.parseInt(targetOffsetStr); } if (attributes.getValue("paramcount") == null) { // call against empty method callMethodRule = new CallMethodRule(targetOffset, methodName); } else { int paramCount = Integer.parseInt(attributes.getValue("paramcount")); String paramTypesAttr = attributes.getValue("paramtypes"); if (paramTypesAttr == null || paramTypesAttr.length() == 0) { callMethodRule = new CallMethodRule(targetOffset, methodName, paramCount); } else { String[] paramTypes = getParamTypes(paramTypesAttr); callMethodRule = new CallMethodRule( targetOffset, methodName, paramCount, paramTypes); } } return callMethodRule; }
/** * Add an "call method" rule for the specified parameters. * If <code>paramCount</code> is set to zero the rule will use * the body of the matched element as the single argument of the * method, unless <code>paramTypes</code> is null or empty, in this * case the rule will call the specified method with no arguments. * * @param pattern Element matching pattern * @param methodName Method name to be called * @param paramCount Number of expected parameters (or zero * for a single parameter from the body of this element) * @param paramTypes The Java class names of the arguments * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as <code>java.lang.Boolean</code> * for a <code>boolean</code> parameter) * @see CallMethodRule */ public void addCallMethod(String pattern, String methodName, int paramCount, Class<?> paramTypes[]) { addRule(pattern, new CallMethodRule( methodName, paramCount, paramTypes)); }
/** * Add an "call method" rule for the specified parameters. * If <code>paramCount</code> is set to zero the rule will use * the body of the matched element as the single argument of the * method, unless <code>paramTypes</code> is null or empty, in this * case the rule will call the specified method with no arguments. * * @param pattern Element matching pattern * @param methodName Method name to be called * @param paramCount Number of expected parameters (or zero * for a single parameter from the body of this element) * @param paramTypes Set of Java class names for the types * of the expected parameters * (if you wish to use a primitive type, specify the corresonding * Java wrapper class instead, such as <code>java.lang.Boolean</code> * for a <code>boolean</code> parameter) * @see CallMethodRule */ public void addCallMethod(String pattern, String methodName, int paramCount, String paramTypes[]) { addRule(pattern, new CallMethodRule( methodName, paramCount, paramTypes)); }
digester.addRule(prefPath, new CallMethodRule(1, "addPreference", 9)); digester.addCallParam(prefPath, 0, A_NAME); digester.addCallParam(prefPath, 1, A_VALUE);