Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 46299 invoked from network); 20 Feb 2011 00:30:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 Feb 2011 00:30:12 -0000 Received: (qmail 30293 invoked by uid 500); 20 Feb 2011 00:30:11 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 30214 invoked by uid 500); 20 Feb 2011 00:30:11 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 30207 invoked by uid 99); 20 Feb 2011 00:30:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Feb 2011 00:30:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Feb 2011 00:30:09 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EE42623889D7; Sun, 20 Feb 2011 00:29:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1072466 - in /commons/sandbox/digester3/trunk/src/examples/addressbook: ./ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/commons/ src/main/java/org/apache/commons/digester3/ src/main/java/org/apache/commons/digester... Date: Sun, 20 Feb 2011 00:29:48 -0000 To: commits@commons.apache.org From: simonetripodi@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110220002948.EE42623889D7@eris.apache.org> Author: simonetripodi Date: Sun Feb 20 00:29:48 2011 New Revision: 1072466 URL: http://svn.apache.org/viewvc?rev=1072466&view=rev Log: imported and adapted the addressbook example Added: commons/sandbox/digester3/trunk/src/examples/addressbook/example.xml (with props) commons/sandbox/digester3/trunk/src/examples/addressbook/readme.txt (with props) commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/ commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/ commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/ commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/ commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/ commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/ commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Address.java (with props) commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBook.java (with props) commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBookModule.java (with props) commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Main.java (with props) commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Person.java (with props) Added: commons/sandbox/digester3/trunk/src/examples/addressbook/example.xml URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/addressbook/example.xml?rev=1072466&view=auto ============================================================================== --- commons/sandbox/digester3/trunk/src/examples/addressbook/example.xml (added) +++ commons/sandbox/digester3/trunk/src/examples/addressbook/example.xml Sun Feb 20 00:29:48 2011 @@ -0,0 +1,54 @@ + + + + + Gonzo + gonzo@muppets.com +
+ home + 123 Maine Ave. + Las Vegas + NV + 01234 + USA +
+
+ business + 234 Maple Dr. + Los Angeles + CA + 98765 + USA +
+
+ + + Kermit + kermit@muppets.com + kermie@acme.com +
+ business + 987 Brown Rd + Las Cruces + NM + 75321 + USA +
+
+ +
Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/example.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/example.xml ------------------------------------------------------------------------------ svn:keywords = Date Revision Author HeadURL Id Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/example.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: commons/sandbox/digester3/trunk/src/examples/addressbook/readme.txt URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/addressbook/readme.txt?rev=1072466&view=auto ============================================================================== --- commons/sandbox/digester3/trunk/src/examples/addressbook/readme.txt (added) +++ commons/sandbox/digester3/trunk/src/examples/addressbook/readme.txt Sun Feb 20 00:29:48 2011 @@ -0,0 +1,52 @@ +######################################################################### +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +######################################################################### + +== overview + +The files in this directory are intended as an example of how to use +the Apache Digester's basic functionality via its java interface. + +Topics covered: +* how to create a digester instance +* how to parse a file +* how to use the "object create" rule to create java objects +* how to use the "set properties" rule (basic usage) to map xml attributes + to java bean properties. +* how to use the "set next" rule to build trees of java objects. +* how to use the "call method rule" (basic usage) +* how to use the "call parameter rule" to process the text contained + in a tag's body +* how to use the "call parameter rule" to process the contents of an + xml attribute. + +== compiling and running + +First rename the build.properties.sample file in the parent directory +to build.properties and edit it to suit your environment. Then in this +directory: + +* to compile: + mvn compile + +* to build the jar artifact + mvn compile + +* to run: + mvn verify + +Alternatively, you can set up your CLASSPATH appropriately, and +run the example directly. Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/readme.txt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/readme.txt ------------------------------------------------------------------------------ svn:keywords = Date Revision Author HeadURL Id Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/readme.txt ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Address.java URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Address.java?rev=1072466&view=auto ============================================================================== --- commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Address.java (added) +++ commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Address.java Sun Feb 20 00:29:48 2011 @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.digester3.examples.addressbook; + +import java.io.PrintStream; + +/** + * See Main.java. + */ +public class Address { + + private String type; + + private String street; + + private String city; + + private String state; + + private String zip; + + private String country; + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append( " address (type "+ type + ")\n"); + sb.append( " " + street + "\n"); + sb.append( " " + city + " " + state + " " + zip + "\n"); + sb.append( " " + country + "\n"); + return sb.toString(); + } + + public void print(PrintStream out, int indentAmount) { + StringBuffer indentStr = new StringBuffer(indentAmount); + for(; indentAmount > 0; --indentAmount) { + indentStr.append(' '); + } + + out.print(indentStr); + out.print("address type: "); + out.println(type); + + out.print(indentStr); + out.println(" " + street); + + out.print(indentStr); + out.println(" " + city + " " + state + " " + zip); + + out.print(indentStr); + out.println(" " + country); + } + + /** + * Returns the value of street. + */ + public String getStreet() { + return street; + } + + /** + * Sets the value of street. + * @param street The value to assign to street. + */ + public void setStreet(String street) { + this.street = street; + } + + /** + * Returns the value of city. + */ + public String getCity() { + return city; + } + + /** + * Sets the value of city. + * @param city The value to assign to city. + */ + public void setCity(String city) { + this.city = city; + } + + /** + * Returns the value of state. + */ + public String getState() { + return state; + } + + /** + * Sets the value of state. + * @param state The value to assign to state. + */ + public void setState(String state) { + this.state = state; + } + + /** + * Returns the value of zip. + */ + public String getZip() { + return zip; + } + + /** + * Sets the value of zip. + * @param zip The value to assign to zip. + */ + public void setZip(String zip) { + this.zip = zip; + } + + /** + * Returns the value of country. + */ + public String getCountry() { + return country; + } + + /** + * Sets the value of country. + * @param country The value to assign to country. + */ + public void setCountry(String country) { + this.country = country; + } + + /** + * Returns the value of type. + */ + public String getType() { + return type; + } + + /** + * Sets the value of type. + * @param type The value to assign to type. + */ + public void setType(String type) { + this.type = type; + } + +} Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Address.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Address.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Address.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBook.java URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBook.java?rev=1072466&view=auto ============================================================================== --- commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBook.java (added) +++ commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBook.java Sun Feb 20 00:29:48 2011 @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.digester3.examples.addressbook; + +import java.util.LinkedList; + +/** + * See Main.java. + */ +public class AddressBook { + + private final LinkedList people = new LinkedList(); + + public void addPerson(Person p) { + people.addLast(p); + } + + public void print() { + System.out.println("Address book has " + people.size() + " entries"); + + for (Person p : this.people) { + p.print(); + } + } + +} Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBook.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBook.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBook.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBookModule.java URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBookModule.java?rev=1072466&view=auto ============================================================================== --- commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBookModule.java (added) +++ commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBookModule.java Sun Feb 20 00:29:48 2011 @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.digester3.examples.addressbook; + +import org.apache.commons.digester3.AbstractRulesModule; + +/** + * See Main.java. + */ +public final class AddressBookModule extends AbstractRulesModule { + + @Override + protected void configure() { + forPattern("address-book/person") + // create a new instance of class Person, and push that + // object onto the digester stack of objects + .createObject().ofType(Person.class) + .then() + // map *any* attributes on the tag to appropriate + // setter-methods on the top object on the stack (the Person + // instance created by the preceeding rule). + // + // For example: + // if attribute "id" exists on the xml tag, and method setId + // with one parameter exists on the object that is on top of + // the digester object stack, then a call will be made to that + // method. The value will be type-converted from string to + // whatever type the target method declares (where possible), + // using the commons ConvertUtils functionality. + // + // Attributes on the xml tag for which no setter methods exist + // on the top object on the stack are just ignored. + .setProperties() + .then() + // call the addPerson method on the second-to-top object on + // the stack (the AddressBook object), passing the top object + // on the stack (the recently created Person object). + .setNext("addPerson"); + //-------------------------------------------------- + // when we encounter a "name" tag, call setName on the top + // object on the stack, passing the text contained within the + // body of that name element [specifying a zero parameter count + // implies one actual parameter, being the body text]. + // The top object on the stack will be a person object, because + // the pattern address-book/person always triggers the + // ObjectCreateRule we added previously. + forPattern("address-book/person/name") + .callMethod("setName").usingElementBodyAsArgument(); + //-------------------------------------------------- + // when we encounter an "email" tag, call addEmail on the top + // object on the stack, passing two parameters: the "type" + // attribute, and the text within the tag body. + forPattern("address-book/person/email") + .callMethod("addEmail").withParamTypes(String.class, String.class) + .then() + .callParam().ofIndex(0).fromAttribute("type") + .then() + .callParam().ofIndex(1); + //-------------------------------------------------- + // When we encounter an "address" tag, create an instance of class + // Address and push it on the digester stack of objects. After + // doing that, call addAddress on the second-to-top object on the + // digester stack (a "Person" object), passing the top object on + // the digester stack (the "Address" object). And also set things + // up so that for each child xml element encountered between the start + // of the address tag and the end of the address tag, the text + // contained in that element is passed to a setXXX method on the + // Address object where XXX is the name of the xml element found. + forPattern("address-book/person/address") + .createObject().ofType(Address.class) + .then() + .setNestedProperties() + .then() + .setNext("addAddress"); + } + +} Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBookModule.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBookModule.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/AddressBookModule.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Main.java URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Main.java?rev=1072466&view=auto ============================================================================== --- commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Main.java (added) +++ commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Main.java Sun Feb 20 00:29:48 2011 @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.digester3.examples.addressbook; + +import static org.apache.commons.digester3.DigesterLoader.newLoader; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.digester3.Digester; +import org.xml.sax.SAXException; + +/** + * A simple program to demonstrate the basic functionality of the + * Commons Digester module. + *

+ * This code will parse the provided "example.xml" file to build a tree + * of java objects, then cause those objects to print out their values + * to demonstrate that the input file has been processed correctly. + *

+ * As with all code, there are many ways of achieving the same goal; + * the solution here is only one possible solution to the problem. +*

+ * Very verbose comments are included here, as this class is intended + * as a tutorial; if you look closely at method "addRules", you will + * see that the amount of code required to use the Digester is actually + * quite low. + *

+ * Usage: java Main example.xml + */ +public class Main { + + /** + * Main method : entry point for running this example program. + *

+ * Usage: java Example example.xml + */ + public static void main(String[] args) { + if (args.length != 1) { + usage(); + System.exit(-1); + } + + String filename = args[0]; + + // Create a Digester instance + Digester d = newLoader(new AddressBookModule()).newDigester(); + + // Prime the digester stack with an object for rules to + // operate on. Note that it is quite common for "this" + // to be the object pushed. + AddressBook book = new AddressBook(); + d.push(book); + + // Process the input file. + try { + File srcfile = new File(filename); + d.parse(srcfile); + } catch (IOException ioe) { + System.out.println("Error reading input file:" + ioe.getMessage()); + System.exit(-1); + } catch (SAXException se) { + System.out.println("Error parsing input file:" + se.getMessage()); + System.exit(-1); + } + + // Print out all the contents of the address book, as loaded from + // the input file. + book.print(); + } + + private static void usage() { + System.out.println("Usage: java Main example.xml"); + } + +} Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Main.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Main.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Main.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Person.java URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Person.java?rev=1072466&view=auto ============================================================================== --- commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Person.java (added) +++ commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Person.java Sun Feb 20 00:29:48 2011 @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.digester3.examples.addressbook; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * See Main.java. + */ +public class Person { + + private final Map emails = new HashMap(); + + private final List

addresses = new ArrayList
(); + + private int id; + + private String category; + + private String name; + + /** + * A unique id for this person. Note that the Digester automatically + * converts the id to an integer. + */ + public void setId(int id) { + this.id = id; + } + + public void setCategory(String category) { + this.category = category; + } + + public void setName(String name) { + this.name = name; + } + + /** we assume only one email of each type... */ + public void addEmail(String type, String address) { + emails.put(type, address); + } + + public void addAddress(Address addr) { + addresses.add(addr); + } + + public void print() { + System.out.println("Person #" + id); + System.out.println(" category=" + category); + System.out.println(" name=" + name); + + for (Entry email : this.emails.entrySet()) { + String type = email.getKey(); + String address = email.getValue(); + + System.out.println(" email (type " + type + ") : " + address); + } + + for (Address addr : this.addresses) { + addr.print(System.out, 2); + } + } + +} Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Person.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Person.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: commons/sandbox/digester3/trunk/src/examples/addressbook/src/main/java/org/apache/commons/digester3/examples/addressbook/Person.java ------------------------------------------------------------------------------ svn:mime-type = text/plain