Package org.apache.beehive.controls.api

Examples of org.apache.beehive.controls.api.ControlException


            }

            rows.populate(resultSet);
            return rows;
        } catch (SQLException e) {
            throw new ControlException(e.getMessage(), e);
        }
    }
View Full Code Here


        _fields = null;

        try {
            _columnCount = resultSet.getMetaData().getColumnCount();
        } catch (SQLException e) {
            throw new ControlException("RowToObjectMapper: SQLException: " + e.getMessage(), e);
        }
    }
View Full Code Here

                    if (_returnTypeClass.isAssignableFrom(val.getClass())) {
                        return val;
                    }
                }
            } catch (SQLException e) {
                throw new ControlException(e.getMessage(), e);
            }
        }

        if (_fields == null) {
            try {
                getFieldMappings();
            } catch (SQLException e) {
                throw new ControlException(e.getMessage(), e);
            }
        }

        try {
            resultObject = _returnTypeClass.newInstance();
        } catch (InstantiationException e) {
            throw new ControlException("InstantiationException when trying to create instance of : "
                                       + _returnTypeClass.getName(), e);
        } catch (IllegalAccessException e) {
            throw new ControlException("IllegalAccessException when trying to create instance of : "
                                       + _returnTypeClass.getName(), e);
        }

        for (int i = 1; i < _fields.length; i++) {
            AccessibleObject f = _fields[i];
            Object resultValue = null;

            try {
                resultValue = extractColumnValue(i, _fieldTypes[i]);
                if (f instanceof Field) {
                    ((Field) f).set(resultObject, resultValue);
                } else {
                    _args[0] = resultValue;
                    ((Method) f).invoke(resultObject, _args);
                }
            } catch (SQLException e) {
                throw new ControlException(e.getMessage(), e);
            } catch (IllegalArgumentException iae) {

                try {
                    ResultSetMetaData md = _resultSet.getMetaData();
                    if (f instanceof Field) {
                        throw new ControlException("The declared Java type for field " + ((Field) f).getName()
                                                   + ((Field) f).getType().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());
                    } else {
                        throw new ControlException("The declared Java type for method " + ((Method) f).getName()
                                                   + ((Method) f).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) {
                if (f instanceof Field) {
                    throw new ControlException("IllegalAccessException when trying to access field " + ((Field) f).getName(), e);
                } else {
                    throw new ControlException("IllegalAccessException when trying to access method " + ((Method) f).getName(), e);
                }
            } catch (InvocationTargetException e) {
                if (f instanceof Field) {
                    throw new ControlException("InvocationTargetException when trying to access field " + ((Field) f).getName(), e);
                } else {
                    throw new ControlException("InvocationTargetException when trying to access method " + ((Method) f).getName(), e);
                }
            }
        }
        return resultObject;
    }
View Full Code Here

                    // check for overloads
                    Object field = mapFields.get(fieldName);
                    if (field == null) {
                        mapFields.put(fieldName, m);
                    } else {
                        throw new ControlException("Unable to choose between overloaded methods " + m.getName()
                                                   + " on the " + _returnTypeClass.getName() + " class. Mapping is done using "
                                                   + "a case insensitive comparision of SQL ResultSet columns to field "
                                                   + "names and public setter methods on the return class.");
                    }
                }
            }
        }

        // fix for 8813: include inherited and non-public fields
        for (Class clazz = _returnTypeClass; clazz != null && clazz != Object.class; clazz = clazz.getSuperclass()) {
            Field[] classFields = clazz.getDeclaredFields();
            for (Field f : classFields) {
                if (Modifier.isStatic(f.getModifiers())) continue;
                if (!Modifier.isPublic(f.getModifiers())) continue;
                String fieldName = f.getName().toUpperCase();
                if (!mapFields.containsKey(fieldName)) continue;

                Object field = mapFields.get(fieldName);
                if (field == null) {
                    mapFields.put(fieldName, f);
                }
            }
        }

        // finally actually init the fields array
        _fields = new AccessibleObject[_columnCount + 1];
        _fieldTypes = new int[_columnCount + 1];

        for (int i = 1; i < _fields.length; i++) {
            AccessibleObject f = mapFields.get(keys[i]);
            if (f == 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 field names and public setter methods on the return class.");
            }
View Full Code Here

        Object value = null;
        try {
            value = context.getParameterValue(method, _nameQualifiers[0], args);
        } catch (IllegalArgumentException iae) {
            throw new ControlException("Invalid argument name in SQL statement: " + _nameQualifiers[0], iae);
        }

        for (int i = 1; i < _nameQualifiers.length; i++) {
            // handle maps, properties, and fields...
            value = extractValue(value, _nameQualifiers[i - 1], _nameQualifiers[i]);
View Full Code Here

                } catch (NoSuchMethodException e) {
                    getMethodFound = false;
                }

                if (getMethodFound) {
                    throw new ControlException("Colliding field accsessors in user defined class '"
                                               + aClass.getName() + "' for field '" + bName
                                               + "'. Please use is<FieldName> for boolean fields and get<FieldName> name for other datatypes.");
                }
            }
        } catch (NoSuchMethodException e) {
        }

        //
        // try a.getB() if a.isB() was not found.
        //
        if (getMethod == null) {
            try {
                getMethod = aClass.getMethod("get" + bNameCapped, (Class[])null);
                retType = getMethod.getReturnType();
            } catch (NoSuchMethodException e) {
            }
        }

        if (getMethod != null) {
            // OK- a.getB()
            try {
                value = getMethod.invoke(aValue, (Object[]) null);
            } catch (IllegalAccessException e) {
                throw new ControlException("Unable to access public method: " + e.toString());
            } catch (java.lang.reflect.InvocationTargetException e) {
                throw new ControlException("Exception thrown when executing : " + getMethod.getName() + "() to use as parameter");
            }
            return value;
        }

        //
        // try a.b
        //

        try {
            value = aClass.getField(bName).get(aValue);
            return value;
        } catch (NoSuchFieldException e) {
        } catch (IllegalAccessException e) {
        }

        //
        // try a.get(b)
        //

        if (aValue instanceof Map) {
            try {
                value = TypeMappingsFactory.getInstance().lookupType(aValue, new Object[]{bName});
                return value;
            } catch (Exception mapex) {
                throw new ControlException("Exception thrown when executing Map.get() to resolve parameter" + mapex.toString());
            }
        }

        // no other options...
        if (true) {
            throw new ControlException("Illegal argument in SQL statement: " + _parameterName.toString()
                                       + "; unable to find suitable method of retrieving property " + bName.toString()
                                       + " out of object " + aName.toString() + ".");
        }
        return null;
    }
View Full Code Here

                return _resultSet.getClob(index);
            case TypeMappingsFactory.TYPE_ARRAY:
                return _resultSet.getArray(index);
            case TypeMappingsFactory.TYPE_READER:
            case TypeMappingsFactory.TYPE_STREAM:
                throw new ControlException("streaming return types are not supported by the JdbcControl; use ResultSet instead");
            case TypeMappingsFactory.TYPE_STRUCT:
            case TypeMappingsFactory.TYPE_UNKNOWN:
                // JAVA_TYPE (could be any), or REF
                return _resultSet.getObject(index);
            default:
                throw new ControlException("internal error: unknown type ID: " + Integer.toString(resultType));
        }
    }
View Full Code Here

            Class factoryClass = discoverer.find(ControlBeanContextFactory.class, DefaultControlBeanContextFactory.class.getName());
            ControlBeanContextFactory factory = (ControlBeanContextFactory)factoryClass.newInstance();
            _cbc = factory.instantiate(this);
        }
        catch (Exception e) {
            throw new ControlException("Exception creating ControlBeanContext", e);
        }

        //_cbc = new ControlBeanContext( this );

        //
View Full Code Here

                                        _implClass.getName() + "Initializer");
                _implInitializer = (ImplInitializer)initClass.newInstance();
            }
            catch (Exception e)
            {
                throw new ControlException("Control initialization failure", e);
            }
        }
        return _implInitializer;
    }
View Full Code Here

                // annotation, else downstream requirements (such as having a valid control init
                // class) will not be met.
                //
                if (_implClass.getAnnotation(ControlImplementation.class) == null)
                {
                    throw new ControlException("@" + ControlImplementation.class.getName() + " annotation is missing from control implementation class: " + _implClass.getName());
                }
            }
            catch (ClassNotFoundException cnfe)
            {
                throw new ControlException("Unable to load control implementation: "  + implBinding, cnfe);
            }

            //
            // Cache the threading policy associated with the impl
            //
            Threading thr = (Threading)_implClass.getAnnotation(Threading.class);
            if ( thr != null )
                _threadingPolicy = thr.value();
            else
                _threadingPolicy = ThreadingPolicy.SINGLE_THREADED;    // default to single-threaded

            ensureThreadingBehaviour();

            try
            {
                //
                // Create and initialize the new instance
                //
                _control = _implClass.newInstance();

                try
                {
                    /*
                    Run the ImplInitializer.  This class is code generated based on metadata from a control
                    implementation.  If a Control implementation declares event handlers for the
                    ControlBeanContext or for the ResourceContext, executing this code generated class
                    will add the appropriate LifeCycle and / or Resource event listeners.
                     */
                    getImplInitializer().initialize(this, _control);
                    _hasServices = true;
                }
                catch (Exception e)
                {
                    throw new ControlException("Control initialization failure", e);
                }

                //
                // Once the control is initialized, then allow the associated context
                // to do any initialization.
                //
                ControlBeanContext cbcs = getBeanContextProxy();

                /*
                Implementation note: this call will run the LifeCycleListener(s) that have
                been wired-up to the ControlBeanContext object associated with this ControlBean.
                */
                cbcs.initializeControl();
            }
            catch (RuntimeException re) {
                // never mask RuntimeExceptions
                throw re;
            }
            catch (Exception e)
            {
                throw new ControlException("Unable to create control instance", e);
            }
        }

        //
        // If the implementation instance does not currently have contextual services, they
View Full Code Here

TOP

Related Classes of org.apache.beehive.controls.api.ControlException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.