You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/06/14 23:14:49 UTC

svn commit: r190657 [12/23] - in /incubator/beehive/trunk/system-controls: ./ ant/ samples/ejb/ samples/ejb/client/org/apache/beehive/controls/system/ejb/sample/client/ samples/ejb/control/org/apache/beehive/controls/system/ejb/sample/control/ samples/ejb/ejb/META-INF/ samples/ejb/ejb/org/apache/beehive/controls/system/ejb/sample/bean/ samples/jdbc/jdbcControlSample/ samples/jdbc/jdbcControlSample/META-INF/ samples/jdbc/jdbcControlSample/WEB-INF/ samples/jdbc/jdbcControlSample/WEB-INF/src/ samples/jdbc/jdbcControlSample/WEB-INF/src/controls/ samples/jdbc/jdbcControlSample/WEB-INF/src/servlet/ samples/jdbc/jdbcControlSample/WEB-INF/src/shared/ samples/jms/ samples/jms/src/org/apache/beehive/controls/system/jms/samples/ samples/webservice/amazon/ samples/webservice/amazon/junit/ samples/webservice/amazon/schemas/ samples/webservice/common/src/test/ samples/webservice/google/ samples/webservice/google/junit/model/ samples/webservice/google/rpc_schemas/ samples/webservice/google/servlet/ samples/webservice/wsm_samples_client/ samples/webservice/wsm_samples_client/junit/ samples/webservice/wsm_samples_client/junit/org/wsm/samples/client/header/ samples/webservice/wsm_samples_client/junit/org/wsm/samples/client/webparam/ samples/webservice/xmlbeans/ samples/webservice/xmlbeans/junit/ src/ejb/ src/ejb/org/apache/beehive/controls/system/ejb/ src/ejb/schema/ src/jdbc/ src/jdbc/org/apache/beehive/controls/system/jdbc/ src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ src/jms/ src/jms/org/apache/beehive/controls/system/jms/ src/jms/org/apache/beehive/controls/system/jms/impl/ src/jms/org/apache/beehive/controls/system/jndi/ src/jms/org/apache/beehive/controls/system/jndi/impl/ src/webservice/ src/webservice/org/apache/beehive/controls/system/webservice/ src/webservice/org/apache/beehive/controls/system/webservice/generator/ src/webservice/org/apache/beehive/controls/system/webservice/jaxrpc/ src/webservice/org/apache/beehive/controls/system/webservice/utils/ test/ant/ test/conf/ test/src/jdbc/controls/ test/src/jdbc/controls/org/apache/beehive/controls/system/jdbc/test/dbconnection/ test/src/jdbc/controls/org/apache/beehive/controls/system/jdbc/test/errors/ test/src/jdbc/controls/org/apache/beehive/controls/system/jdbc/test/results/ test/src/jdbc/controls/schemas/badusers/ test/src/jdbc/controls/schemas/users/ test/src/jdbc/jdbc-container/ test/src/jdbc/jdbc-container/application/ test/src/jdbc/jdbc-container/src/org/apache/beehive/controls/system/jdbc/containertest/ test/src/jdbc/jdbc-container/webapp/WEB-INF/ test/src/jdbc/jdbc-container/webapp/conf/Catalina/localhost/ test/src/jdbc/junitTests/ test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/dbconnection/ test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/errors/ test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/ test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/sqlparser/ test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/utils/ test/src/webservice/ test/src/webservice/jcxgen-tests/ test/src/webservice/jcxgen-tests/tests/org/apache/beehive/controls/system/webservice/units/jcxgen/ test/src/webservice/schemas/ test/src/webservice/servers/webapp/WEB-INF/ test/src/webservice/servers/webapp/WEB-INF/src/org/apache/beehive/doclitwrap/ test/src/webservice/servers/webapp/WEB-INF/src/web/ test/src/webservice/servers/webapp/WEB-INF/webservices/web/complex/ test/src/webservice/tests/org/apache/beehive/controls/system/webservice/units/dlwservice/

Modified: incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/RowToXmlObjectMapper.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/RowToXmlObjectMapper.java?rev=190657&r1=190656&r2=190657&view=diff
==============================================================================
--- incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/RowToXmlObjectMapper.java (original)
+++ incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/RowToXmlObjectMapper.java Tue Jun 14 14:14:42 2005
@@ -1,325 +1,325 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * $Header:$
- */
-
-package org.apache.beehive.controls.system.jdbc;
-
-import org.apache.beehive.controls.api.ControlException;
-import org.apache.xmlbeans.SchemaProperty;
-import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.util.Calendar;
-import java.util.HashMap;
-
-/**
- * Maps a ResultSet row to an XmlObject.
- */
-public class RowToXmlObjectMapper extends RowMapper {
-
-    private final int _columnCount;
-    private final SchemaType _schemaType;
-
-    private SetterMethod[] _setterMethods;
-    private final Object[] _args = new Object[1];
-
-    /**
-     * Create a new RowToXmlObjectMapper.
-     *
-     * @param resultSet       ResultSet to map
-     * @param returnTypeClass Class to map to.
-     * @param cal             Calendar instance for date/time mappings.
-     * @throws SQLException on error.
-     */
-    RowToXmlObjectMapper(ResultSet resultSet, Class returnTypeClass, Calendar cal)
-            throws SQLException {
-        super(resultSet, returnTypeClass, cal);
-
-        _columnCount = resultSet.getMetaData().getColumnCount();
-        _schemaType = getSchemaType(_returnTypeClass);
-        _setterMethods = null;
-    }
-
-    /**
-     * map a row from the ResultSet to an XmlObject instance
-     *
-     * @return An XmlObject instance.
-     */
-    public Object mapRowToReturnType() {
-
-        Object resultObject = null;
-        if (_columnCount == 1) {
-
-            final int typeId = _tmf.getTypeId(_returnTypeClass);
-
-            try {
-                if (typeId != TypeMappingsFactory.TYPE_UNKNOWN) {
-                    return extractColumnValue(1, typeId);
-                } else {
-                    // we still might want a single value (i.e. java.util.Date)
-                    Object val = extractColumnValue(1, typeId);
-                    if (_returnTypeClass.isAssignableFrom(val.getClass())) {
-                        return val;
-                    }
-                }
-            } catch (SQLException e) {
-                throw new ControlException(e.getMessage(), e);
-            }
-        }
-
-        if (_setterMethods == null) {
-            try {
-                getResultSetMappings();
-            } catch (SQLException e) {
-                throw new ControlException(e.getMessage(), e);
-            }
-        }
-
-        resultObject = XmlObject.Factory.newInstance(new XmlOptions().setDocumentType(_schemaType));
-
-        for (int i = 1; i < _setterMethods.length; i++) {
-            Method setterMethod = _setterMethods[i].getSetter();
-            Object resultValue = null;
-
-            try {
-                resultValue = extractColumnValue(i, _setterMethods[i].getParameterType());
-
-                // if the setter is for an xmlbean enum type, convert the extracted resultset column
-                // value to the proper xmlbean enum type. All xmlbean enums are derived from the class
-                // StringEnumAbstractBase
-                if (_setterMethods[i].getParameterType() == TypeMappingsFactory.TYPE_XMLBEAN_ENUM) {
-                    Class parameterClass = _setterMethods[i].getParameterClass();
-                    Method m = parameterClass.getMethod("forString", new Class[]{String.class});
-                    resultValue = m.invoke(null, new Object[]{resultValue});
-                }
-
-                _args[0] = resultValue;
-                setterMethod.invoke(resultObject, _args);
-
-                if (_setterMethods[i].getNilable() != null) {
-                    if (_resultSet.wasNull()) {
-                        _setterMethods[i].getNilable().invoke(resultObject, (Object[]) null);
-                    }
-                }
-            } catch (SQLException se) {
-                throw new ControlException(se.getMessage(), se);
-            } catch (IllegalArgumentException iae) {
-                try {
-                    ResultSetMetaData md = _resultSet.getMetaData();
-                    throw new ControlException("The declared Java type for method " + setterMethod.getName()
-                                               + setterMethod.getParameterTypes()[0].toString()
-                                               + " is incompatible with the SQL format of column " + md.getColumnName(i).toString()
-                                               + md.getColumnTypeName(i).toString()
-                                               + " which returns objects of type " + resultValue.getClass().getName());
-                } catch (SQLException e) {
-                    throw new ControlException(e.getMessage(), e);
-                }
-            } catch (IllegalAccessException e) {
-                throw new ControlException("IllegalAccessException when trying to access method " + setterMethod.getName(), e);
-            } catch (NoSuchMethodException e) {
-                throw new ControlException("NoSuchMethodException when trying to map schema enum value using Enum.forString().", e);
-            } catch (InvocationTargetException e) {
-                throw new ControlException("IllegalInvocationException when trying to access method " + setterMethod.getName(), e);
-            }
-        }
-        return resultObject;
-    }
-
-
-// ///////////////////////////////////////////////// private methods /////////////////////////////////////////////////
-
-    /**
-     * Build the necessary structures to do the mapping
-     *
-     * @throws SQLException
-     */
-    private void getResultSetMappings() throws SQLException {
-
-        //
-        // special case for XmlObject, find factory class
-        //
-        if (_schemaType.isDocumentType()) {
-            return;
-        }
-
-        final String[] keys = getKeysFromResultSet();
-
-        //
-        // find setters for return class
-        //
-        HashMap<String, Method> mapFields = new HashMap<String, Method>(_columnCount * 2);
-        for (int i = 1; i <= _columnCount; i++) {
-            mapFields.put(keys[i], null);
-        }
-
-        // public methods
-        Method[] classMethods = _returnTypeClass.getMethods();
-        for (Method method : classMethods) {
-
-            if (isSetterMethod(method)) {
-                final String fieldName = method.getName().substring(3).toUpperCase();
-                if (mapFields.containsKey(fieldName)) {
-                    mapFields.put(fieldName, method);
-                }
-            }
-        }
-
-        // finally actually init the fields array
-        _setterMethods = new SetterMethod[_columnCount + 1];
-
-        for (int i = 1; i < _setterMethods.length; i++) {
-            Method setterMethod = mapFields.get(keys[i]);
-            if (setterMethod == null) {
-                throw new ControlException("Unable to map the SQL column " + keys[i]
-                                           + " to a field on the " + _returnTypeClass.getName() +
-                                           " class. Mapping is done using a case insensitive comparision of SQL ResultSet "
-                                           + "columns to public setter methods on the return class.");
-            }
-
-            _setterMethods[i] = new SetterMethod(setterMethod);
-        }
-    }
-
-    /**
-     * Build a String array of column names from the ResultSet.
-     *
-     * @return A String array containing the column names contained within the ResultSet.
-     * @throws SQLException on error
-     */
-    protected String[] getKeysFromResultSet()
-            throws SQLException {
-
-        String[] keys = super.getKeysFromResultSet();
-
-        // check schemaProperty mapping names for more accurate column->field mapping
-        SchemaProperty[] props = _schemaType.getElementProperties();
-        for (int i = 0; i < props.length; i++) {
-
-            int col = -1;
-            try {
-                col = _resultSet.findColumn(props[i].getName().getLocalPart());
-            } catch (SQLException x) {
-            }
-
-            if (col > 0) {
-                keys[col] = props[i].getJavaPropertyName().toUpperCase();
-            }
-        }
-        return keys;
-    }
-
-    /**
-     * Get the SchemaType for the specified class.
-     *
-     * @param returnType Class to get the SchemaType for.
-     * @return SchemaType
-     */
-    private SchemaType getSchemaType(Class returnType) {
-        SchemaType schemaType = null;
-        if (XmlObject.class.isAssignableFrom(returnType)) {
-            try {
-                Field f = returnType.getField("type");
-                if (SchemaType.class.isAssignableFrom(f.getType()) && Modifier.isStatic(f.getModifiers())) {
-                    schemaType = (SchemaType) f.get(null);
-                }
-            } catch (NoSuchFieldException x) {
-            } catch (IllegalAccessException x) {
-            }
-        }
-        return schemaType;
-    }
-
-    // /////////////////////////////////////////////INNER CLASSES/////////////////////////////////////////////////
-
-    /**
-     * Helper class which contains setter method information.
-     */
-    private final class SetterMethod {
-        private final Method _setter;
-        private final int _parameterType;
-        private final Class _parameterClass;
-        private final Method _nilable;
-
-        /**
-         * Create a new setter method.
-         *
-         * @param setter Method instance.
-         */
-        SetterMethod(Method setter) {
-            _setter = setter;
-            _parameterClass = _setter.getParameterTypes()[0];
-            _parameterType = _tmf.getTypeId(_parameterClass);
-            _nilable = isNilable();
-        }
-
-        /**
-         * Return the setter method.
-         *
-         * @return Method
-         */
-        Method getSetter() { return _setter; }
-
-        /**
-         * Return the class of the setter method's paramater.
-         *
-         * @return Class of the setter method's param.
-         */
-        Class getParameterClass() { return _parameterClass; }
-
-        /**
-         * Get the type of the methods paramter.
-         * Type is defined by the TypeMappingsFactory, prefixed by TYPE_.
-         *
-         * @return int type.
-         */
-        int getParameterType() { return _parameterType; }
-
-        /**
-         * Get the nilable method for this setter.
-         *
-         * @return Method.
-         */
-        Method getNilable() { return _nilable; }
-
-        /**
-         * This takes care of the special case for xml beans return types.
-         * since they return primitive types even if they are nillable, we
-         * must explicitly call setNil after getting the column out of the resultSet.
-         * for that, we need to keep track of each field's setNil method.
-         * if the field is not nillable, it will not have a setNil method, and
-         * that array index will be null.
-         *
-         * @return Method
-         */
-        private Method isNilable() {
-            try {
-                return _returnTypeClass.getMethod("setNil" + _setter.getName().substring(3), new Class[]{});
-            } catch (NoSuchMethodException e) {
-                // NOOP - just means there is no setNil
-            }
-            return null;
-        }
-    }
-}
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc;
+
+import org.apache.beehive.controls.api.ControlException;
+import org.apache.xmlbeans.SchemaProperty;
+import org.apache.xmlbeans.SchemaType;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.Calendar;
+import java.util.HashMap;
+
+/**
+ * Maps a ResultSet row to an XmlObject.
+ */
+public class RowToXmlObjectMapper extends RowMapper {
+
+    private final int _columnCount;
+    private final SchemaType _schemaType;
+
+    private SetterMethod[] _setterMethods;
+    private final Object[] _args = new Object[1];
+
+    /**
+     * Create a new RowToXmlObjectMapper.
+     *
+     * @param resultSet       ResultSet to map
+     * @param returnTypeClass Class to map to.
+     * @param cal             Calendar instance for date/time mappings.
+     * @throws SQLException on error.
+     */
+    RowToXmlObjectMapper(ResultSet resultSet, Class returnTypeClass, Calendar cal)
+            throws SQLException {
+        super(resultSet, returnTypeClass, cal);
+
+        _columnCount = resultSet.getMetaData().getColumnCount();
+        _schemaType = getSchemaType(_returnTypeClass);
+        _setterMethods = null;
+    }
+
+    /**
+     * map a row from the ResultSet to an XmlObject instance
+     *
+     * @return An XmlObject instance.
+     */
+    public Object mapRowToReturnType() {
+
+        Object resultObject = null;
+        if (_columnCount == 1) {
+
+            final int typeId = _tmf.getTypeId(_returnTypeClass);
+
+            try {
+                if (typeId != TypeMappingsFactory.TYPE_UNKNOWN) {
+                    return extractColumnValue(1, typeId);
+                } else {
+                    // we still might want a single value (i.e. java.util.Date)
+                    Object val = extractColumnValue(1, typeId);
+                    if (_returnTypeClass.isAssignableFrom(val.getClass())) {
+                        return val;
+                    }
+                }
+            } catch (SQLException e) {
+                throw new ControlException(e.getMessage(), e);
+            }
+        }
+
+        if (_setterMethods == null) {
+            try {
+                getResultSetMappings();
+            } catch (SQLException e) {
+                throw new ControlException(e.getMessage(), e);
+            }
+        }
+
+        resultObject = XmlObject.Factory.newInstance(new XmlOptions().setDocumentType(_schemaType));
+
+        for (int i = 1; i < _setterMethods.length; i++) {
+            Method setterMethod = _setterMethods[i].getSetter();
+            Object resultValue = null;
+
+            try {
+                resultValue = extractColumnValue(i, _setterMethods[i].getParameterType());
+
+                // if the setter is for an xmlbean enum type, convert the extracted resultset column
+                // value to the proper xmlbean enum type. All xmlbean enums are derived from the class
+                // StringEnumAbstractBase
+                if (_setterMethods[i].getParameterType() == TypeMappingsFactory.TYPE_XMLBEAN_ENUM) {
+                    Class parameterClass = _setterMethods[i].getParameterClass();
+                    Method m = parameterClass.getMethod("forString", new Class[]{String.class});
+                    resultValue = m.invoke(null, new Object[]{resultValue});
+                }
+
+                _args[0] = resultValue;
+                setterMethod.invoke(resultObject, _args);
+
+                if (_setterMethods[i].getNilable() != null) {
+                    if (_resultSet.wasNull()) {
+                        _setterMethods[i].getNilable().invoke(resultObject, (Object[]) null);
+                    }
+                }
+            } catch (SQLException se) {
+                throw new ControlException(se.getMessage(), se);
+            } catch (IllegalArgumentException iae) {
+                try {
+                    ResultSetMetaData md = _resultSet.getMetaData();
+                    throw new ControlException("The declared Java type for method " + setterMethod.getName()
+                                               + setterMethod.getParameterTypes()[0].toString()
+                                               + " is incompatible with the SQL format of column " + md.getColumnName(i).toString()
+                                               + md.getColumnTypeName(i).toString()
+                                               + " which returns objects of type " + resultValue.getClass().getName());
+                } catch (SQLException e) {
+                    throw new ControlException(e.getMessage(), e);
+                }
+            } catch (IllegalAccessException e) {
+                throw new ControlException("IllegalAccessException when trying to access method " + setterMethod.getName(), e);
+            } catch (NoSuchMethodException e) {
+                throw new ControlException("NoSuchMethodException when trying to map schema enum value using Enum.forString().", e);
+            } catch (InvocationTargetException e) {
+                throw new ControlException("IllegalInvocationException when trying to access method " + setterMethod.getName(), e);
+            }
+        }
+        return resultObject;
+    }
+
+
+// ///////////////////////////////////////////////// private methods /////////////////////////////////////////////////
+
+    /**
+     * Build the necessary structures to do the mapping
+     *
+     * @throws SQLException
+     */
+    private void getResultSetMappings() throws SQLException {
+
+        //
+        // special case for XmlObject, find factory class
+        //
+        if (_schemaType.isDocumentType()) {
+            return;
+        }
+
+        final String[] keys = getKeysFromResultSet();
+
+        //
+        // find setters for return class
+        //
+        HashMap<String, Method> mapFields = new HashMap<String, Method>(_columnCount * 2);
+        for (int i = 1; i <= _columnCount; i++) {
+            mapFields.put(keys[i], null);
+        }
+
+        // public methods
+        Method[] classMethods = _returnTypeClass.getMethods();
+        for (Method method : classMethods) {
+
+            if (isSetterMethod(method)) {
+                final String fieldName = method.getName().substring(3).toUpperCase();
+                if (mapFields.containsKey(fieldName)) {
+                    mapFields.put(fieldName, method);
+                }
+            }
+        }
+
+        // finally actually init the fields array
+        _setterMethods = new SetterMethod[_columnCount + 1];
+
+        for (int i = 1; i < _setterMethods.length; i++) {
+            Method setterMethod = mapFields.get(keys[i]);
+            if (setterMethod == null) {
+                throw new ControlException("Unable to map the SQL column " + keys[i]
+                                           + " to a field on the " + _returnTypeClass.getName() +
+                                           " class. Mapping is done using a case insensitive comparision of SQL ResultSet "
+                                           + "columns to public setter methods on the return class.");
+            }
+
+            _setterMethods[i] = new SetterMethod(setterMethod);
+        }
+    }
+
+    /**
+     * Build a String array of column names from the ResultSet.
+     *
+     * @return A String array containing the column names contained within the ResultSet.
+     * @throws SQLException on error
+     */
+    protected String[] getKeysFromResultSet()
+            throws SQLException {
+
+        String[] keys = super.getKeysFromResultSet();
+
+        // check schemaProperty mapping names for more accurate column->field mapping
+        SchemaProperty[] props = _schemaType.getElementProperties();
+        for (int i = 0; i < props.length; i++) {
+
+            int col = -1;
+            try {
+                col = _resultSet.findColumn(props[i].getName().getLocalPart());
+            } catch (SQLException x) {
+            }
+
+            if (col > 0) {
+                keys[col] = props[i].getJavaPropertyName().toUpperCase();
+            }
+        }
+        return keys;
+    }
+
+    /**
+     * Get the SchemaType for the specified class.
+     *
+     * @param returnType Class to get the SchemaType for.
+     * @return SchemaType
+     */
+    private SchemaType getSchemaType(Class returnType) {
+        SchemaType schemaType = null;
+        if (XmlObject.class.isAssignableFrom(returnType)) {
+            try {
+                Field f = returnType.getField("type");
+                if (SchemaType.class.isAssignableFrom(f.getType()) && Modifier.isStatic(f.getModifiers())) {
+                    schemaType = (SchemaType) f.get(null);
+                }
+            } catch (NoSuchFieldException x) {
+            } catch (IllegalAccessException x) {
+            }
+        }
+        return schemaType;
+    }
+
+    // /////////////////////////////////////////////INNER CLASSES/////////////////////////////////////////////////
+
+    /**
+     * Helper class which contains setter method information.
+     */
+    private final class SetterMethod {
+        private final Method _setter;
+        private final int _parameterType;
+        private final Class _parameterClass;
+        private final Method _nilable;
+
+        /**
+         * Create a new setter method.
+         *
+         * @param setter Method instance.
+         */
+        SetterMethod(Method setter) {
+            _setter = setter;
+            _parameterClass = _setter.getParameterTypes()[0];
+            _parameterType = _tmf.getTypeId(_parameterClass);
+            _nilable = isNilable();
+        }
+
+        /**
+         * Return the setter method.
+         *
+         * @return Method
+         */
+        Method getSetter() { return _setter; }
+
+        /**
+         * Return the class of the setter method's paramater.
+         *
+         * @return Class of the setter method's param.
+         */
+        Class getParameterClass() { return _parameterClass; }
+
+        /**
+         * Get the type of the methods paramter.
+         * Type is defined by the TypeMappingsFactory, prefixed by TYPE_.
+         *
+         * @return int type.
+         */
+        int getParameterType() { return _parameterType; }
+
+        /**
+         * Get the nilable method for this setter.
+         *
+         * @return Method.
+         */
+        Method getNilable() { return _nilable; }
+
+        /**
+         * This takes care of the special case for xml beans return types.
+         * since they return primitive types even if they are nillable, we
+         * must explicitly call setNil after getting the column out of the resultSet.
+         * for that, we need to keep track of each field's setNil method.
+         * if the field is not nillable, it will not have a setNil method, and
+         * that array index will be null.
+         *
+         * @return Method
+         */
+        private Method isNilable() {
+            try {
+                return _returnTypeClass.getMethod("setNil" + _setter.getName().substring(3), new Class[]{});
+            } catch (NoSuchMethodException e) {
+                // NOOP - just means there is no setNil
+            }
+            return null;
+        }
+    }
+}

Propchange: incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/RowToXmlObjectMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/TypeMappingsFactory.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/TypeMappingsFactory.java?rev=190657&r1=190656&r2=190657&view=diff
==============================================================================
--- incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/TypeMappingsFactory.java (original)
+++ incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/TypeMappingsFactory.java Tue Jun 14 14:14:42 2005
@@ -1,392 +1,392 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * $Header:$
- */
-
-package org.apache.beehive.controls.system.jdbc;
-
-import org.apache.beehive.controls.api.ControlException;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
-import java.sql.Types;
-import java.sql.Blob;
-import java.sql.Clob;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Currently contains all types of type mappings. Implemented using singleton pattern.
- */
-//@todo: refactor!
-public final class TypeMappingsFactory {
-
-
-    private static TypeMappingsFactory _instance;
-
-    /**
-     * Get an instance of this class.
-     * @return TypeMappingsFactory instance.
-     */
-    public static TypeMappingsFactory getInstance() {
-        if (_instance == null) {
-            _instance = new TypeMappingsFactory();
-        }
-        return _instance;
-    }
-
-    public static final int TYPE_UNKNOWN = 0;
-    static final int TYPE_BYTE = 1;
-    static final int TYPE_SHORT = 2;
-    static final int TYPE_INT = 3;
-    static final int TYPE_LONG = 4;
-    static final int TYPE_FLOAT = 5;
-    static final int TYPE_DOUBLE = 6;
-    static final int TYPE_BOOLEAN = 7;
-    static final int TYPE_BYTE_OBJ = 8;
-    static final int TYPE_SHORT_OBJ = 9;
-    static final int TYPE_INT_OBJ = 10;
-    static final int TYPE_LONG_OBJ = 11;
-    static final int TYPE_FLOAT_OBJ = 12;
-    static final int TYPE_DOUBLE_OBJ = 13;
-    static final int TYPE_BOOLEAN_OBJ = 14;
-    static final int TYPE_BIG_DECIMAL = 15;
-    static final int TYPE_STRING = 16;
-    static final int TYPE_BYTES = 17;
-    static final int TYPE_SQLDATE = 18;
-    static final int TYPE_TIME = 19;
-    static final int TYPE_TIMESTAMP = 20;
-    static final int TYPE_STREAM = 21;
-    static final int TYPE_READER = 22;
-    static final int TYPE_CLOB = 23;
-    static final int TYPE_BLOB = 24;
-    static final int TYPE_ARRAY = 25;
-    static final int TYPE_REF = 26;
-    static final int TYPE_DATE = 27;
-    static final int TYPE_CALENDAR = 28;
-    static final int TYPE_STRUCT = 29;
-    static final int TYPE_XMLBEAN_ENUM = 30;
-    static final int TYPE_MAX = 31;
-
-    private Map<Class, Object> _primitiveDefaults;
-
-    //
-    // keys in this map are the class of the method's return type,
-    // values are the set of constants defined above all prefixed with
-    // TYPE_
-    //
-    private Map<Class, Integer> _typeMap;
-    private Map<Class, Integer> _typeSqlMap;
-
-    /**
-     * Map a string version of sql type to sql type (java.sql.Types).
-     * example: "INTEGER" maps to java.sql.Types.INTEGER
-     */
-    private Map<String, Integer> _typeSqlNameMap;
-
-    private static Method _methodMapGet;
-
-    /**
-     * Constructor
-     */
-    TypeMappingsFactory() {
-
-        _primitiveDefaults = new HashMap<Class, Object>();
-        _primitiveDefaults.put(Boolean.TYPE, Boolean.FALSE);
-        _primitiveDefaults.put(Integer.TYPE, new Integer(0));
-        _primitiveDefaults.put(Long.TYPE, new Long(0));
-        _primitiveDefaults.put(Byte.TYPE, new Byte((byte) 0));
-        _primitiveDefaults.put(Short.TYPE, new Short((short) 0));
-        _primitiveDefaults.put(Character.TYPE, new Character('\u0000'));
-        _primitiveDefaults.put(Float.TYPE, new Float(0.0f));
-        _primitiveDefaults.put(Double.TYPE, new Double(0.0d));
-
-        // Class to internal enum
-        _typeMap = new HashMap<Class, Integer>(TYPE_MAX * 2);
-        _typeMap.put(Boolean.TYPE, new Integer(TYPE_BOOLEAN));
-        _typeMap.put(Integer.TYPE, new Integer(TYPE_INT));
-        _typeMap.put(Long.TYPE, new Integer(TYPE_LONG));
-        _typeMap.put(Byte.TYPE, new Integer(TYPE_BYTE));
-        _typeMap.put(Short.TYPE, new Integer(TYPE_SHORT));
-        _typeMap.put(Float.TYPE, new Integer(TYPE_FLOAT));
-        _typeMap.put(Double.TYPE, new Integer(TYPE_DOUBLE));
-        _typeMap.put(Boolean.class, new Integer(TYPE_BOOLEAN_OBJ));
-        _typeMap.put(Integer.class, new Integer(TYPE_INT_OBJ));
-        _typeMap.put(Long.class, new Integer(TYPE_LONG_OBJ));
-        _typeMap.put(Byte.class, new Integer(TYPE_BYTE_OBJ));
-        _typeMap.put(Short.class, new Integer(TYPE_SHORT_OBJ));
-        _typeMap.put(Float.class, new Integer(TYPE_FLOAT_OBJ));
-        _typeMap.put(Double.class, new Integer(TYPE_DOUBLE_OBJ));
-        _typeMap.put(String.class, new Integer(TYPE_STRING));
-        _typeMap.put(java.math.BigDecimal.class, new Integer(TYPE_BIG_DECIMAL));
-        _typeMap.put(byte[].class, new Integer(TYPE_BYTES));
-        _typeMap.put(java.sql.Timestamp.class, new Integer(TYPE_TIMESTAMP));
-        _typeMap.put(java.sql.Time.class, new Integer(TYPE_TIME));
-        _typeMap.put(java.sql.Date.class, new Integer(TYPE_SQLDATE));
-        _typeMap.put(java.sql.Ref.class, new Integer(TYPE_REF));
-        _typeMap.put(java.sql.Blob.class, new Integer(TYPE_BLOB));
-        _typeMap.put(java.sql.Clob.class, new Integer(TYPE_CLOB));
-        _typeMap.put(java.sql.Array.class, new Integer(TYPE_ARRAY));
-        _typeMap.put(java.sql.Struct.class, new Integer(TYPE_STRUCT));
-        _typeMap.put(java.io.Reader.class, new Integer(TYPE_READER));
-        _typeMap.put(java.io.InputStream.class, new Integer(TYPE_STREAM));
-        _typeMap.put(java.util.Date.class, new Integer(TYPE_DATE));
-        _typeMap.put(java.util.Calendar.class, new Integer(TYPE_CALENDAR));
-        _typeMap.put(java.util.GregorianCalendar.class, new Integer(TYPE_CALENDAR));
-        _typeMap.put(org.apache.xmlbeans.StringEnumAbstractBase.class, new Integer(TYPE_XMLBEAN_ENUM));
-
-        // Class to java.sql.Types
-        _typeSqlMap = new HashMap<Class, Integer>(TYPE_MAX * 2);
-        _typeSqlMap.put(Boolean.TYPE, new Integer(Types.BOOLEAN));
-        _typeSqlMap.put(Integer.TYPE, new Integer(Types.INTEGER));
-        _typeSqlMap.put(Long.TYPE, new Integer(Types.BIGINT));
-        _typeSqlMap.put(Byte.TYPE, new Integer(Types.TINYINT));
-        _typeSqlMap.put(Short.TYPE, new Integer(Types.SMALLINT));
-        _typeSqlMap.put(Float.TYPE, new Integer(Types.REAL));
-        _typeSqlMap.put(Double.TYPE, new Integer(Types.DOUBLE));
-        _typeSqlMap.put(Boolean.class, new Integer(Types.BOOLEAN));
-        _typeSqlMap.put(Integer.class, new Integer(Types.INTEGER));
-        _typeSqlMap.put(Long.class, new Integer(Types.BIGINT));
-        _typeSqlMap.put(Byte.class, new Integer(Types.TINYINT));
-        _typeSqlMap.put(Short.class, new Integer(Types.SMALLINT));
-        _typeSqlMap.put(Float.class, new Integer(Types.REAL));
-        _typeSqlMap.put(Double.class, new Integer(Types.DOUBLE));
-        _typeSqlMap.put(String.class, new Integer(Types.VARCHAR));
-        _typeSqlMap.put(java.math.BigDecimal.class, new Integer(Types.DECIMAL));
-        _typeSqlMap.put(byte[].class, new Integer(Types.VARBINARY));
-        _typeSqlMap.put(java.sql.Timestamp.class, new Integer(Types.TIMESTAMP));
-        _typeSqlMap.put(java.sql.Time.class, new Integer(Types.TIME));
-        _typeSqlMap.put(java.sql.Date.class, new Integer(Types.DATE));
-        _typeSqlMap.put(java.sql.Ref.class, new Integer(Types.REF));
-        _typeSqlMap.put(java.sql.Blob.class, new Integer(Types.BLOB));
-        _typeSqlMap.put(java.sql.Clob.class, new Integer(Types.CLOB));
-        _typeSqlMap.put(java.sql.Array.class, new Integer(Types.ARRAY));
-        _typeSqlMap.put(java.sql.Struct.class, new Integer(Types.STRUCT));
-        _typeSqlMap.put(java.util.Date.class, new Integer(Types.TIMESTAMP));
-        _typeSqlMap.put(java.util.Calendar.class, new Integer(Types.TIMESTAMP));
-        _typeSqlMap.put(java.util.GregorianCalendar.class, new Integer(Types.TIMESTAMP));
-        _typeSqlMap.put(org.apache.xmlbeans.StringEnumAbstractBase.class, new Integer(Types.VARCHAR));
-
-        // String to java.sql.Types
-        _typeSqlNameMap = new HashMap<String, Integer>(TYPE_MAX * 2);
-        _typeSqlNameMap.put("BIT", new Integer(Types.BIT));
-        _typeSqlNameMap.put("TINYINT", new Integer(Types.TINYINT));
-        _typeSqlNameMap.put("SMALLINT", new Integer(Types.SMALLINT));
-        _typeSqlNameMap.put("INTEGER", new Integer(Types.INTEGER));
-        _typeSqlNameMap.put("BIGINT", new Integer(Types.BIGINT));
-        _typeSqlNameMap.put("FLOAT", new Integer(Types.REAL));
-        _typeSqlNameMap.put("REAL", new Integer(Types.REAL));
-        _typeSqlNameMap.put("DOUBLE", new Integer(Types.DOUBLE));
-        _typeSqlNameMap.put("NUMERIC", new Integer(Types.NUMERIC));
-        _typeSqlNameMap.put("DECIMAL", new Integer(Types.DECIMAL));
-        _typeSqlNameMap.put("CHAR", new Integer(Types.CHAR));
-        _typeSqlNameMap.put("VARCHAR", new Integer(Types.VARCHAR));
-        _typeSqlNameMap.put("LONGVARCHAR", new Integer(Types.LONGVARCHAR));
-        _typeSqlNameMap.put("DATE", new Integer(Types.DATE));
-        _typeSqlNameMap.put("TIME", new Integer(Types.TIME));
-        _typeSqlNameMap.put("TIMESTAMP", new Integer(Types.TIMESTAMP));
-        _typeSqlNameMap.put("BINARY", new Integer(Types.BINARY));
-        _typeSqlNameMap.put("VARBINARY", new Integer(Types.VARBINARY));
-        _typeSqlNameMap.put("LONGVARBINARY", new Integer(Types.LONGVARBINARY));
-        _typeSqlNameMap.put("NULL", new Integer(Types.NULL));
-        _typeSqlNameMap.put("OTHER", new Integer(Types.OTHER));
-        _typeSqlNameMap.put("JAVA_OBJECT", new Integer(Types.JAVA_OBJECT));
-        _typeSqlNameMap.put("DISTINCT", new Integer(Types.DISTINCT));
-        _typeSqlNameMap.put("STRUCT", new Integer(Types.STRUCT));
-        _typeSqlNameMap.put("ARRAY", new Integer(Types.ARRAY));
-        _typeSqlNameMap.put("BLOB", new Integer(Types.BLOB));
-        _typeSqlNameMap.put("CLOB", new Integer(Types.CLOB));
-        _typeSqlNameMap.put("REF", new Integer(Types.REF));
-        _typeSqlNameMap.put("DATALINK", new Integer(Types.DATALINK));
-        _typeSqlNameMap.put("BOOLEAN", new Integer(Types.BOOLEAN));
-
-        // some JAVA synonyms
-        _typeSqlNameMap.put("BYTE", new Integer(Types.TINYINT));
-        _typeSqlNameMap.put("SHORT", new Integer(Types.SMALLINT));
-        _typeSqlNameMap.put("INT", new Integer(Types.INTEGER));
-        _typeSqlNameMap.put("LONG", new Integer(Types.BIGINT));
-
-        // cache the Map.get method for efficiency
-        try {
-            _methodMapGet = java.util.Map.class.getMethod("get", new Class[]{Object.class});
-        } catch (NoSuchMethodException e) {
-            throw new ControlException("Can not find java.util.Map.get(Object) method");
-        }
-    }
-
-    /**
-     * Convert a type string to its SQL Type int value.
-     * @param type A String containing the SQL type name.
-     * @return The SQL type, TYPE_UNKNOWN if cannot convert.
-     */
-    public int convertStringToSQLType(String type) {
-        if (_typeSqlNameMap.containsKey(type.toUpperCase())) {
-            return _typeSqlNameMap.get(type.toUpperCase());
-        }
-        return TYPE_UNKNOWN;
-    }
-
-    /**
-     * Get the SQL type of a class, start at top level class an check all super classes until match is found.
-     * @param classType Class to get SQL type of.
-     * @return Types.OTHER if cannot find SQL type.
-     */
-    public int getSqlType(Class classType) {
-
-        final Class origType = classType;
-        while (classType != null) {
-            Integer type = _typeSqlMap.get(classType);
-            if (type != null) {
-                return type.intValue();
-            }
-            classType = classType.getSuperclass();
-        }
-
-        //
-        // special check for blobs/clobs they are interfaces not derived from
-        //
-        if (Blob.class.isAssignableFrom(origType)) {
-            return _typeSqlMap.get(Blob.class).intValue();
-        } else if (Clob.class.isAssignableFrom(origType)) {
-            return _typeSqlMap.get(Clob.class).intValue();
-        }
-
-        return Types.OTHER;
-    }
-
-    /**
-     * Get the SQL type for an object.
-     * @param o Object to get SQL type of.
-     * @return SQL type of the object, Types.OTHER if cannot classify.
-     */
-    public int getSqlType(Object o) {
-        if (null == o) {
-            return Types.NULL;
-        }
-        return getSqlType(o.getClass());
-    }
-
-    /**
-     *
-     * @param val
-     * @param args
-     * @return
-     * @throws IllegalAccessException
-     * @throws InvocationTargetException
-     */
-    public Object lookupType(Object val, Object[] args)
-            throws IllegalAccessException, InvocationTargetException
-    {
-        return _methodMapGet.invoke(val, args);
-    }
-
-    /**
-     * Get the type id (defined by this class) for the given class.
-     * @param classType Class to get type of.
-     * @return Type id of class.
-     */
-    public int getTypeId(Class classType) {
-
-        final Class origType = classType;
-        while (null != classType) {
-            Integer typeObj = (Integer) _typeMap.get(classType);
-            if (null != typeObj) {
-                return typeObj.intValue();
-            }
-            classType = classType.getSuperclass();
-        }
-
-        //
-        // special check for blobs/clobs they are interfaces not derived from
-        //
-        if (Blob.class.isAssignableFrom(origType)) {
-            return _typeMap.get(Blob.class).intValue();
-        } else if (Clob.class.isAssignableFrom(origType)) {
-            return _typeMap.get(Clob.class).intValue();
-        }
-
-        return TYPE_UNKNOWN;
-    }
-
-   /**
-    * Returns a primitive legal value as opposed to null if type is primitive.
-    * @param type type to get null value for.
-    * @return null value for specifed type.
-    */
-   public Object fixNull(Class type) {
-       return type.isPrimitive() ? _primitiveDefaults.get(type) : null;
-   }
-
-   /**
-     * Create an Object array for the given array.
-     *
-     * @param o An array.
-     * @return A new object array.
-     */
-    public static Object[] toObjectArray(Object o) {
-
-        Class clas = o.getClass().getComponentType();
-
-        if (null == clas) return null;
-
-        Object[] arr;
-
-        if (clas == Boolean.TYPE) {
-            boolean[] src = (boolean[]) o;
-            arr = new Object[src.length];
-            for (int i = 0; i < src.length; i++)
-                arr[i] = new Boolean(src[i]);
-        } else if (clas == Character.TYPE) {
-            char[] src = (char[]) o;
-            arr = new Object[src.length];
-            for (int i = 0; i < src.length; i++)
-                arr[i] = new Character(src[i]);
-        } else if (clas == Byte.TYPE) {
-            byte[] src = (byte[]) o;
-            arr = new Object[src.length];
-            for (int i = 0; i < src.length; i++)
-                arr[i] = new Byte(src[i]);
-        } else if (clas == Short.TYPE) {
-            short[] src = (short[]) o;
-            arr = new Object[src.length];
-            for (int i = 0; i < src.length; i++)
-                arr[i] = new Short(src[i]);
-        } else if (clas == Integer.TYPE) {
-            int[] src = (int[]) o;
-            arr = new Object[src.length];
-            for (int i = 0; i < src.length; i++)
-                arr[i] = new Integer(src[i]);
-        } else if (clas == Long.TYPE) {
-            long[] src = (long[]) o;
-            arr = new Object[src.length];
-            for (int i = 0; i < src.length; i++)
-                arr[i] = new Long(src[i]);
-        } else if (clas == Float.TYPE) {
-            float[] src = (float[]) o;
-            arr = new Object[src.length];
-            for (int i = 0; i < src.length; i++)
-                arr[i] = new Float(src[i]);
-        } else if (clas == Double.TYPE) {
-            double[] src = (double[]) o;
-            arr = new Object[src.length];
-            for (int i = 0; i < src.length; i++)
-                arr[i] = new Double(src[i]);
-        } else {
-            arr = (Object[]) o;
-        }
-        return arr;
-    }
-}
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc;
+
+import org.apache.beehive.controls.api.ControlException;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+import java.sql.Types;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Currently contains all types of type mappings. Implemented using singleton pattern.
+ */
+//@todo: refactor!
+public final class TypeMappingsFactory {
+
+
+    private static TypeMappingsFactory _instance;
+
+    /**
+     * Get an instance of this class.
+     * @return TypeMappingsFactory instance.
+     */
+    public static TypeMappingsFactory getInstance() {
+        if (_instance == null) {
+            _instance = new TypeMappingsFactory();
+        }
+        return _instance;
+    }
+
+    public static final int TYPE_UNKNOWN = 0;
+    static final int TYPE_BYTE = 1;
+    static final int TYPE_SHORT = 2;
+    static final int TYPE_INT = 3;
+    static final int TYPE_LONG = 4;
+    static final int TYPE_FLOAT = 5;
+    static final int TYPE_DOUBLE = 6;
+    static final int TYPE_BOOLEAN = 7;
+    static final int TYPE_BYTE_OBJ = 8;
+    static final int TYPE_SHORT_OBJ = 9;
+    static final int TYPE_INT_OBJ = 10;
+    static final int TYPE_LONG_OBJ = 11;
+    static final int TYPE_FLOAT_OBJ = 12;
+    static final int TYPE_DOUBLE_OBJ = 13;
+    static final int TYPE_BOOLEAN_OBJ = 14;
+    static final int TYPE_BIG_DECIMAL = 15;
+    static final int TYPE_STRING = 16;
+    static final int TYPE_BYTES = 17;
+    static final int TYPE_SQLDATE = 18;
+    static final int TYPE_TIME = 19;
+    static final int TYPE_TIMESTAMP = 20;
+    static final int TYPE_STREAM = 21;
+    static final int TYPE_READER = 22;
+    static final int TYPE_CLOB = 23;
+    static final int TYPE_BLOB = 24;
+    static final int TYPE_ARRAY = 25;
+    static final int TYPE_REF = 26;
+    static final int TYPE_DATE = 27;
+    static final int TYPE_CALENDAR = 28;
+    static final int TYPE_STRUCT = 29;
+    static final int TYPE_XMLBEAN_ENUM = 30;
+    static final int TYPE_MAX = 31;
+
+    private Map<Class, Object> _primitiveDefaults;
+
+    //
+    // keys in this map are the class of the method's return type,
+    // values are the set of constants defined above all prefixed with
+    // TYPE_
+    //
+    private Map<Class, Integer> _typeMap;
+    private Map<Class, Integer> _typeSqlMap;
+
+    /**
+     * Map a string version of sql type to sql type (java.sql.Types).
+     * example: "INTEGER" maps to java.sql.Types.INTEGER
+     */
+    private Map<String, Integer> _typeSqlNameMap;
+
+    private static Method _methodMapGet;
+
+    /**
+     * Constructor
+     */
+    TypeMappingsFactory() {
+
+        _primitiveDefaults = new HashMap<Class, Object>();
+        _primitiveDefaults.put(Boolean.TYPE, Boolean.FALSE);
+        _primitiveDefaults.put(Integer.TYPE, new Integer(0));
+        _primitiveDefaults.put(Long.TYPE, new Long(0));
+        _primitiveDefaults.put(Byte.TYPE, new Byte((byte) 0));
+        _primitiveDefaults.put(Short.TYPE, new Short((short) 0));
+        _primitiveDefaults.put(Character.TYPE, new Character('\u0000'));
+        _primitiveDefaults.put(Float.TYPE, new Float(0.0f));
+        _primitiveDefaults.put(Double.TYPE, new Double(0.0d));
+
+        // Class to internal enum
+        _typeMap = new HashMap<Class, Integer>(TYPE_MAX * 2);
+        _typeMap.put(Boolean.TYPE, new Integer(TYPE_BOOLEAN));
+        _typeMap.put(Integer.TYPE, new Integer(TYPE_INT));
+        _typeMap.put(Long.TYPE, new Integer(TYPE_LONG));
+        _typeMap.put(Byte.TYPE, new Integer(TYPE_BYTE));
+        _typeMap.put(Short.TYPE, new Integer(TYPE_SHORT));
+        _typeMap.put(Float.TYPE, new Integer(TYPE_FLOAT));
+        _typeMap.put(Double.TYPE, new Integer(TYPE_DOUBLE));
+        _typeMap.put(Boolean.class, new Integer(TYPE_BOOLEAN_OBJ));
+        _typeMap.put(Integer.class, new Integer(TYPE_INT_OBJ));
+        _typeMap.put(Long.class, new Integer(TYPE_LONG_OBJ));
+        _typeMap.put(Byte.class, new Integer(TYPE_BYTE_OBJ));
+        _typeMap.put(Short.class, new Integer(TYPE_SHORT_OBJ));
+        _typeMap.put(Float.class, new Integer(TYPE_FLOAT_OBJ));
+        _typeMap.put(Double.class, new Integer(TYPE_DOUBLE_OBJ));
+        _typeMap.put(String.class, new Integer(TYPE_STRING));
+        _typeMap.put(java.math.BigDecimal.class, new Integer(TYPE_BIG_DECIMAL));
+        _typeMap.put(byte[].class, new Integer(TYPE_BYTES));
+        _typeMap.put(java.sql.Timestamp.class, new Integer(TYPE_TIMESTAMP));
+        _typeMap.put(java.sql.Time.class, new Integer(TYPE_TIME));
+        _typeMap.put(java.sql.Date.class, new Integer(TYPE_SQLDATE));
+        _typeMap.put(java.sql.Ref.class, new Integer(TYPE_REF));
+        _typeMap.put(java.sql.Blob.class, new Integer(TYPE_BLOB));
+        _typeMap.put(java.sql.Clob.class, new Integer(TYPE_CLOB));
+        _typeMap.put(java.sql.Array.class, new Integer(TYPE_ARRAY));
+        _typeMap.put(java.sql.Struct.class, new Integer(TYPE_STRUCT));
+        _typeMap.put(java.io.Reader.class, new Integer(TYPE_READER));
+        _typeMap.put(java.io.InputStream.class, new Integer(TYPE_STREAM));
+        _typeMap.put(java.util.Date.class, new Integer(TYPE_DATE));
+        _typeMap.put(java.util.Calendar.class, new Integer(TYPE_CALENDAR));
+        _typeMap.put(java.util.GregorianCalendar.class, new Integer(TYPE_CALENDAR));
+        _typeMap.put(org.apache.xmlbeans.StringEnumAbstractBase.class, new Integer(TYPE_XMLBEAN_ENUM));
+
+        // Class to java.sql.Types
+        _typeSqlMap = new HashMap<Class, Integer>(TYPE_MAX * 2);
+        _typeSqlMap.put(Boolean.TYPE, new Integer(Types.BOOLEAN));
+        _typeSqlMap.put(Integer.TYPE, new Integer(Types.INTEGER));
+        _typeSqlMap.put(Long.TYPE, new Integer(Types.BIGINT));
+        _typeSqlMap.put(Byte.TYPE, new Integer(Types.TINYINT));
+        _typeSqlMap.put(Short.TYPE, new Integer(Types.SMALLINT));
+        _typeSqlMap.put(Float.TYPE, new Integer(Types.REAL));
+        _typeSqlMap.put(Double.TYPE, new Integer(Types.DOUBLE));
+        _typeSqlMap.put(Boolean.class, new Integer(Types.BOOLEAN));
+        _typeSqlMap.put(Integer.class, new Integer(Types.INTEGER));
+        _typeSqlMap.put(Long.class, new Integer(Types.BIGINT));
+        _typeSqlMap.put(Byte.class, new Integer(Types.TINYINT));
+        _typeSqlMap.put(Short.class, new Integer(Types.SMALLINT));
+        _typeSqlMap.put(Float.class, new Integer(Types.REAL));
+        _typeSqlMap.put(Double.class, new Integer(Types.DOUBLE));
+        _typeSqlMap.put(String.class, new Integer(Types.VARCHAR));
+        _typeSqlMap.put(java.math.BigDecimal.class, new Integer(Types.DECIMAL));
+        _typeSqlMap.put(byte[].class, new Integer(Types.VARBINARY));
+        _typeSqlMap.put(java.sql.Timestamp.class, new Integer(Types.TIMESTAMP));
+        _typeSqlMap.put(java.sql.Time.class, new Integer(Types.TIME));
+        _typeSqlMap.put(java.sql.Date.class, new Integer(Types.DATE));
+        _typeSqlMap.put(java.sql.Ref.class, new Integer(Types.REF));
+        _typeSqlMap.put(java.sql.Blob.class, new Integer(Types.BLOB));
+        _typeSqlMap.put(java.sql.Clob.class, new Integer(Types.CLOB));
+        _typeSqlMap.put(java.sql.Array.class, new Integer(Types.ARRAY));
+        _typeSqlMap.put(java.sql.Struct.class, new Integer(Types.STRUCT));
+        _typeSqlMap.put(java.util.Date.class, new Integer(Types.TIMESTAMP));
+        _typeSqlMap.put(java.util.Calendar.class, new Integer(Types.TIMESTAMP));
+        _typeSqlMap.put(java.util.GregorianCalendar.class, new Integer(Types.TIMESTAMP));
+        _typeSqlMap.put(org.apache.xmlbeans.StringEnumAbstractBase.class, new Integer(Types.VARCHAR));
+
+        // String to java.sql.Types
+        _typeSqlNameMap = new HashMap<String, Integer>(TYPE_MAX * 2);
+        _typeSqlNameMap.put("BIT", new Integer(Types.BIT));
+        _typeSqlNameMap.put("TINYINT", new Integer(Types.TINYINT));
+        _typeSqlNameMap.put("SMALLINT", new Integer(Types.SMALLINT));
+        _typeSqlNameMap.put("INTEGER", new Integer(Types.INTEGER));
+        _typeSqlNameMap.put("BIGINT", new Integer(Types.BIGINT));
+        _typeSqlNameMap.put("FLOAT", new Integer(Types.REAL));
+        _typeSqlNameMap.put("REAL", new Integer(Types.REAL));
+        _typeSqlNameMap.put("DOUBLE", new Integer(Types.DOUBLE));
+        _typeSqlNameMap.put("NUMERIC", new Integer(Types.NUMERIC));
+        _typeSqlNameMap.put("DECIMAL", new Integer(Types.DECIMAL));
+        _typeSqlNameMap.put("CHAR", new Integer(Types.CHAR));
+        _typeSqlNameMap.put("VARCHAR", new Integer(Types.VARCHAR));
+        _typeSqlNameMap.put("LONGVARCHAR", new Integer(Types.LONGVARCHAR));
+        _typeSqlNameMap.put("DATE", new Integer(Types.DATE));
+        _typeSqlNameMap.put("TIME", new Integer(Types.TIME));
+        _typeSqlNameMap.put("TIMESTAMP", new Integer(Types.TIMESTAMP));
+        _typeSqlNameMap.put("BINARY", new Integer(Types.BINARY));
+        _typeSqlNameMap.put("VARBINARY", new Integer(Types.VARBINARY));
+        _typeSqlNameMap.put("LONGVARBINARY", new Integer(Types.LONGVARBINARY));
+        _typeSqlNameMap.put("NULL", new Integer(Types.NULL));
+        _typeSqlNameMap.put("OTHER", new Integer(Types.OTHER));
+        _typeSqlNameMap.put("JAVA_OBJECT", new Integer(Types.JAVA_OBJECT));
+        _typeSqlNameMap.put("DISTINCT", new Integer(Types.DISTINCT));
+        _typeSqlNameMap.put("STRUCT", new Integer(Types.STRUCT));
+        _typeSqlNameMap.put("ARRAY", new Integer(Types.ARRAY));
+        _typeSqlNameMap.put("BLOB", new Integer(Types.BLOB));
+        _typeSqlNameMap.put("CLOB", new Integer(Types.CLOB));
+        _typeSqlNameMap.put("REF", new Integer(Types.REF));
+        _typeSqlNameMap.put("DATALINK", new Integer(Types.DATALINK));
+        _typeSqlNameMap.put("BOOLEAN", new Integer(Types.BOOLEAN));
+
+        // some JAVA synonyms
+        _typeSqlNameMap.put("BYTE", new Integer(Types.TINYINT));
+        _typeSqlNameMap.put("SHORT", new Integer(Types.SMALLINT));
+        _typeSqlNameMap.put("INT", new Integer(Types.INTEGER));
+        _typeSqlNameMap.put("LONG", new Integer(Types.BIGINT));
+
+        // cache the Map.get method for efficiency
+        try {
+            _methodMapGet = java.util.Map.class.getMethod("get", new Class[]{Object.class});
+        } catch (NoSuchMethodException e) {
+            throw new ControlException("Can not find java.util.Map.get(Object) method");
+        }
+    }
+
+    /**
+     * Convert a type string to its SQL Type int value.
+     * @param type A String containing the SQL type name.
+     * @return The SQL type, TYPE_UNKNOWN if cannot convert.
+     */
+    public int convertStringToSQLType(String type) {
+        if (_typeSqlNameMap.containsKey(type.toUpperCase())) {
+            return _typeSqlNameMap.get(type.toUpperCase());
+        }
+        return TYPE_UNKNOWN;
+    }
+
+    /**
+     * Get the SQL type of a class, start at top level class an check all super classes until match is found.
+     * @param classType Class to get SQL type of.
+     * @return Types.OTHER if cannot find SQL type.
+     */
+    public int getSqlType(Class classType) {
+
+        final Class origType = classType;
+        while (classType != null) {
+            Integer type = _typeSqlMap.get(classType);
+            if (type != null) {
+                return type.intValue();
+            }
+            classType = classType.getSuperclass();
+        }
+
+        //
+        // special check for blobs/clobs they are interfaces not derived from
+        //
+        if (Blob.class.isAssignableFrom(origType)) {
+            return _typeSqlMap.get(Blob.class).intValue();
+        } else if (Clob.class.isAssignableFrom(origType)) {
+            return _typeSqlMap.get(Clob.class).intValue();
+        }
+
+        return Types.OTHER;
+    }
+
+    /**
+     * Get the SQL type for an object.
+     * @param o Object to get SQL type of.
+     * @return SQL type of the object, Types.OTHER if cannot classify.
+     */
+    public int getSqlType(Object o) {
+        if (null == o) {
+            return Types.NULL;
+        }
+        return getSqlType(o.getClass());
+    }
+
+    /**
+     *
+     * @param val
+     * @param args
+     * @return
+     * @throws IllegalAccessException
+     * @throws InvocationTargetException
+     */
+    public Object lookupType(Object val, Object[] args)
+            throws IllegalAccessException, InvocationTargetException
+    {
+        return _methodMapGet.invoke(val, args);
+    }
+
+    /**
+     * Get the type id (defined by this class) for the given class.
+     * @param classType Class to get type of.
+     * @return Type id of class.
+     */
+    public int getTypeId(Class classType) {
+
+        final Class origType = classType;
+        while (null != classType) {
+            Integer typeObj = (Integer) _typeMap.get(classType);
+            if (null != typeObj) {
+                return typeObj.intValue();
+            }
+            classType = classType.getSuperclass();
+        }
+
+        //
+        // special check for blobs/clobs they are interfaces not derived from
+        //
+        if (Blob.class.isAssignableFrom(origType)) {
+            return _typeMap.get(Blob.class).intValue();
+        } else if (Clob.class.isAssignableFrom(origType)) {
+            return _typeMap.get(Clob.class).intValue();
+        }
+
+        return TYPE_UNKNOWN;
+    }
+
+   /**
+    * Returns a primitive legal value as opposed to null if type is primitive.
+    * @param type type to get null value for.
+    * @return null value for specifed type.
+    */
+   public Object fixNull(Class type) {
+       return type.isPrimitive() ? _primitiveDefaults.get(type) : null;
+   }
+
+   /**
+     * Create an Object array for the given array.
+     *
+     * @param o An array.
+     * @return A new object array.
+     */
+    public static Object[] toObjectArray(Object o) {
+
+        Class clas = o.getClass().getComponentType();
+
+        if (null == clas) return null;
+
+        Object[] arr;
+
+        if (clas == Boolean.TYPE) {
+            boolean[] src = (boolean[]) o;
+            arr = new Object[src.length];
+            for (int i = 0; i < src.length; i++)
+                arr[i] = new Boolean(src[i]);
+        } else if (clas == Character.TYPE) {
+            char[] src = (char[]) o;
+            arr = new Object[src.length];
+            for (int i = 0; i < src.length; i++)
+                arr[i] = new Character(src[i]);
+        } else if (clas == Byte.TYPE) {
+            byte[] src = (byte[]) o;
+            arr = new Object[src.length];
+            for (int i = 0; i < src.length; i++)
+                arr[i] = new Byte(src[i]);
+        } else if (clas == Short.TYPE) {
+            short[] src = (short[]) o;
+            arr = new Object[src.length];
+            for (int i = 0; i < src.length; i++)
+                arr[i] = new Short(src[i]);
+        } else if (clas == Integer.TYPE) {
+            int[] src = (int[]) o;
+            arr = new Object[src.length];
+            for (int i = 0; i < src.length; i++)
+                arr[i] = new Integer(src[i]);
+        } else if (clas == Long.TYPE) {
+            long[] src = (long[]) o;
+            arr = new Object[src.length];
+            for (int i = 0; i < src.length; i++)
+                arr[i] = new Long(src[i]);
+        } else if (clas == Float.TYPE) {
+            float[] src = (float[]) o;
+            arr = new Object[src.length];
+            for (int i = 0; i < src.length; i++)
+                arr[i] = new Float(src[i]);
+        } else if (clas == Double.TYPE) {
+            double[] src = (double[]) o;
+            arr = new Object[src.length];
+            for (int i = 0; i < src.length; i++)
+                arr[i] = new Double(src[i]);
+        } else {
+            arr = (Object[]) o;
+        }
+        return arr;
+    }
+}

Propchange: incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/TypeMappingsFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/JdbcFragment.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/JdbcFragment.java?rev=190657&r1=190656&r2=190657&view=diff
==============================================================================
--- incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/JdbcFragment.java (original)
+++ incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/JdbcFragment.java Tue Jun 14 14:14:42 2005
@@ -1,73 +1,73 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * $Header:$
- */
-
-package org.apache.beehive.controls.system.jdbc.parser;
-
-import org.apache.beehive.controls.api.context.ControlBeanContext;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-
-/**
- * Represents an SQL escape sequence found in the SQL annotation's statement member. A JdbcFragment may
- * contain child SqlFragments, typically these fragments consist of LiteralFragments and ReflectionFragments.
- * Parameter substitutions may occur within the SQL escape delimiters {}.
- *
- * Syntactically an SQL escape sequence must match one of the following forms, where <i>_space_</i> is a whitespace character:
- *
- * <UL><LI>{call_space_.....}</LI>
- * <LI>{?=_space_.....}</LI>
- * <LI>{d_space_.....}</LI>
- * <LI>{t_space_.....}</LI>
- * <LI>{ts_space_.....}</LI>
- * <LI>{fn_space_.....}</LI>
- * <LI>{escape_space_.....}</LI>
- * <LI>{oj_space_.....}</LI>
- */
-public final class JdbcFragment extends SqlFragmentContainer {
-
-    /**
-     * Create a new JdbcFragment
-     */
-    JdbcFragment() {
-        super();
-    }
-
-    /**
-     * Get the prepared statement parameter value(s) contained within this fragment.
-     *
-     * @param context A ControlBeanContext instance.
-     * @param method The annotated method.
-     * @param args The method's arguments.
-     *
-     * @return null if this fragment doesn't contain a parameter value.
-     */
-    Object[] getParameterValues(ControlBeanContext context, Method method, Object[] args) {
-
-        ArrayList<Object> values = new ArrayList<Object>();
-        for (SqlFragment sf : _children) {
-            if (sf.hasParamValue()) {
-                Object[] moreValues = sf.getParameterValues(context, method, args);
-                for (Object o : moreValues) {
-                    values.add(o);
-                }
-            }
-        }
-        return values.toArray();
-    }
-}
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc.parser;
+
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+
+/**
+ * Represents an SQL escape sequence found in the SQL annotation's statement member. A JdbcFragment may
+ * contain child SqlFragments, typically these fragments consist of LiteralFragments and ReflectionFragments.
+ * Parameter substitutions may occur within the SQL escape delimiters {}.
+ *
+ * Syntactically an SQL escape sequence must match one of the following forms, where <i>_space_</i> is a whitespace character:
+ *
+ * <UL><LI>{call_space_.....}</LI>
+ * <LI>{?=_space_.....}</LI>
+ * <LI>{d_space_.....}</LI>
+ * <LI>{t_space_.....}</LI>
+ * <LI>{ts_space_.....}</LI>
+ * <LI>{fn_space_.....}</LI>
+ * <LI>{escape_space_.....}</LI>
+ * <LI>{oj_space_.....}</LI>
+ */
+public final class JdbcFragment extends SqlFragmentContainer {
+
+    /**
+     * Create a new JdbcFragment
+     */
+    JdbcFragment() {
+        super();
+    }
+
+    /**
+     * Get the prepared statement parameter value(s) contained within this fragment.
+     *
+     * @param context A ControlBeanContext instance.
+     * @param method The annotated method.
+     * @param args The method's arguments.
+     *
+     * @return null if this fragment doesn't contain a parameter value.
+     */
+    Object[] getParameterValues(ControlBeanContext context, Method method, Object[] args) {
+
+        ArrayList<Object> values = new ArrayList<Object>();
+        for (SqlFragment sf : _children) {
+            if (sf.hasParamValue()) {
+                Object[] moreValues = sf.getParameterValues(context, method, args);
+                for (Object o : moreValues) {
+                    values.add(o);
+                }
+            }
+        }
+        return values.toArray();
+    }
+}

Propchange: incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/JdbcFragment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/LiteralFragment.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/LiteralFragment.java?rev=190657&r1=190656&r2=190657&view=diff
==============================================================================
--- incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/LiteralFragment.java (original)
+++ incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/LiteralFragment.java Tue Jun 14 14:14:42 2005
@@ -1,59 +1,59 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * $Header:$
- */
-
-package org.apache.beehive.controls.system.jdbc.parser;
-
-import org.apache.beehive.controls.api.context.ControlBeanContext;
-
-import java.lang.reflect.Method;
-
-/**
- * Represents a portion of the SQL annotation's statement member which is not within substitution delimiters.
- * The parser creates LiteralFragements for portions of the SQL statement which do not require any special processing.
- */
-public final class LiteralFragment extends SqlFragment {
-
-    private final String _value;
-
-    /**
-     * Create an new LiteralFragment with the specified value.
-     * @param value Value of this fragment.
-     */
-    LiteralFragment(String value) {
-        _value = value;
-    }
-
-    /**
-     * Get the text for a PreparedStatement
-     * @param context A ControlBeanContext instance
-     * @param m The annotated method.
-     * @param args The method's parameters.
-     * @return A String containing the literal value for this fragment.
-     */
-    String getPreparedStatementText(ControlBeanContext context, Method m, Object[] args) {
-       return _value;
-    }
-
-    /**
-     * Required for JUnit testing.
-     * @return The String value of this fragment.
-     */
-    public String toString() {
-        return _value;
-    }
-}
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc.parser;
+
+import org.apache.beehive.controls.api.context.ControlBeanContext;
+
+import java.lang.reflect.Method;
+
+/**
+ * Represents a portion of the SQL annotation's statement member which is not within substitution delimiters.
+ * The parser creates LiteralFragements for portions of the SQL statement which do not require any special processing.
+ */
+public final class LiteralFragment extends SqlFragment {
+
+    private final String _value;
+
+    /**
+     * Create an new LiteralFragment with the specified value.
+     * @param value Value of this fragment.
+     */
+    LiteralFragment(String value) {
+        _value = value;
+    }
+
+    /**
+     * Get the text for a PreparedStatement
+     * @param context A ControlBeanContext instance
+     * @param m The annotated method.
+     * @param args The method's parameters.
+     * @return A String containing the literal value for this fragment.
+     */
+    String getPreparedStatementText(ControlBeanContext context, Method m, Object[] args) {
+       return _value;
+    }
+
+    /**
+     * Required for JUnit testing.
+     * @return The String value of this fragment.
+     */
+    public String toString() {
+        return _value;
+    }
+}

Propchange: incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/LiteralFragment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ParameterChecker.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ParameterChecker.java?rev=190657&r1=190656&r2=190657&view=diff
==============================================================================
--- incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ParameterChecker.java (original)
+++ incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ParameterChecker.java Tue Jun 14 14:14:42 2005
@@ -1,196 +1,196 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * $Header:$
- */
-package org.apache.beehive.controls.system.jdbc.parser;
-
-import com.sun.mirror.declaration.ClassDeclaration;
-import com.sun.mirror.declaration.FieldDeclaration;
-import com.sun.mirror.declaration.MethodDeclaration;
-import com.sun.mirror.declaration.ParameterDeclaration;
-import com.sun.mirror.declaration.TypeDeclaration;
-import com.sun.mirror.type.DeclaredType;
-import com.sun.mirror.type.TypeMirror;
-import com.sun.mirror.util.DeclarationFilter;
-import org.apache.beehive.controls.api.ControlException;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-
-/**
- * Does compile-time checking of reflection parameteres in the SQL annotations's statement
- * element vs. method parameters. Invoked by the JdbcControlChecker.
- */
-public class ParameterChecker {
-
-    /**
-     * Verify that all reflection parameters in the statement element can be mapped to method parameters.
-     *
-     * @param statement The parsed statement element.
-     * @param methodDecl The method declaration which was annotated.
-     */
-    public static void checkReflectionParameters(SqlFragmentContainer statement, MethodDeclaration methodDecl) {
-
-        ArrayList<ParameterDeclaration> params =
-                new ArrayList<ParameterDeclaration>(methodDecl.getParameters());
-        HashMap<String, ParameterDeclaration> paramMap = new HashMap<String, ParameterDeclaration>();
-
-        // don't run these checks if this is a compiled class file (method names replaced with arg0, arg1, etc)
-        if (params.size() > 0 && params.get(0).getSimpleName().equals("arg0")) {
-            return;
-        }
-
-        for (int i = 0; i < params.size(); i++) {
-            paramMap.put(params.get(i).getSimpleName(), params.get(i));
-        }
-
-        doCheck(statement, paramMap, methodDecl);
-    }
-
-    /**
-     * Walk the tree of children of the statement, process all children of type ReflectionFragment.
-     *
-     * @param statement The parsed statement element.
-     * @param paramMap The method parameters, keyed by name.
-     * @param method The method declaration which was annotated.
-     */
-    private static void doCheck(SqlFragmentContainer statement, HashMap<String, ParameterDeclaration> paramMap,
-                         final MethodDeclaration method)
-    {
-
-        SqlFragment[] fragments = statement.getChildren();
-        for (SqlFragment fragment : fragments) {
-
-            // if the fragment is a container check all of its children.
-            if (fragment instanceof SqlFragmentContainer) {
-                doCheck((SqlFragmentContainer) fragment, paramMap, method);
-
-                // reflection fragment - make sure it can be mapped using the method's param values.
-            } else if (fragment instanceof ReflectionFragment) {
-                checkReflectionFragment((ReflectionFragment) fragment, paramMap, method);
-            }
-        }
-    }
-
-    /**
-     * Check the fragment.  Must be able to resolve references like 'foo.bar' -> 'foo' where 'foo' is a method param
-     * of a type which contains a public getter or field named 'getBar()' or 'bar' respectively.
-     *
-     * @param fragment The reflection fragment to check.
-     * @param paramMap The method parameters, keyed by name.
-     * @param method The method declaration which was annotated.
-     */
-    private static void checkReflectionFragment(ReflectionFragment fragment,
-                                                HashMap<String, ParameterDeclaration> paramMap, MethodDeclaration method)
-    {
-
-        final String[] paramNameQualifiers = ((ReflectionFragment) fragment).getParameterNameQualifiers();
-        final String parameterName = ((ReflectionFragment) fragment).getParameterName();
-
-        if (paramMap.containsKey(paramNameQualifiers[0]) == false) {
-            throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
-        }
-
-        ParameterDeclaration tpd = paramMap.get(paramNameQualifiers[0]);
-        TypeMirror type = tpd.getType();
-
-        MethodDeclaration getterMethod = null;
-        FieldDeclaration field = null;
-
-        for (int i = 1; i < paramNameQualifiers.length; i++) {
-
-            getterMethod = null;
-            field = null;
-
-            // loop through superclasses until we find a match or run out of superclasses
-            while (type != null) {
-
-                if (type instanceof DeclaredType == false) {
-                    throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
-                }
-
-                TypeDeclaration td = ((DeclaredType) type).getDeclaration();
-                //
-                // abort if Map!!! No further checking can be done.
-                //
-                if (td.getQualifiedName().equals("java.util.Map")) {
-                    return;
-                }
-
-                Collection<? extends MethodDeclaration> methods =
-                        DeclarationFilter.FILTER_PUBLIC.filter(td.getMethods());
-                for (MethodDeclaration m : methods) {
-                    String upperFirst = paramNameQualifiers[i].substring(0,1).toUpperCase();
-                    if (paramNameQualifiers[i].length() > 1) {
-                        upperFirst = upperFirst + paramNameQualifiers[i].substring(1);
-                    }
-                    if (m.getSimpleName().equals("get" + upperFirst)
-                        || m.getSimpleName().equals("is" + upperFirst)) {
-                        getterMethod = m;
-                    }
-                }
-
-                if (getterMethod == null) {
-                    Collection<FieldDeclaration> fields =
-                            DeclarationFilter.FILTER_PUBLIC.filter(td.getFields());
-                    for (FieldDeclaration fd : fields) {
-                        if (fd.getSimpleName().equals(paramNameQualifiers[i])) {
-                            field = fd;
-                        }
-                    }
-                }
-
-                // try the super-class
-                if (getterMethod == null && field == null) {
-                    if (td instanceof ClassDeclaration) {
-                        type = ((ClassDeclaration) td).getSuperclass();
-                        continue;
-                    }
-                }
-
-                break;
-            } // while
-
-            // found a match, get its type and continue within the for loop
-            if (getterMethod != null) {
-                type = getterMethod.getReturnType();
-            } else if (field != null) {
-                type = field.getType();
-            } else {
-                throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
-            }
-        }
-    }
-
-    /**
-     * build the error message for this module.
-     * 
-     * @param parameterName
-     * @param methodName
-     * @return
-     */
-    private static String buildMessage(String parameterName, String methodName) {
-        StringBuilder message = new StringBuilder();
-        message.append("Unable to map the parameter in SQL statement ");
-        message.append(parameterName);
-        message.append(" to a parameter of the method ");
-        message.append(methodName);
-        message.append(". Mapping is accomplished by matching a method parameter name to ");
-        message.append("a value delimited by '{' and '}' in the statement element.");
-        return message.toString();
-    }
-}
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.controls.system.jdbc.parser;
+
+import com.sun.mirror.declaration.ClassDeclaration;
+import com.sun.mirror.declaration.FieldDeclaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.declaration.ParameterDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
+import com.sun.mirror.type.DeclaredType;
+import com.sun.mirror.type.TypeMirror;
+import com.sun.mirror.util.DeclarationFilter;
+import org.apache.beehive.controls.api.ControlException;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+
+/**
+ * Does compile-time checking of reflection parameteres in the SQL annotations's statement
+ * element vs. method parameters. Invoked by the JdbcControlChecker.
+ */
+public class ParameterChecker {
+
+    /**
+     * Verify that all reflection parameters in the statement element can be mapped to method parameters.
+     *
+     * @param statement The parsed statement element.
+     * @param methodDecl The method declaration which was annotated.
+     */
+    public static void checkReflectionParameters(SqlFragmentContainer statement, MethodDeclaration methodDecl) {
+
+        ArrayList<ParameterDeclaration> params =
+                new ArrayList<ParameterDeclaration>(methodDecl.getParameters());
+        HashMap<String, ParameterDeclaration> paramMap = new HashMap<String, ParameterDeclaration>();
+
+        // don't run these checks if this is a compiled class file (method names replaced with arg0, arg1, etc)
+        if (params.size() > 0 && params.get(0).getSimpleName().equals("arg0")) {
+            return;
+        }
+
+        for (int i = 0; i < params.size(); i++) {
+            paramMap.put(params.get(i).getSimpleName(), params.get(i));
+        }
+
+        doCheck(statement, paramMap, methodDecl);
+    }
+
+    /**
+     * Walk the tree of children of the statement, process all children of type ReflectionFragment.
+     *
+     * @param statement The parsed statement element.
+     * @param paramMap The method parameters, keyed by name.
+     * @param method The method declaration which was annotated.
+     */
+    private static void doCheck(SqlFragmentContainer statement, HashMap<String, ParameterDeclaration> paramMap,
+                         final MethodDeclaration method)
+    {
+
+        SqlFragment[] fragments = statement.getChildren();
+        for (SqlFragment fragment : fragments) {
+
+            // if the fragment is a container check all of its children.
+            if (fragment instanceof SqlFragmentContainer) {
+                doCheck((SqlFragmentContainer) fragment, paramMap, method);
+
+                // reflection fragment - make sure it can be mapped using the method's param values.
+            } else if (fragment instanceof ReflectionFragment) {
+                checkReflectionFragment((ReflectionFragment) fragment, paramMap, method);
+            }
+        }
+    }
+
+    /**
+     * Check the fragment.  Must be able to resolve references like 'foo.bar' -> 'foo' where 'foo' is a method param
+     * of a type which contains a public getter or field named 'getBar()' or 'bar' respectively.
+     *
+     * @param fragment The reflection fragment to check.
+     * @param paramMap The method parameters, keyed by name.
+     * @param method The method declaration which was annotated.
+     */
+    private static void checkReflectionFragment(ReflectionFragment fragment,
+                                                HashMap<String, ParameterDeclaration> paramMap, MethodDeclaration method)
+    {
+
+        final String[] paramNameQualifiers = ((ReflectionFragment) fragment).getParameterNameQualifiers();
+        final String parameterName = ((ReflectionFragment) fragment).getParameterName();
+
+        if (paramMap.containsKey(paramNameQualifiers[0]) == false) {
+            throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
+        }
+
+        ParameterDeclaration tpd = paramMap.get(paramNameQualifiers[0]);
+        TypeMirror type = tpd.getType();
+
+        MethodDeclaration getterMethod = null;
+        FieldDeclaration field = null;
+
+        for (int i = 1; i < paramNameQualifiers.length; i++) {
+
+            getterMethod = null;
+            field = null;
+
+            // loop through superclasses until we find a match or run out of superclasses
+            while (type != null) {
+
+                if (type instanceof DeclaredType == false) {
+                    throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
+                }
+
+                TypeDeclaration td = ((DeclaredType) type).getDeclaration();
+                //
+                // abort if Map!!! No further checking can be done.
+                //
+                if (td.getQualifiedName().equals("java.util.Map")) {
+                    return;
+                }
+
+                Collection<? extends MethodDeclaration> methods =
+                        DeclarationFilter.FILTER_PUBLIC.filter(td.getMethods());
+                for (MethodDeclaration m : methods) {
+                    String upperFirst = paramNameQualifiers[i].substring(0,1).toUpperCase();
+                    if (paramNameQualifiers[i].length() > 1) {
+                        upperFirst = upperFirst + paramNameQualifiers[i].substring(1);
+                    }
+                    if (m.getSimpleName().equals("get" + upperFirst)
+                        || m.getSimpleName().equals("is" + upperFirst)) {
+                        getterMethod = m;
+                    }
+                }
+
+                if (getterMethod == null) {
+                    Collection<FieldDeclaration> fields =
+                            DeclarationFilter.FILTER_PUBLIC.filter(td.getFields());
+                    for (FieldDeclaration fd : fields) {
+                        if (fd.getSimpleName().equals(paramNameQualifiers[i])) {
+                            field = fd;
+                        }
+                    }
+                }
+
+                // try the super-class
+                if (getterMethod == null && field == null) {
+                    if (td instanceof ClassDeclaration) {
+                        type = ((ClassDeclaration) td).getSuperclass();
+                        continue;
+                    }
+                }
+
+                break;
+            } // while
+
+            // found a match, get its type and continue within the for loop
+            if (getterMethod != null) {
+                type = getterMethod.getReturnType();
+            } else if (field != null) {
+                type = field.getType();
+            } else {
+                throw new ControlException(buildMessage(parameterName, method.getSimpleName()));
+            }
+        }
+    }
+
+    /**
+     * build the error message for this module.
+     * 
+     * @param parameterName
+     * @param methodName
+     * @return
+     */
+    private static String buildMessage(String parameterName, String methodName) {
+        StringBuilder message = new StringBuilder();
+        message.append("Unable to map the parameter in SQL statement ");
+        message.append(parameterName);
+        message.append(" to a parameter of the method ");
+        message.append(methodName);
+        message.append(". Mapping is accomplished by matching a method parameter name to ");
+        message.append("a value delimited by '{' and '}' in the statement element.");
+        return message.toString();
+    }
+}

Propchange: incubator/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ParameterChecker.java
------------------------------------------------------------------------------
    svn:eol-style = native