You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2002/08/29 21:28:50 UTC
cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester IDBean.java SimpleReadTest.xml TestIDRead.java
rdonkin 2002/08/29 12:28:50
Modified: betwixt/src/java/org/apache/commons/betwixt/io
BeanReader.java
Added: betwixt/src/test/org/apache/commons/betwixt/digester
IDBean.java SimpleReadTest.xml TestIDRead.java
Log:
Fixed a problem with bean creation. It used to be that beans would only be created if they were root elements. This patch allows them to be created anywhere. Also a test case.
Revision Changes Path
1.3 +4 -0 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanReader.java
Index: BeanReader.java
===================================================================
RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanReader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BeanReader.java 9 Jul 2002 21:50:31 -0000 1.2
+++ BeanReader.java 29 Aug 2002 19:28:50 -0000 1.3
@@ -140,6 +140,7 @@
log.trace("Added path: " + path + ", mapped to: " + beanClass.getName());
}
addBeanCreateRule( path, elementDescriptor, beanClass );
+ addBeanCreateRule( "*/" + path, elementDescriptor, beanClass );
}
}
@@ -153,6 +154,8 @@
ElementDescriptor elementDescriptor = xmlInfo.getElementDescriptor();
addBeanCreateRule( path, elementDescriptor, beanClass );
+ } else {
+ log.warn("Cannot add class " + beanClass.getName() + " since it already exists");
}
}
@@ -198,6 +201,7 @@
*/
public void setLog(Log log) {
this.log = log;
+ setLogger(log);
}
// Implementation methods
1.1 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester/IDBean.java
Index: IDBean.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester/IDBean.java,v 1.1 2002/08/29 19:28:50 rdonkin Exp $
* $Revision: 1.1 $
* $Date: 2002/08/29 19:28:50 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: IDBean.java,v 1.1 2002/08/29 19:28:50 rdonkin Exp $
*/
package org.apache.commons.betwixt.digester;
import java.util.List;
import java.util.ArrayList;
/** Bean for testing ID-IDRef reading.
*
* @author Robert Burrell Donkin
* @version $Revision: 1.1 $
*/
public class IDBean {
private String id;
private String name;
private IDBean child;
private List children = new ArrayList();
public IDBean() {}
public IDBean(String id, String name) {
setId(id);
setName(name);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List getChildren() {
return children;
}
public void addChild(IDBean child) {
children.add(child);
}
public String toString() {
return "IDBean[name=" + getName() + ",id=" + getId() + "]";
}
}
1.1 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester/SimpleReadTest.xml
Index: SimpleReadTest.xml
===================================================================
<?xml version="1.0"?>
<IDBean id="1">
<name>alpha</name>
<children>
<IDBean id="2">
<name>beta</name>
<children/>
<id>two</id>
</IDBean>
<IDBean id="3">
<name>gamma</name>
<children/>
<id>three</id>
</IDBean>
</children>
<id>one</id>
</IDBean>
1.1 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester/TestIDRead.java
Index: TestIDRead.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester/TestIDRead.java,v 1.1 2002/08/29 19:28:50 rdonkin Exp $
* $Revision: 1.1 $
* $Date: 2002/08/29 19:28:50 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: TestIDRead.java,v 1.1 2002/08/29 19:28:50 rdonkin Exp $
*/
package org.apache.commons.betwixt.digester;
import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.commons.betwixt.io.BeanWriter;
import org.apache.commons.betwixt.io.BeanReader;
import org.apache.commons.betwixt.io.BeanCreateRule;
import org.apache.commons.betwixt.AbstractTestCase;
import org.apache.commons.logging.impl.SimpleLog;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
/** Test harness for ID-IDRef reading.
*
* @author Robert Burrell Donkin
* @version $Revision: 1.1 $
*/
public class TestIDRead extends AbstractTestCase {
public static void main( String[] args ) {
TestRunner.run( suite() );
}
public static Test suite() {
return new TestSuite(TestIDRead.class);
}
public TestIDRead(String testName) {
super(testName);
}
public void testSimpleRead() throws Exception {
BeanWriter writer = new BeanWriter();
IDBean bean = new IDBean("alpha","one");
bean.addChild(new IDBean("beta","two"));
bean.addChild(new IDBean("gamma","three"));
writer.write(bean);
BeanReader reader = new BeanReader();
// logging just for this method
// SimpleLog log = new SimpleLog("[XMLIntrospectorHelper]");
// log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
// XMLIntrospectorHelper.setLog(log);
//
// log = new SimpleLog("[BeanCreateRule]");
// log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
// BeanCreateRule.setLog(log);
//
// log = new SimpleLog("[BeanReader]");
// log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
// reader.setLog(log);
//
// log = new SimpleLog("[XMLIntrospector]");
// log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
// reader.getXMLIntrospector().setLog(log);
reader.registerBeanClass( IDBean.class );
//reader.registerBeanClass( "IDBean/children/IDBean", IDBean.class );
System.out.println(reader.getRules().rules());
InputStream in = new FileInputStream(
getTestFile("src/test/org/apache/commons/betwixt/digester/SimpleReadTest.xml") );
try {
Object obj = reader.parse( in );
assertEquals("Read bean type is incorrect", true, (obj instanceof IDBean) );
IDBean alpha = (IDBean) obj;
assertEquals("Wrong list size", 2 , alpha.getChildren().size());
IDBean beta = (IDBean) alpha.getChildren().get(0);
assertEquals("Wrong name (A)", "beta" , beta.getName());
IDBean gamma = (IDBean) alpha.getChildren().get(1);
assertEquals("Wrong name (B)", "gamma" , gamma.getName());
}
finally {
in.close();
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>