You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by cb...@apache.org on 2005/06/26 11:56:25 UTC

svn commit: r201731 - in /ibatis/trunk/java/mapper/mapper2: doc/ src/com/ibatis/common/logging/ src/com/ibatis/common/logging/jakarta/ src/com/ibatis/common/logging/jdk14/ src/com/ibatis/common/logging/log4j/ src/com/ibatis/common/logging/nologging/ sr...

Author: cbegin
Date: Sat Jun 25 00:18:49 2005
New Revision: 201731

URL: http://svn.apache.org/viewcvs?rev=201731&view=rev
Log:
Removed dependency on Commons Logging, will autodetect and use Commons Logging, Log4J, JDK 1.4 or no logging (missed non-versioned files last commit)

AND

Improved entity resolvers to be smarter, checks both system and public IDs, and both ibatis.com and apache.org

Added:
    ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/Log.java
    ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/LogFactory.java
    ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/jakarta/
    ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/jdk14/
    ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/log4j/
    ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/nologging/
Modified:
    ibatis/trunk/java/mapper/mapper2/doc/release.txt
    ibatis/trunk/java/mapper/mapper2/src/com/ibatis/dao/engine/builder/xml/DaoClasspathEntityResolver.java
    ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapClasspathEntityResolver.java

Modified: ibatis/trunk/java/mapper/mapper2/doc/release.txt
URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/mapper/mapper2/doc/release.txt?rev=201731&r1=201730&r2=201731&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/doc/release.txt (original)
+++ ibatis/trunk/java/mapper/mapper2/doc/release.txt Sat Jun 25 00:18:49 2005
@@ -11,7 +11,8 @@
  o Fixed IBATIS-146 consumes additional result sets before retrieving output params (JTDS fix)
  o Fixed IBATIS-130 parameter maps don't allow for complete TypeHandler implementations
  o Removed dependency on Commons Logging, will autodetect and use Commons Logging, Log4J, JDK 1.4 or no logging
- 
+ o Improved entity resolvers to be smarter, checks both system and public IDs, and both ibatis.com and apache.org  
+
 ------------------------------
  2.1.0 - May 16, 2004
 ------------------------------

Added: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/Log.java
URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/Log.java?rev=201731&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/Log.java (added)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/Log.java Sat Jun 25 00:18:49 2005
@@ -0,0 +1,13 @@
+package com.ibatis.common.logging;
+
+public interface Log {
+
+  boolean isDebugEnabled();
+
+  void error(String s, Exception e);
+
+  public void debug(String s);
+
+  public void warn(String s);
+
+}

Added: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/LogFactory.java
URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/LogFactory.java?rev=201731&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/LogFactory.java (added)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/common/logging/LogFactory.java Sat Jun 25 00:18:49 2005
@@ -0,0 +1,35 @@
+package com.ibatis.common.logging;
+
+import java.lang.reflect.Constructor;
+
+public class LogFactory {
+
+  private static Constructor logConstructor;
+
+  static {
+    tryImplementation("org.apache.commons.logging.LogFactory", "com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl");
+    tryImplementation("org.apache.log4j.Logger", "com.ibatis.common.logging.log4j.Log4jImpl");
+    tryImplementation("java.util.logging.Logger", "com.ibatis.common.logging.jdk14.Jdk14LoggingImpl");
+    tryImplementation("java.lang.Object", "com.ibatis.common.logging.nologging.NoLoggingImpl");
+  }
+
+  private static void tryImplementation(String testClassName, String implClassName) {
+    if (logConstructor == null) {
+      try {
+        Class.forName(testClassName);
+        Class implClass = Class.forName(implClassName);
+        logConstructor = implClass.getConstructor(new Class[]{Class.class});
+      } catch (Throwable t) {
+      }
+    }
+  }
+
+  public static Log getLog(Class aClass) {
+    try {
+      return (Log)logConstructor.newInstance(new Object[]{aClass});
+    } catch (Throwable t) {
+      throw new RuntimeException("Error creating logger for class " + aClass + ".  Cause: " + t, t);
+    }
+  }
+
+}

Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/dao/engine/builder/xml/DaoClasspathEntityResolver.java
URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/dao/engine/builder/xml/DaoClasspathEntityResolver.java?rev=201731&r1=201730&r2=201731&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/dao/engine/builder/xml/DaoClasspathEntityResolver.java (original)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/dao/engine/builder/xml/DaoClasspathEntityResolver.java Sat Jun 25 00:18:49 2005
@@ -21,12 +21,24 @@
 import org.xml.sax.SAXException;
 
 import java.io.InputStream;
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
 
 public class DaoClasspathEntityResolver implements EntityResolver {
 
-  private static final String SYSTEM_ID_DAO = "http://www.ibatis.com/dtd/dao-2.dtd";
   private static final String DTD_PATH_DAO = "com/ibatis/dao/engine/builder/xml/dao-2.dtd";
 
+  private static final Map doctypeMap = new HashMap();
+
+  static {
+    doctypeMap.put("http://www.ibatis.com/dtd/dao-2.dtd", DTD_PATH_DAO);
+    doctypeMap.put("http://ibatis.apache.org/dtd/dao-2.dtd", DTD_PATH_DAO);
+    doctypeMap.put("-//iBATIS.com//DTD DAO Configuration 2.0", DTD_PATH_DAO);
+    doctypeMap.put("-//iBATIS.com//DTD DAO Config 2.0", DTD_PATH_DAO);
+  }
+
+
   /**
    * Converts a public DTD into a local one
    *
@@ -40,11 +52,16 @@
     InputSource source = null;
 
     try {
-      if (systemId.equals(SYSTEM_ID_DAO)) {
-        InputStream in = Resources.getResourceAsStream(DTD_PATH_DAO);
-        source = new InputSource(in);
-      } else {
-        source = null;
+      String path = (String) doctypeMap.get(publicId);
+      path = (String) doctypeMap.get(systemId);
+      if (path != null) {
+        InputStream in = null;
+        try {
+          in = Resources.getResourceAsStream(path);
+          source = new InputSource(in);
+        } catch (IOException e) {
+          // ignore, null is ok
+        }
       }
     } catch (Exception e) {
       throw new SAXException(e.toString());

Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapClasspathEntityResolver.java
URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapClasspathEntityResolver.java?rev=201731&r1=201730&r2=201731&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapClasspathEntityResolver.java (original)
+++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapClasspathEntityResolver.java Sat Jun 25 00:18:49 2005
@@ -21,16 +21,31 @@
 import org.xml.sax.SAXException;
 
 import java.io.InputStream;
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
 
 /**
  * Offline entity resolver for the iBATIS DTDs
  */
 public class SqlMapClasspathEntityResolver implements EntityResolver {
 
-  private static final String SYSTEM_ID_SQL_MAP_CONFIG = "http://www.ibatis.com/dtd/sql-map-config-2.dtd";
-  private static final String SYSTEM_ID_SQL_MAP = "http://www.ibatis.com/dtd/sql-map-2.dtd";
-  private static final String DTD_PATH_SQL_MAP_CONFIG = "com/ibatis/sqlmap/engine/builder/xml/sql-map-config-2.dtd";
-  private static final String DTD_PATH_SQL_MAP = "com/ibatis/sqlmap/engine/builder/xml/sql-map-2.dtd";
+  private static final String SQL_MAP_CONFIG_DTD = "com/ibatis/sqlmap/engine/builder/xml/sql-map-config-2.dtd";
+  private static final String SQL_MAP_DTD = "com/ibatis/sqlmap/engine/builder/xml/sql-map-2.dtd";
+
+  private static final Map doctypeMap = new HashMap();
+
+  static {
+    doctypeMap.put("http://www.ibatis.com/dtd/sql-map-config-2.dtd", SQL_MAP_CONFIG_DTD);
+    doctypeMap.put("http://ibatis.apache.org/dtd/sql-map-config-2.dtd", SQL_MAP_CONFIG_DTD);
+    doctypeMap.put("-//iBATIS.com//DTD SQL Map Config 2.0//EN", SQL_MAP_CONFIG_DTD);
+
+    doctypeMap.put("http://www.ibatis.com/dtd/sql-map-2.dtd", SQL_MAP_DTD);
+    doctypeMap.put("http://ibatis.apache.org/dtd/sql-map-2.dtd", SQL_MAP_DTD);
+    doctypeMap.put("-//iBATIS.com//DTD SQL Map 2.0//EN", SQL_MAP_DTD);
+  }
+
 
   /**
    * Converts a public DTD into a local one
@@ -43,21 +58,21 @@
   public InputSource resolveEntity(String publicId, String systemId)
       throws SAXException {
     InputSource source = null;
-
     try {
-      if (systemId.equals(SYSTEM_ID_SQL_MAP_CONFIG)) {
-        InputStream in = Resources.getResourceAsStream(DTD_PATH_SQL_MAP_CONFIG);
-        source = new InputSource(in);
-      } else if (systemId.equals(SYSTEM_ID_SQL_MAP)) {
-        InputStream in = Resources.getResourceAsStream(DTD_PATH_SQL_MAP);
-        source = new InputSource(in);
-      } else {
-        source = null;
+      String path = (String) doctypeMap.get(publicId);
+      path = (String) doctypeMap.get(systemId);
+      if (path != null) {
+        InputStream in = null;
+        try {
+          in = Resources.getResourceAsStream(path);
+          source = new InputSource(in);
+        } catch (IOException e) {
+          // ignore, null is ok
+        }
       }
     } catch (Exception e) {
       throw new SAXException(e.toString());
     }
-
     return source;
   }