You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by pi...@apache.org on 2004/11/01 16:55:34 UTC

svn commit: rev 56245 - in cocoon/whiteboard/kernel/src/org/apache/cocoon/kernel: configuration startup

Author: pier
Date: Mon Nov  1 07:55:33 2004
New Revision: 56245

Modified:
   cocoon/whiteboard/kernel/src/org/apache/cocoon/kernel/configuration/Configuration.java
   cocoon/whiteboard/kernel/src/org/apache/cocoon/kernel/startup/Main.java
Log:
Add support for primitive types to Configuration

Modified: cocoon/whiteboard/kernel/src/org/apache/cocoon/kernel/configuration/Configuration.java
==============================================================================
--- cocoon/whiteboard/kernel/src/org/apache/cocoon/kernel/configuration/Configuration.java	(original)
+++ cocoon/whiteboard/kernel/src/org/apache/cocoon/kernel/configuration/Configuration.java	Mon Nov  1 07:55:33 2004
@@ -738,6 +738,17 @@
      */
     public Object getValueAs(Class type)
     throws ConfigurationException {
+        /* Normalize primitive class types */
+        if (type.isPrimitive()) {
+            if (type.equals(boolean.class)) type = Boolean.class;
+            else if (type.equals(double.class)) type = Double.class;
+            else if (type.equals(float.class)) type = Float.class;
+            else if (type.equals(int.class)) type = Integer.class;
+            else if (type.equals(long.class)) type = Long.class;
+            else throw new ConfigurationException("Unsupported primitive: " + type);
+        }
+
+        /* Return the correct object */
         if (Boolean.class.equals(type)) {
             return new Boolean(this.getBooleanValue());
         } else if (Double.class.equals(type)) {
@@ -751,6 +762,8 @@
         } else if (String.class.equals(type)) {
             return this.getStringValue();
         }
+
+        /* Fail miserably */
         throw new ConfigurationException("Unsupported type " + type.getName());
     }
 
@@ -1000,6 +1013,17 @@
      */
     public Object getAttributeAs(String name, Class type)
     throws ConfigurationException {
+        /* Normalize primitive class types */
+        if (type.isPrimitive()) {
+            if (type.equals(boolean.class)) type = Boolean.class;
+            else if (type.equals(double.class)) type = Double.class;
+            else if (type.equals(float.class)) type = Float.class;
+            else if (type.equals(int.class)) type = Integer.class;
+            else if (type.equals(long.class)) type = Long.class;
+            else throw new ConfigurationException("Unsupported primitive: " + type);
+        }
+
+        /* Return the correct object */
         if (Boolean.class.equals(type)) {
             return new Boolean(this.getBooleanAttribute(name));
         } else if (Double.class.equals(type)) {
@@ -1013,7 +1037,9 @@
         } else if (String.class.equals(type)) {
             return this.getStringAttribute(name);
         }
-        throw new ConfigurationException("Unsupported type " + type.getName());
+
+        /* Fail miserably */
+        throw new ConfigurationException("Unsupported type: " + type.getName());
     }
 
     /* ====================================================================== */

Modified: cocoon/whiteboard/kernel/src/org/apache/cocoon/kernel/startup/Main.java
==============================================================================
--- cocoon/whiteboard/kernel/src/org/apache/cocoon/kernel/startup/Main.java	(original)
+++ cocoon/whiteboard/kernel/src/org/apache/cocoon/kernel/startup/Main.java	Mon Nov  1 07:55:33 2004
@@ -43,9 +43,18 @@
     /**
      * <p>Create a new {@link Main} instance.</p>
      */
-    private Main(Deployer deployer) {
+    private Main(Deployer deployer) throws Throwable {
         if (deployer == null) throw new NullPointerException("Null deployer");
         this.deployer = deployer;
+
+        Object datasource = deployer.lookup("test");
+        System.err.println("CLASS: " + datasource.getClass().getName());
+        Class interfaces[] = datasource.getClass().getInterfaces();
+        System.err.println("INTERFACES: " + interfaces.length);
+        for (int k = 0; k < interfaces.length; k++) {
+            System.err.println(" - " + interfaces[k].getName());
+        }
+        ((javax.sql.DataSource)deployer.lookup("test")).getConnection();
     }
     
     /**