Package org.apache.commons.jelly

Examples of org.apache.commons.jelly.JellyException


                else if (obj instanceof String) {
                    try {
                        maxRows = Integer.parseInt((String) obj);
                    }
                    catch (NumberFormatException nfe) {
                        throw new JellyException(
                            Resources.getMessage("SQL_MAXROWS_PARSE_ERROR", (String) obj),
                            nfe);
                    }
                }
                else {
                    throw new JellyException(Resources.getMessage("SQL_MAXROWS_INVALID"));
                }
            }
        }

        Result result = null;
        String sqlStatement = null;

        log.debug( "About to lookup connection" );
       
        try {
            conn = getConnection();

            /*
             * Use the SQL statement specified by the sql attribute, if any,
             * otherwise use the body as the statement.
             */
            if (sql != null) {
                sqlStatement = sql;
            }
            else {
                sqlStatement = getBodyText();
            }
            if (sqlStatement == null || sqlStatement.trim().length() == 0) {
                throw new JellyException(Resources.getMessage("SQL_NO_STATEMENT"));
            }
            /*
             * We shouldn't have a negative startRow or illegal maxrows
             */
            if ((startRow < 0) || (maxRows < -1)) {
                throw new JellyException(Resources.getMessage("PARAM_BAD_VALUE"));
            }

            /*
             * Note! We must not use the setMaxRows() method on the
             * the statement to limit the number of rows, since the
             * Result factory must be able to figure out the correct
             * value for isLimitedByMaxRows(); there's no way to check
             * if it was from the ResultSet.
             */
            if ( log.isDebugEnabled() ) {
                log.debug( "About to execute query: " + sqlStatement );
            }
           
            ResultSet rs = null;
            if ( hasParameters() ) {
                PreparedStatement ps = conn.prepareStatement(sqlStatement);
                setParameters(ps);           
                rs = ps.executeQuery();
            }
            else {
                Statement statement = conn.createStatement();
                rs = statement.executeQuery(sqlStatement);
            }
           
            result = new ResultImpl(rs, startRow, maxRows);
            context.setVariable(var, result);
        }
        catch (SQLException e) {
            throw new JellyException(sqlStatement + ": " + e.getMessage(), e);
        }
        finally {
            if (conn != null && !isPartOfTransaction) {
                try {
                    conn.close();
View Full Code Here


     */
    protected DynamicTagLibrary getTagLibrary() throws JellyException {
        TaglibTag tag
            = (TaglibTag) findAncestorWithClass(TaglibTag.class);
        if ( tag == null ) {
            throw new JellyException( "<define:tag> must be inside <define:taglib>" );
        }
        return tag.getTagLibrary();
    }
View Full Code Here

                context.setVariable(var, answer);
            }
        }
        else {
            if ( target == null ) {
                throw new JellyException( "Either a 'var' or a 'target' attribute must be defined for this tag" );
            }
            if ( property == null ) {
                throw new JellyException( "You must define a 'property' attribute if you specify a 'target'" );
            }
            setPropertyValue( target, property, answer );
        }
    }
View Full Code Here

        // Check that this tag is used inside the body of
        // a DynaClass tag, so that it can access the
        // context of that tag
        DynaclassTag parentTag = (DynaclassTag) findAncestorWithClass( DynaclassTag.class );
        if ( parentTag == null ) {
            throw new JellyException( "This tag must be enclosed inside a <dynaclass> tag" );
        }

        // Check property name
        if (name == null) {
            throw new MissingAttributeException( "name" );
        }

        // Lookup appropriate property class
        Class propClass = propertyClass;
        if (propClass == null) {
           
            // Check property type
            if (type == null) {
                throw new MissingAttributeException( "type" );
            }
   
            if (type.equals("String")) {
                propClass = String.class;
            }
            else if (type.equals("Integer")) {
                propClass = Integer.TYPE;
            }
            else if (type.equals("Short")) {
                propClass = Short.TYPE;
            }
            else if (type.equals("Long")) {
                propClass = Long.TYPE;
            }
            else if (type.equals("Float")) {
                propClass = Float.TYPE;
            }
            else if (type.equals("Double")) {
                propClass = Double.TYPE;
            }
            else if (type.equals("Long")) {
                propClass = Long.TYPE;
            }
   
            if (propClass == null) {
                try {
                    propClass = Class.forName(type);
                }
                catch (Exception e) {
                    throw new JellyException
                            ("Class " + type +
                            " not found by Class.forName");
                }
            }
        }
View Full Code Here

        props =
            (DynaProperty[]) propList.toArray(
                new DynaProperty[propList.size()]);

        if (props == null) {
            throw new JellyException("No properties list");
        }

        if (props.length == 0) {
            throw new JellyException("No properties");
        }

        // Create the dynaclass with name and properties
        dynaClass = (DynaClass) new BasicDynaClass(name, null, props);
View Full Code Here

        };
       
        // lets find the test suite
        TestSuite suite = getSuite();
        if ( suite == null ) {
            throw new JellyException( "Could not find a TestSuite to add this test to. This tag should be inside a <test:suite> tag" );
        }
        suite.addTest(testCase);
    }
View Full Code Here

            try {
                XPath xpath = new Dom4jXPath(attributeValue);
                return new XPathExpression(xpath);
            }
            catch (JaxenException e) {
                throw new JellyException( "Could not parse XPath expression: \"" + attributeValue + "\" reason: " + e, e );           
            }           
        }
       
        if (attributeName.equals("match")) {
            if ( log.isDebugEnabled() ) {
                log.debug( "Parsing XPath pattern: " + attributeValue );
            }
           
            try {
                Pattern pattern = DocumentHelper.createPattern( attributeValue );
                return new XPathPatternExpression(pattern);
            }
            catch (Exception e) {
                throw new JellyException( "Could not parse XPath expression: \"" + attributeValue + "\" reason: " + e, e );           
            }           
        }
       
        // will use the default expression instead
        return super.createExpression(factory, tagName, attributeName, attributeValue);
View Full Code Here

            try {
                XPath xpath = new Dom4jXPath(attributeValue);
                return new XPathExpression(xpath);
            }
            catch (JaxenException e) {
                throw new JellyException( "Could not parse XPath expression: \"" + attributeValue + "\" reason: " + e, e );           
            }           
        }
       
        // will use the default expression instead
        return super.createExpression(factory, tagName, attributeName, attributeValue);
View Full Code Here

        TransactionTag parent =
            (TransactionTag) findAncestorWithClass(TransactionTag.class);
        if (parent != null) {
            if (dataSourceSpecified) {
                throw new JellyException(Resources.getMessage("ERROR_NESTED_DATASOURCE"));
            }
            conn = parent.getSharedConnection();
            isPartOfTransaction = true;
        }
        else {
            if ((rawDataSource == null) && dataSourceSpecified) {
                throw new JellyException(Resources.getMessage("SQL_DATASOURCE_NULL"));
            }
            DataSource dataSource = DataSourceUtil.getDataSource(rawDataSource, context);
            try {
                conn = dataSource.getConnection();
            }
            catch (Exception ex) {
                throw new JellyException(
                    Resources.getMessage("DATASOURCE_INVALID", ex.getMessage()));
            }
        }

        return conn;
View Full Code Here

    // Tag interface
    //-------------------------------------------------------------------------
    public void doTag(XMLOutput output) throws Exception {
        StylesheetTag tag = (StylesheetTag) findAncestorWithClass( StylesheetTag.class );
        if (tag == null) {
            throw new JellyException( "This <template> tag must be used inside a <stylesheet> tag" );
        }

        if ( log.isDebugEnabled() ) {       
            log.debug( "adding template rule for match: " + match );
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.jelly.JellyException

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.