commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject svn commit: r153391 - jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions
Date Fri, 11 Feb 2005 12:23:25 GMT
Author: skitching
Date: Fri Feb 11 04:23:23 2005
New Revision: 153391

URL: http://svn.apache.org/viewcvs?view=rev&rev=153391
Log:
Functionality split out from old CallParamRule

Added:
    jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamAttributeAction.java
  (with props)
    jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamBodyAction.java
  (with props)
    jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamFromStackAction.java
  (with props)
    jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamLiteralAction.java
  (with props)
    jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamPathAction.java
  (with props)

Added: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamAttributeAction.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamAttributeAction.java?view=auto&rev=153391
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamAttributeAction.java
(added)
+++ jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamAttributeAction.java
Fri Feb 11 04:23:23 2005
@@ -0,0 +1,106 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.digester2.actions;
+
+import org.xml.sax.Attributes;
+
+import org.apache.commons.digester2.ArrayStack;
+import org.apache.commons.logging.Log;
+
+import org.apache.commons.digester2.Context;
+import org.apache.commons.digester2.AbstractAction;
+import org.apache.commons.digester2.ParseException;
+
+/**
+ * Action which saves an xml attribute as a parameter value for a method
+ * invoked by a CallMethodRule.
+ */
+
+public class CallParamAttributeAction extends AbstractAction {
+
+    /**
+     * The zero-relative index of the parameter we are saving.
+     */
+    protected int paramIndex = 0;
+
+    /**
+     * The attribute from which to save the parameter value
+     */
+    protected String attributeName;
+
+    // ---------------------------------------------------------
+    // Constructor
+    // ---------------------------------------------------------
+
+    /**
+     * Construct a "call parameter" rule that will save the value of the
+     * specified attribute as the parameter value.
+     *
+     * @param paramIndex The zero-relative parameter number
+     * @param attributeName The name of the attribute to save
+     */
+    public CallParamAttributeAction(int paramIndex, String attributeName) {
+        this.paramIndex = paramIndex;
+        this.attributeName = attributeName;
+    }
+
+    // ---------------------------------------------------------
+    // Public Methods
+    // ---------------------------------------------------------
+
+    /**
+     * Process the start of this element.
+     *
+     * @param attributes The attribute list for this element
+     */
+    public void begin(
+    Context context,
+    String namespace, String name, Attributes attributes)
+    throws ParseException {
+        Object paramValue = attributes.getValue(attributeName);
+
+        Log log = context.getLogger();
+        if (log.isDebugEnabled()) {
+            StringBuffer sb = new StringBuffer("[CallParamAttributeAction]{");
+            sb.append(context.getMatchPath());
+            sb.append("} saving xml attribute [");
+            sb.append(attributeName);
+            sb.append("] value [");
+            sb.append(paramValue);
+            sb.append("]");
+            log.debug(sb.toString());
+        }
+
+        Parameters params = (Parameters) context.peek(CallMethodAction.PARAM_STACK);
+        params.put(paramIndex, paramValue);
+    }
+
+    /**
+     * Render a printable version of this Rule.
+     */
+    public String toString() {
+        StringBuffer sb = new StringBuffer("CallParamAttributeAction[");
+        sb.append("paramIndex=");
+        sb.append(paramIndex);
+        sb.append(", attributeName=");
+        sb.append(attributeName);
+        sb.append("]");
+        return sb.toString();
+    }
+}

Propchange: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamAttributeAction.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamBodyAction.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamBodyAction.java?view=auto&rev=153391
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamBodyAction.java
(added)
+++ jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamBodyAction.java
Fri Feb 11 04:23:23 2005
@@ -0,0 +1,97 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.digester2.actions;
+
+import org.xml.sax.Attributes;
+
+import org.apache.commons.digester2.ArrayStack;
+import org.apache.commons.logging.Log;
+
+import org.apache.commons.digester2.Context;
+import org.apache.commons.digester2.AbstractAction;
+import org.apache.commons.digester2.ParseException;
+
+/**
+ * Action which saves the body text of the current xml element as a parameter
+ * to a method invoked by a CallMethodRule.
+ */
+
+public class CallParamBodyAction extends AbstractAction {
+
+    /**
+     * The zero-relative index of the parameter we are saving.
+     */
+    protected int paramIndex = 0;
+    
+    // ---------------------------------------------------------
+    // Constructor
+    //
+    // TODO: support attributes
+    //   "trim" --> trim the body before passing as parameter?
+    //   "emptyAsNull" --> pass null if the body is an empty string
+    // ---------------------------------------------------------
+
+    /**
+     * Construct a "call parameter" rule that will pass the body text
+     * of the matching xml element as the parameter value.
+     *
+     * @param paramIndex The zero-relative parameter number
+     */
+    public CallParamBodyAction(int paramIndex) {
+        this.paramIndex = paramIndex;
+    }
+
+    // ---------------------------------------------------------
+    // Public Methods
+    // ---------------------------------------------------------
+
+    /**
+     * Process the start of this element.
+     *
+     * @param attributes The attribute list for this element
+     */
+    public void body(
+    Context context,
+    String namespace, String name, 
+    String text)
+    throws ParseException {
+        Log log = context.getLogger();
+        if (log.isDebugEnabled()) {
+            StringBuffer sb = new StringBuffer("[CallParamBodyAction]{");
+            sb.append(context.getMatchPath());
+            sb.append("} saving body text value [");
+            sb.append(text);
+            sb.append("]");
+            log.debug(sb.toString());
+        }
+
+        Parameters params = (Parameters) context.peek(CallMethodAction.PARAM_STACK);
+        params.put(paramIndex, text);
+    }
+
+    /**
+     * Render a printable version of this Rule.
+     */
+    public String toString() {
+        StringBuffer sb = new StringBuffer("CallParamBodyAction[");
+        sb.append("paramIndex=");
+        sb.append(paramIndex);
+        return sb.toString();
+    }
+}

Propchange: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamBodyAction.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamFromStackAction.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamFromStackAction.java?view=auto&rev=153391
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamFromStackAction.java
(added)
+++ jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamFromStackAction.java
Fri Feb 11 04:23:23 2005
@@ -0,0 +1,101 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.digester2.actions;
+
+import org.xml.sax.Attributes;
+
+import org.apache.commons.digester2.ArrayStack;
+import org.apache.commons.logging.Log;
+
+import org.apache.commons.digester2.Context;
+import org.apache.commons.digester2.AbstractAction;
+import org.apache.commons.digester2.ParseException;
+
+/**
+ * Action which fetches an object from the digester object stack to use
+ * as a parameter for the target method invoked by a CallMethodRule.
+ */
+
+public class CallParamFromStackAction extends AbstractAction {
+
+    /**
+     * The zero-relative index of the parameter we are saving.
+     */
+    protected int paramIndex = 0;
+    
+    /**
+     * Which object to pass. 
+     */
+    protected int stackOffset;
+    
+    // ---------------------------------------------------------
+    // Constructor
+    // ---------------------------------------------------------
+
+    /**
+     * Construct a "call parameter" rule that will pass the body text
+     * of the matching xml element as the parameter value.
+     *
+     * @param paramIndex The zero-relative parameter number
+     */
+    public CallParamFromStackAction(int paramIndex, int stackOffset) {
+        this.paramIndex = paramIndex;
+        this.stackOffset = stackOffset;
+    }
+
+    // ---------------------------------------------------------
+    // Public Methods
+    // ---------------------------------------------------------
+
+    /**
+     * Process the start of this element.
+     *
+     * @param attributes The attribute list for this element
+     */
+    public void begin(
+    Context context,
+    String namespace, String name, Attributes attributes)
+    throws ParseException {
+
+        Object paramValue = context.peek(stackOffset);
+        
+        Log log = context.getLogger();
+        if (log.isDebugEnabled()) {
+            StringBuffer sb = new StringBuffer("[CallParamFromStackAction]{");
+            sb.append(context.getMatchPath());
+            sb.append("}");
+            log.debug(sb.toString());
+        }
+
+        Parameters params = (Parameters) context.peek(CallMethodAction.PARAM_STACK);
+        params.put(paramIndex, paramValue);
+    }
+
+    /**
+     * Render a printable version of this Rule.
+     */
+    public String toString() {
+        StringBuffer sb = new StringBuffer("CallParamFromStackAction[");
+        sb.append("paramIndex=");
+        sb.append(paramIndex);
+        sb.append(", stackOffset=");
+        sb.append(stackOffset);
+        return sb.toString();
+    }
+}

Propchange: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamFromStackAction.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamLiteralAction.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamLiteralAction.java?view=auto&rev=153391
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamLiteralAction.java
(added)
+++ jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamLiteralAction.java
Fri Feb 11 04:23:23 2005
@@ -0,0 +1,99 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.digester2.actions;
+
+import org.xml.sax.Attributes;
+
+import org.apache.commons.digester2.ArrayStack;
+import org.apache.commons.logging.Log;
+
+import org.apache.commons.digester2.Context;
+import org.apache.commons.digester2.AbstractAction;
+import org.apache.commons.digester2.ParseException;
+
+/**
+ * Action which saves a literal value (including an arbitrary Object reference)
+ * as a parameter to a method invoked by a CallMethodRule.
+ */
+
+public class CallParamLiteralAction extends AbstractAction {
+
+    /**
+     * The zero-relative index of the parameter we are saving.
+     */
+    protected int paramIndex;
+
+    /**
+     * The literal object to save as a parameter.
+     */
+    protected Object literal;
+
+    // ---------------------------------------------------------
+    // Constructor
+    // ---------------------------------------------------------
+
+    /**
+     * Construct a "call parameter" rule that will save the provided
+     * literal object as the parameter value.
+     *
+     * @param paramIndex The zero-relative parameter number
+     * @param literal The object to be passed to the target method.
+     */
+    public CallParamLiteralAction(int paramIndex, Object literal) {
+        this.paramIndex = paramIndex;
+        this.literal = literal;
+    }
+
+    // ---------------------------------------------------------
+    // Public Methods
+    // ---------------------------------------------------------
+
+    /**
+     * Process the start of this element.
+     *
+     * @param attributes The attribute list for this element
+     */
+    public void begin(
+    Context context,
+    String namespace, String name, Attributes attributes)
+    throws ParseException {
+        Log log = context.getLogger();
+        if (log.isDebugEnabled()) {
+            StringBuffer sb = new StringBuffer("[CallParamLiteralAction]{");
+            sb.append(context.getMatchPath());
+            sb.append("} saving literal value [");
+            sb.append(literal);
+            sb.append("]");
+            log.debug(sb.toString());
+        }
+
+        Parameters params = (Parameters) context.peek(CallMethodAction.PARAM_STACK);
+        params.put(paramIndex, literal);
+    }
+
+    /**
+     * Render a printable version of this Rule.
+     */
+    public String toString() {
+        StringBuffer sb = new StringBuffer("CallParamLiteralAction[");
+        sb.append("paramIndex=");
+        sb.append(paramIndex);
+        return sb.toString();
+    }
+}

Propchange: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamLiteralAction.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamPathAction.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamPathAction.java?view=auto&rev=153391
==============================================================================
--- jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamPathAction.java
(added)
+++ jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamPathAction.java
Fri Feb 11 04:23:23 2005
@@ -0,0 +1,93 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.digester2.actions;
+
+import org.xml.sax.Attributes;
+
+import org.apache.commons.digester2.ArrayStack;
+import org.apache.commons.logging.Log;
+
+import org.apache.commons.digester2.Context;
+import org.apache.commons.digester2.AbstractAction;
+import org.apache.commons.digester2.ParseException;
+
+/**
+ * Action which fetches an object from the digester object stack to use
+ * as a parameter for the target method invoked by a CallMethodRule.
+ */
+
+public class CallParamPathAction extends AbstractAction {
+
+    /**
+     * The zero-relative index of the parameter we are saving.
+     */
+    protected int paramIndex = 0;
+    
+    // ---------------------------------------------------------
+    // Constructor
+    // ---------------------------------------------------------
+
+    /**
+     * Construct a "call parameter" rule that will pass the
+     * path from the document root to the current element as the
+     * parameter value.
+     *
+     * @param paramIndex The zero-relative parameter number
+     */
+    public CallParamPathAction(int paramIndex) {
+        this.paramIndex = paramIndex;
+    }
+
+    // ---------------------------------------------------------
+    // Public Methods
+    // ---------------------------------------------------------
+
+    /**
+     * Process the start of this element.
+     *
+     * @param attributes The attribute list for this element
+     */
+    public void begin(
+    Context context,
+    String namespace, String name, Attributes attributes)
+    throws ParseException {
+        String paramValue = context.getMatchPath();
+        
+        Log log = context.getLogger();
+        if (log.isDebugEnabled()) {
+            StringBuffer sb = new StringBuffer("[CallParamPathAction]{");
+            sb.append(context.getMatchPath());
+            sb.append("}");
+            log.debug(sb.toString());
+        }
+
+        Parameters params = (Parameters) context.peek(CallMethodAction.PARAM_STACK);
+        params.put(paramIndex, paramValue);
+    }
+
+    /**
+     * Render a printable version of this Rule.
+     */
+    public String toString() {
+        StringBuffer sb = new StringBuffer("CallParamPathAction[");
+        sb.append("paramIndex=");
+        sb.append(paramIndex);
+        return (sb.toString());
+    }
+}

Propchange: jakarta/commons/proper/digester/branches/digester2/src/java/org/apache/commons/digester2/actions/CallParamPathAction.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message