Package org.apache.beehive.controls.api

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


    RowToHashMapMapper(ResultSet resultSet, Class returnTypeClass, Calendar cal) {
        super(resultSet, returnTypeClass, cal);
        try {
            _keys = getKeysFromResultSet();
        } catch (SQLException sql) {
            throw new ControlException("RowToHashMapMapper: SQLException: " + sql.getMessage(), sql);
        }
    }
View Full Code Here


     */
    public Object mapRowToReturnType() {
        try {
            return new ResultSetHashMap(_resultSet, _keys);
        } catch (SQLException e) {
            throw new ControlException("Exception creating HashMap return type: ", e);
        }
    }
View Full Code Here

        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()));
            }
        }
    }
View Full Code Here

                    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;
    }
View Full Code Here

        _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.");
            }
View Full Code Here

    RowToMapMapper(ResultSet resultSet, Class returnTypeClass, Calendar cal) {
        super(resultSet, returnTypeClass, cal);
        try {
        _keys = getKeysFromResultSet();
        } catch (SQLException e) {
            throw new ControlException("RowToMapMapper: SQLException: " + e.getMessage(), e);
        }
    }
View Full Code Here

     */
    public Object mapRowToReturnType() {
        try {
        return Collections.unmodifiableMap(new ResultSetHashMap(_resultSet, _keys));
        } catch (SQLException e) {
           throw new ControlException("Exception while creating ResultSetHashMap.", e);
        }
    }
View Full Code Here

        Constructor c = null;
        try {
            c = rowMapper.getDeclaredConstructor(_params);
            return (RowMapper) c.newInstance(new Object[]{rs, returnType, cal});
        } catch (NoSuchMethodException e) {
            throw new ControlException("Failure creating new instance of RowMapper, " + e.toString(), e);
        } catch (InstantiationException e) {
            throw new ControlException("Failure creating new instance of RowMapper, " + e.toString(), e);
        } catch (IllegalAccessException e) {
            throw new ControlException("Failure creating new instance of RowMapper, " + e.toString(), e);
        } catch (InvocationTargetException e) {
            throw new ControlException("Failure creating new instance of RowMapper, " + e.getCause().toString(), e);
        }
    }
View Full Code Here

        //
        if (remoteHome != null)
        {
            if (localHome != null)
            {
                throw new ControlException(controlInterface +
                                           " extends multiple EJB home interfaces.");
            }
            _homeInterface = getRoot(remoteHome, derivesFrom);
        }
        else if (localHome != null)
        {
            _homeInterface = getRoot(localHome, derivesFrom);
        }
        else
        {
            throw new ControlException(controlInterface +
                " does not extend the EJBHome or EJBLocalHome interfaces");
        }

        if (remoteBean != null)
        {
            if (localBean != null)
            {
                throw new ControlException("Interface " + controlInterface +
                            " extends multiple EJB object interfaces.");
            }
            _beanInterface = getRoot(remoteBean, derivesFrom);
        }
        else if (localBean != null)
        {
            _beanInterface = getRoot(localBean, derivesFrom);
        }
        else
        {
            throw new ControlException("Interface " + controlInterface +
             " does not extend the EJBObject or EJBLocalObject interfaces");
        }

        // Identify the bean type via bean interface reflection
        _beanType = "Session";
View Full Code Here

        JdbcControl.SQL methodSQL = (JdbcControl.SQL) context.getMethodPropertySet(method, JdbcControl.SQL.class);
        _returnClass = methodSQL.iteratorElementType();

        if (_returnClass == null) {
            throw new ControlException("Invalid return class declared for Iterator:" + _returnClass.getName());
        }

        _rowMapper = RowMapperFactory.getRowMapper(rs, _returnClass, cal);
    }
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.