Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 89668 invoked from network); 28 Apr 2006 20:42:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 28 Apr 2006 20:42:36 -0000 Received: (qmail 3964 invoked by uid 500); 28 Apr 2006 20:42:36 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 3938 invoked by uid 500); 28 Apr 2006 20:42:35 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 3927 invoked by uid 99); 28 Apr 2006 20:42:35 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Apr 2006 13:42:35 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Apr 2006 13:42:35 -0700 Received: from ajax.apache.org (localhost.localdomain [127.0.0.1]) by ajax.apache.org (Postfix) with ESMTP id 1D56BD49FE for ; Fri, 28 Apr 2006 21:42:14 +0100 (BST) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Apache Wiki To: derby-commits@db.apache.org Date: Fri, 28 Apr 2006 20:42:14 -0000 Message-ID: <20060428204214.19576.26618@ajax.apache.org> Subject: [Db-derby Wiki] Update of "DatabaseUtilitiesSource" by DonaldMcLean X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Dear Wiki user, You have subscribed to a wiki page or wiki category on "Db-derby Wiki" for change notification. The following page has been changed by DonaldMcLean: http://wiki.apache.org/db-derby/DatabaseUtilitiesSource New page: ## Please edit system and help pages ONLY in the moinmaster wiki! For more ## information, please see MoinMaster:MoinPagesEditorGroup. ##master-page:Unknown-Page ##master-date:Unknown-Date ##acl MoinPagesEditorGroup:read,write,delete,revert All:read #format wiki #language en == Database Utilites source for DatabaseManager == {{{ package your.package.here; import org.jdom.Document; import org.jdom.Element; import org.jdom.input.SAXBuilder; import java.io.File; import java.io.InputStream; import java.util.ArrayList; /** * Created: * Date: Sep 4, 2005 * Time: 10:01:39 PM */ public class DatabaseUtilities { public static boolean deleteAnyFile(File file) { if (!file.exists()) { return true; } if (!file.isDirectory()) { return file.delete(); } return deleteDirectory(file); } /** * Loads the .xml file with the same SEEN_NAME as the class from the * same package as the class. * * @param interestedClass * @return XML document for interestedClass */ public static Document getXMLResource(Class interestedClass) { String className = interestedClass.getName(); int dotIndex = className.lastIndexOf('.') + 1; String resourceName = className.substring(dotIndex) + ".xml"; return getXMLResource(resourceName, interestedClass); } public static Document getXMLResource(String resourceName, Class interestedClass) { System.out.println("[Utilities : getXMLResource]: resourceName: " + resourceName); InputStream stream = interestedClass.getResourceAsStream(resourceName); if (stream == null) { return null; } return loadDomDocument(stream); } /** * Loads and returns the JDOM Document from the given file. */ private static Document loadDomDocument(InputStream iFile) { SAXBuilder builder = new SAXBuilder(); Document lDocument = null; builder.setValidation(false); try { lDocument = builder.build(iFile); } catch (Exception e) { e.printStackTrace(); } return lDocument; } // loadDomDocument /** * @param directory - item to be deleted. * @return success or failure */ private static boolean deleteDirectory(File directory) { File[] contents = directory.listFiles(); for (int i = 0; i < contents.length; i++) { File next = contents[i]; boolean result = deleteAnyFile(next); if (!result) { return false; } } return directory.delete(); } static public Class getClass(Element classNameElement) { Class result = null; String className = classNameElement.getText(); System.out.println("[Utilities.getClass] getting class '" + className + "'."); result = loadClass(className); System.out.println("[ColumnType.getClass] got '" + result + "'."); return result; } public static Class loadClass(String className) { Class result = null; try { result = Class.forName(className); } catch (ClassNotFoundException e) { System.out.println("[ColumnType.ColumnType] Unable to load class '" + className + "'."); } return result; } } }}}