HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Build To Spec"
Vol. 6, Issue 7, p. 48

	


Listing 1

public class AccountEJB implements EntityBean {

   private String userId;
   private ContactInformation info;
   // ...
}

public class ContactInformation implements Serializable {

   private String telephone;
   private String address;
   // ... etc ...
}




Listing 2

Connection c;
PreparedStatement ps;
ResultSet rs;

try {
   c = dataSource.getConnection();
   ps = c.prepareStatement(statement);
   rs = ps.executeQuery();

   // Do stuff with 'rs'.
}
catch (SQLException se) {
   // Handle this exception.
}
finally {
   if (rs != null)
       rs.close();

   // Close statement before connection.
   if (ps != null)
       ps.close();
   if (c != null)
       c.close();
}



Listing 3

import java.io.File;
import java.io.StringWriter;
import java.io.PrintStream;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;

public class XMLChecker {

   public static boolean parseFile(File file, PrintStream out,
                                   boolean validate) {
       try {
           Document document = null;
           DocumentBuilderFactory docBuilderFactory = null;
           DocumentBuilder docBuilder = null;
           try {
               docBuilderFactory = DocumentBuilderFactory.newInstance();
               docBuilderFactory.setValidating(validate);
               if (docBuilderFactory != null) {
                   docBuilder = docBuilderFactory.newDocumentBuilder();
            }
           } catch (ParserConfigurationException pce) {
               out.println(pce);
           }
           if (docBuilder != null) {
               document = docBuilder.parse(file);
           }
           return true;
       } catch (java.io.IOException ioe) {
           out.println("Caught IO exception" + ioe);
       } catch (org.xml.sax.SAXParseException spe) {
           out.println(spe);
       } catch ( org.xml.sax.SAXException se) {
           System.out.println(se);
       }

       return false;
   }
}



Listing 4



appA1.ear:
       x.war              References classes in ejbA2.jar
       ejbA1.jar
       yUtil.jar

appA2.ear:
        z.war
       ejbA2.jar
       zUtil.jar

  
 
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.