openamf/src/java/org/openamf/examples RecordSetTest.java,NONE,1.1 Person.java,NONE,1.1 RefsTester.java,NONE,1.1 SubmitToURL.java,NONE,1.1 Authentication.java,NONE,1.1 Test3.java,NONE,1.1 RSS.java,NONE,1.1 Directory.java,NONE,1.1 TestBean.java,NONE,1.1
[email protected] Wed, 20 Aug 2003 12:32:23 -0700
| Newsgroups | gmane.comp.java.openamf.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/openamf/openamf/src/java/org/openamf/examples In directory sc8-pr-cvs1:/tmp/cvs-serv2623/src/java/org/openamf/examples Added Files: RecordSetTest.java Person.java RefsTester.java SubmitToURL.java Authentication.java Test3.java RSS.java Directory.java TestBean.java Log Message: moved example classes from test pacakge to new examples package --- NEW FILE: RecordSetTest.java --- /* * www.openamf.org * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.openamf.examples; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.openamf.recordset.ASRecordSet; /** * @author Jason Calabrese <[email protected]> * @version $Revision: 1.1 $, $Date: 2003/08/20 19:32:21 $ */ public class RecordSetTest { private static Log log = LogFactory.getLog(RecordSetTest.class); /** * Normally you would return a java.sql.ResultSet, * but since this is a test I want to make sure a * RecordSet comes back * * @param sql * @param dbURL * @param jdbcDriver * @return */ public ASRecordSet getData(String sql, String dbURL, String jdbcDriver) { ASRecordSet asRecordSet = new ASRecordSet(); Connection conn = null; try { conn = getConnection(dbURL, jdbcDriver); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); asRecordSet.populate(rs); log.debug("populated asRecordSet with rs"); rs.close(); stmt.close(); } catch (Exception e) { log.error("Unable to execute sql", e); // return error as record set int rowCount = 25; List rows = new ArrayList(); for (int i = 0; i < rowCount; i++) { List row = new ArrayList(); row.add(e.getMessage() + (i + 1)); row.add(sql + (i + 1)); row.add(dbURL + (i + 1)); rows.add(row); } asRecordSet.populate(new String[]{"Error", "SQL", "dbUrl"}, rows); log.debug("populated asRecordSet with rows"); } return asRecordSet; } private Connection getConnection(String dbURL, String jdbcDriver) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException { Connection conn = null; //Load driver Class.forName(jdbcDriver).newInstance(); conn = DriverManager.getConnection(dbURL); return conn; } public static void main(String[] args) { ASRecordSet asRecordSet = new RecordSetTest().getData( "Select * from users", "jdbc:mysql://localhost/openamf?user=openamf&password=openamf", "com.mysql.jdbc.Driver"); System.out.println(asRecordSet); } } --- NEW FILE: Person.java --- /* * www.openamf.org * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.openamf.examples; import java.io.Serializable; import java.util.Date; import java.util.List; /** * @author Jason Calabrese <[email protected]> * @version $Revision: 1.1 $, $Date: 2003/08/20 19:32:21 $ */ public class Person implements Serializable { private String firstName; private String lastName; private String address; private String city; private String state; private int zipCode; private Date birthDate; private List extraInfo; public Person() { } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getState() { return state; } public void setState(String state) { this.state = state; } public int getZipCode() { return zipCode; } public void setZipCode(int zipCode) { this.zipCode = zipCode; } public Date getBirthDate() { return birthDate; } public void setBirthDate(Date birthDate) { this.birthDate = birthDate; } public List getExtraInfo() { return extraInfo; } public void setExtraInfo(List list) { extraInfo = list; } public String toString() { return firstName + " " + lastName; } } --- NEW FILE: RefsTester.java --- /* * www.openamf.org * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.openamf.examples; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * @author Radoslaw Sliwinski <madlyr at users.sourceforge.net> * @version $Revision: 1.1 $, $Date: 2003/08/20 19:32:21 $ */ public class RefsTester { private static Log log = LogFactory.getLog(RefsTester.class); public void testReferences(List refs) { log.debug("refs.size(): " + refs.size()); if (refs.size() == 2) { log.debug("Object 1 = Object2 ?: " + refs.get(0).equals(refs.get(1))); } } } --- NEW FILE: SubmitToURL.java --- /* * www.openamf.org * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.openamf.examples; import java.net.URL; import java.net.URLConnection; /** * @author Jason Calabrese <[email protected]> * @version $Revision: 1.1 $, $Date: 2003/08/20 19:32:21 $ */ public class SubmitToURL { public String submit(String urlString) { String result = null; try { URL url = new URL(urlString); URLConnection conn = url.openConnection(); result = conn.getContent().toString(); } catch (Exception e) { result = e.toString(); } return result; } public static void main(String[] args) { System.out.println(new SubmitToURL().submit( "http://lists.sourceforge.net/lists/subscribe/[email protected]&pw=test&pw-conf=test")); } } --- NEW FILE: Authentication.java --- /* * www.openamf.org * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.openamf.examples; import java.io.Serializable; /** * @author Jason Calabrese <[email protected]> * @version $Revision: 1.1 $, $Date: 2003/08/20 19:32:21 $ */ public class Authentication implements Serializable { } --- NEW FILE: Test3.java --- /* * www.openamf.org * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.openamf.examples; import java.util.Date; import java.util.List; import java.util.Map; import org.w3c.dom.Document; /** * @author Jason Calabrese <[email protected]> * @version $Revision: 1.1 $, $Date: 2003/08/20 19:32:21 $ */ public class Test3 { public Double getNumber(Double value) { return value; } public List getNumberArray(List value) { return value; } public String getString(String value) { return value; } public Date getDate(Date value) { return value; } public Document getXML(Document value) { return value; } public Map getPOJO(Map value) { return value; } } --- NEW FILE: RSS.java --- /* * www.openamf.org * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.openamf.examples; import java.io.IOException; import org.apache.commons.digester.rss.Channel; import org.apache.commons.digester.rss.RSSDigester; import org.xml.sax.SAXException; /** * @author Jason Calabrese <[email protected]> * @version $Revision: 1.1 $, $Date: 2003/08/20 19:32:21 $ */ public class RSS { public Channel getChannel(String rssURL) throws IOException, SAXException { Channel channel = null; RSSDigester digester = new RSSDigester(); channel = (Channel) digester.parse(rssURL); String url = "http://www.openamf.org/javadocs/index.html"; String desc = channel.getDescription() + "<br/><br/>Click <A href='" + url + "' target='_blank'><U>here</U></A> to view Java Doc's"; channel.setDescription(desc); return channel; } } --- NEW FILE: Directory.java --- /* * www.openamf.org * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.openamf.examples; import java.io.Serializable; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * @author Jason Calabrese <[email protected]> * @version $Revision: 1.1 $, $Date: 2003/08/20 19:32:21 $ */ public class Directory implements Serializable { protected static Log log = LogFactory.getLog(Directory.class); private List people = new ArrayList(); public void addPerson(Person person) { addPerson(person, null); } public void addPerson(Person person, Authentication authentication) { log.debug("Adding " + person + " to Directory "); if (authentication != null) { log.debug("got authentication"); } people.add(person); } public List getPeople(String name) { return getPeople(name, null); } public List getPeople(String name, Authentication authentication) { log.debug("getPeople(" + name + ")"); if (authentication != null) { log.debug("got authentication"); } List result = new ArrayList(); for (Iterator iter = people.iterator(); iter.hasNext();) { Person person = (Person) iter.next(); if (person.getFirstName().equals(name) || person.getLastName().equals(name)) { log.debug("Adding " + person + " to result"); result.add(person); } } return result; } public List getPeople(int zipCode) { return getPeople(zipCode, null); } public List getPeople(int zipCode, Authentication authentication) { log.debug("getPeople(" + zipCode + ")"); if (authentication != null) { log.debug("got authentication"); } List result = new ArrayList(); for (Iterator iter = people.iterator(); iter.hasNext();) { Person person = (Person) iter.next(); if (person.getZipCode() == zipCode) { log.debug("Adding " + person + " to result"); result.add(person); } } return result; } } --- NEW FILE: TestBean.java --- /* * www.openamf.org * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.openamf.examples; /** * @author Jason Calabrese <[email protected]> * @version $Revision: 1.1 $, $Date: 2003/08/20 19:32:21 $ */ public class TestBean { private String testValue; /** * Returns the testValue. * @return String */ public String getTestValue() { return testValue; } /** * Sets the testValue. * @param testValue The testValue to set */ public void setTestValue(String testValue) { this.testValue = testValue; } } ------------------------------------------------------- This SF.net email is sponsored by Dice.com. Did you know that Dice has over 25,000 tech jobs available today? From careers in IT to Engineering to Tech Sales, Dice has tech jobs from the best hiring companies. http://www.dice.com/index.epl?rel_code=104