ivelin 2002/06/12 19:35:04 Modified: src/java/org/apache/cocoon/components/xmlform Form.java Log: Features from latest JXPath version, reduce code. Revision Changes Path 1.3 +11 -59 xml-cocoon2/src/java/org/apache/cocoon/components/xmlform/Form.java Index: Form.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/xmlform/Form.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Form.java 2 Jun 2002 03:33:35 -0000 1.2 +++ Form.java 13 Jun 2002 02:35:04 -0000 1.3 @@ -76,6 +76,7 @@ import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.Pointer; +import org.apache.commons.jxpath.JXPathException; //import org.apache.commons.jxpath.ri.model.dom.DOMAttributePointer; import org.apache.cocoon.Constants; @@ -190,8 +191,7 @@ { if ( model_ == null) throw new IllegalStateException( "Form model not set" ); - Pointer pointer = jxcontext_.locateValue( xpath ); - setValue( pointer, value ); + jxcontext_.setValue(xpath, value); } @@ -228,10 +228,13 @@ // when the instance property is array if ( property != null && property.getClass().isArray() ) { + Class componentType = property.getClass ().getComponentType (); + property = java.lang.reflect.Array.newInstance ( componentType, values.length ); java.lang.System.arraycopy( values, 0, property, 0, values.length ); + pointer.setValue( property ); } else if (property instanceof Collection) { @@ -243,62 +246,11 @@ // (and the only) from the values array else { - this.setValue( pointer, values[0] ); + pointer.setValue( values[0] ); } } - protected void setValue( Pointer pointer, Object value) - { - -// // Dmitri Plotnikov's patch -// pointer.setValue(value); - - Object property = pointer.getValue(); - if ( property != null ) - { - - - // handle DOM elements - if (property instanceof Element) - { - String textPath = pointer.asPath() + "/text()"; - setValue( textPath, value ); - } - else if (property instanceof Text) - { - Text node = (Text) property; - node.setNodeValue ( value.toString() ); - } - /* - else if (pointer instanceof DOMAttributePointer) - { - Attr node = (Attr) ( ( (DOMAttributePointer)pointer).getBaseValue() ); - node.setNodeValue ( value.toString() ); - } - */ - else - { - Object newValue = convertType( value, property.getClass () ); - pointer.setValue( newValue ); - } - } - // set null value - else pointer.setValue( value ); - } - - - /** - * Attempts to convert the request parameter - * String value to the actual model property type - */ - public Object convertType(Object value, Class requiredType) - { - value = Types.convert(value, requiredType); - return value; - } - - /** * Encapsulates access to the model * @@ -447,7 +399,7 @@ { setValue( path, values ); } - catch (IllegalArgumentException ex) + catch (JXPathException ex) { Violation v = new Violation(); v.setPath( path );
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]