Package com.javaforge.bobber.archetype.model

Examples of com.javaforge.bobber.archetype.model.Variable


                        }
                    }
                    getLogger().debug("Not Expr: " + not);
                    getLogger().debug("Condition Value: '" + condition + "'");
                    getLogger().debug("Required Value: '" + requiredValue + "'");
                    final Variable var = (Variable) findVariable(condition, variables);
                    if (var != null)
                    {
                        final String strValue = (String) context.get(var.getName());
                        getLogger().debug("Variable Value is: '" + strValue + "'");
                        if (requiredValue == null)
                        {
                            if (!Boolean.valueOf(strValue).booleanValue())
                            {
View Full Code Here


    protected void processVariables(Iterator variables, VelocityContext context, final boolean interactiveMode) throws ArchetypeTemplateProcessingException
    {
        while (variables.hasNext())
        {
            Variable var = (Variable) variables.next();
            String val = System.getProperty(var.getName(), var.getDefvalue());

            if (interactiveMode)
            {

                StringBuffer message = new StringBuffer();
                message.append(var.getName()).append(": ")
                        .append(NEW_LINE)
                        .append(StringUtils.repeat("*", MESSAGE_LINE_LENGTH))
                        .append(NEW_LINE)
                        .append(NEW_LINE)
                        .append(StringUtils.center(var.getDescription(), MESSAGE_LINE_LENGTH))
                        .append(NEW_LINE)
                        .append(StringUtils.leftPad("[default: " + val + "]", MESSAGE_LINE_LENGTH))
                        .append(NEW_LINE)
                        .append(StringUtils.repeat("*", MESSAGE_LINE_LENGTH));
                getLogger().info(message.toString());
                try
                {
                    String answer = inputHandler.readLine();
                    if (!StringUtils.isEmpty(answer))
                    {
                        val = answer;
                    }
                }
                catch (IOException ie)
                {
                    throw new ArchetypeTemplateProcessingException(ie);
                }
                context.put(var.getName(), val);
            }
            else
            {
                context.put(var.getName(), val);
            }

            if (val.toLowerCase().equals("false") || val.toLowerCase().equals("n"))
            {
                if (var.getVariables() != null)
                {
                    //keep processing the variables picking up the default values
                    processVariables(var.getVariables().iterator(), context, false);

                }
            }
            else if (var.getVariables() != null)
            {
                //keep processing the variables in the current interaction mode
                processVariables(var.getVariables().iterator(), context, interactiveMode);

            }
        }

    }
View Full Code Here

    protected Object findVariable(String variableName, List variables)
    {

        for (int i = 0; i < variables.size(); i++)
        {
            Variable var = (Variable) variables.get(i);
            if (variableName.equals(var.getName()))
            {
                return var;
            }
            else if (var.getVariables() != null)
            {
                Object o = findVariable(variableName, var.getVariables());
                if (o != null)
                {
                    return o;
                }
            }
View Full Code Here

            if ( bobberArchetype.getVariables() != null && bobberArchetype.getVariables().size() > 0 )
            {
                serializer.startTag( NAMESPACE, "variables" );
                for ( Iterator iter = bobberArchetype.getVariables().iterator(); iter.hasNext(); )
                {
                    Variable o = (Variable) iter.next();
                    writeVariable( o, "variable", serializer );
                }
                serializer.endTag( NAMESPACE, "variables" );
            }
            if ( bobberArchetype.getTemplates() != null && bobberArchetype.getTemplates().size() > 0 )
View Full Code Here

            if ( variable.getVariables() != null && variable.getVariables().size() > 0 )
            {
                serializer.startTag( NAMESPACE, "variables" );
                for ( Iterator iter = variable.getVariables().iterator(); iter.hasNext(); )
                {
                    Variable o = (Variable) iter.next();
                    writeVariable( o, "variable", serializer );
                }
                serializer.endTag( NAMESPACE, "variables" );
            }
            serializer.endTag( NAMESPACE, tagName );
View Full Code Here

     * @return Variable
     */
    private Variable parseVariable(String tagName, XmlPullParser parser, boolean strict)
        throws IOException, XmlPullParserException
    {
        Variable variable = new Variable();
        java.util.Set parsed = new java.util.HashSet();
        while ( parser.nextTag() == XmlPullParser.START_TAG )
        {
            if ( parser.getName().equals( "name" )  )
            {
                if ( parsed.contains( "name" ) )
                {
                    throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null );
                }
                parsed.add( "name" );
                variable.setName( getTrimmedValue( parser.nextText()) );
            }
            else if ( parser.getName().equals( "description" )  )
            {
                if ( parsed.contains( "description" ) )
                {
                    throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null );
                }
                parsed.add( "description" );
                variable.setDescription( getTrimmedValue( parser.nextText()) );
            }
            else if ( parser.getName().equals( "defvalue" )  )
            {
                if ( parsed.contains( "defvalue" ) )
                {
                    throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null );
                }
                parsed.add( "defvalue" );
                variable.setDefvalue( getTrimmedValue( parser.nextText()) );
            }
            else if ( parser.getName().equals( "variables" )  )
            {
                if ( parsed.contains( "variables" ) )
                {
                    throw new XmlPullParserException( "Duplicated tag: '" + parser.getName() + "'", parser, null );
                }
                parsed.add( "variables" );
                java.util.List variables = new java.util.ArrayList();
                variable.setVariables( variables );
                while ( parser.nextTag() == XmlPullParser.START_TAG )
                {
                    if ( parser.getName().equals( "variable" ) )
                    {
                        variables.add( parseVariable( "variable", parser, strict ) );
View Full Code Here

                        }
                    }
                    getLogger().debug("Not Expr: " + not);
                    getLogger().debug("Condition Value: '" + condition + "'");
                    getLogger().debug("Required Value: '" + requiredValue + "'");
                    final Variable var = (Variable) findVariable(condition, variables);
                    if (var != null) {
                        final String strValue = (String) context.get(var.getName());
                        getLogger().debug("Variable Value is: '" + strValue + "'");
                        if(requiredValue==null)
                        {
                            if (!Boolean.valueOf(strValue).booleanValue()) {
                                shouldProcess = false;
View Full Code Here

    }

    protected void processVariables(Iterator variables, VelocityContext context, final boolean interactiveMode) throws ArchetypeTemplateProcessingException
    {
        while (variables.hasNext()) {
            Variable var = (Variable) variables.next();
            String val = System.getProperty(var.getName(), var.getDefvalue());

            if (interactiveMode) {

                    StringBuffer message = new StringBuffer();
                    message.append(var.getName()).append(": ")
                            .append(NEW_LINE)
                            .append(StringUtils.repeat("*", MESSAGE_LINE_LENGTH))
                            .append(NEW_LINE)
                            .append(NEW_LINE)
                            .append(StringUtils.center(var.getDescription(), MESSAGE_LINE_LENGTH))
                            .append(NEW_LINE)
                            .append(StringUtils.leftPad("[default: " + val + "]", MESSAGE_LINE_LENGTH))
                            .append(NEW_LINE)
                            .append(StringUtils.repeat("*", MESSAGE_LINE_LENGTH));
                    getLogger().info(message.toString());
                    try {
                        String answer = inputHandler.readLine();
                        if (!StringUtils.isEmpty(answer)) {
                            val = answer;
                        }
                    } catch (IOException ie) {
                        throw new ArchetypeTemplateProcessingException(ie);
                    }
                    context.put(var.getName(), val);
            }
            else
            {
                context.put(var.getName(), val);
            }

            if(val.toLowerCase().equals("false") || val.toLowerCase().equals("n"))
            {
                if(var.getVariables() !=null)
                {
                    //keep processing the variables picking up the default values
                    processVariables(var.getVariables().iterator(), context, false);

                }
            } else if(var.getVariables() !=null)
            {
                //keep processing the variables picking up the default values
                processVariables(var.getVariables().iterator(), context, true);

            }
        }

    }
View Full Code Here

     * @return variable value or null of not found
     */
    protected Object findVariable (String variableName, List variables) {

        for (int i = 0; i < variables.size(); i++) {
            Variable var = (Variable) variables.get(i);
            if (variableName.equals(var.getName())) {
                return var;
            } else if(var.getVariables()!=null) {
                Object o = findVariable(variableName, var.getVariables());
                if(o!=null) {
                    return o;
                }
            }
        }
View Full Code Here

                        }
                    }
                    getLogger().debug("Not Expr: " + not);
                    getLogger().debug("Condition Value: '" + condition + "'");
                    getLogger().debug("Required Value: '" + requiredValue + "'");
                    final Variable var = (Variable) findVariable(condition, variables);
                    if (var != null)
                    {
                        final String strValue = (String) context.get(var.getName());
                        getLogger().debug("Variable Value is: '" + strValue + "'");
                        if (requiredValue == null)
                        {
                            if (!Boolean.valueOf(strValue).booleanValue())
                            {
View Full Code Here

TOP

Related Classes of com.javaforge.bobber.archetype.model.Variable

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.