Package com.volantis.xml.pipeline.sax.impl.template

Examples of com.volantis.xml.pipeline.sax.impl.template.TemplateModel


        XMLPipelineContext pipelineContext =
                dynamicProcess.getPipelineContext();

        // Get the model for containing template for bindings that reference
        // values in containing templates, may be null.
        TemplateModel containing = (TemplateModel) pipelineContext.findObject(
                TemplateModel.class);

        // Create the template process and add it to the pipeline.
        TemplateProcess process = new TemplateProcess(containing);
        dynamicProcess.addProcess(process);

        // Push the template model onto the stack so it can be picked up by
        // nested elements.
        TemplateModel model = process;
        pipelineContext.pushObject(model, false);

        // Start the template.
        model.startTemplate();

        // The presence or absence of the href attribute determines the gross
        // structure of the template:apply.
        String href = attributes.getValue("href");
        EndElementAction action;
        if (href == null) {

            // Template must be inline so a template:bindings element is
            // expected.
            action = new EndTemplateAction(model, process);
        } else {

            // Pretend that we have received a template:bindings element.
            model.startBindings();

            // Template definition needs including at the end
            // of the operation.
            action = new IncludeDefinitionAction(model, process, href);
        }
View Full Code Here


    // Javadoc inherited.
    public Object startElement(
            DynamicProcess dynamicProcess, ExpandedName element,
            Attributes attributes) throws SAXException {

        final TemplateModel model = getModel(dynamicProcess);

        model.startElement(TemplateSchema.PARAMETER);

        final String name = attributes.getValue("name");

        // Convert the type attribute value into an enumeration.
        String type = attributes.getValue("type");
        Complexity complexity;
        if (type == null) {
            complexity = Complexity.SIMPLE;
        } else {
            complexity = Complexity.literal(type);
            if (complexity == null) {
                throw forwardFatalError(dynamicProcess,
                        "Unknown type '" + type + "'");
            }
        }

        // Convert the use attribute value into an enumeration.
        String useAsString = attributes.getValue("use");
        Use use;
        if (useAsString == null) {
            use = Use.REQUIRED;
        } else {
            use = Use.literal(useAsString);
            if (use == null) {
                throw forwardFatalError(dynamicProcess,
                        "Unknown use '" + useAsString + "'");
            }
        }

        String defaultValue = attributes.getValue("default");

        String variable = attributes.getValue("expressionVariable");

        EndElementAction action;

        if (name == null) {
            throw forwardFatalError(dynamicProcess,
                    "A name must be provided for a parameter");
        } else if (use == Use.REQUIRED && defaultValue != null) {
            throw forwardFatalError(dynamicProcess,
                    "Default values cannot be specified for " +
                    "mandatory parameter '" + name + "'");
        } else {
            ParameterBlock parameters = model.getParameterBlock();
            TValue boundValue = parameters.query(name);

            if (boundValue != null) {
                if (boundValue.getComplexity() == Complexity.COMPLEX &&
                        complexity == Complexity.SIMPLE) {

                    throw forwardFatalError(dynamicProcess,
                            "A complex binding has been provided for the " +
                            "simple parameter " + name);
                } else {

                    model.transition(TemplateSchema.VALUE_START);

                    dynamicProcess.getPipelineContext()
                            .getFlowControlManager().exitCurrentElement();

                    // Record the fact that the existing binding value is
                    // "good"
                    boundValue.verify();

                    model.transition(TemplateSchema.VALUE_END);

                    action = new EndParameterAction(model);
                }
            } else if (use == Use.REQUIRED) {
                throw forwardFatalError(dynamicProcess,
                        "No binding has been provided for required " +
                        "parameter " + name);
            } else {
                // The parameter is optional and has no existing binding
                if (defaultValue != null) {

                    TValue value = model.createSimpleValue(defaultValue);
                    model.addDefaultValue(name, value);

                    action = new EndParameterAction(model);

                } else {
                    model.setValueSetter(new TemplateValueSetter() {

                        public void setTemplateValue(TValue value)
                                throws SAXException {
                            model.addDefaultValue(name, value);
                        }
                    });
                    action = new EndParameterAction(model);
                }
            }
View Full Code Here

    // Javadoc inherited.
    public Object startElement(
            DynamicProcess dynamicProcess, ExpandedName element,
            Attributes attributes) throws SAXException {

        TemplateModel model = getModel(dynamicProcess);

        model.startDeclarations();

        return null;
    }
View Full Code Here

    // Javadoc inherited.
    protected void endElementImpl(
            DynamicProcess dynamicProcess, ExpandedName element, Object object)
            throws SAXException {

        TemplateModel model = getModel(dynamicProcess);

        // Make sure that all the bindings supplied by the apply are correct.
        ParameterBlock parameters = model.getParameterBlock();
        for (Iterator i = parameters.iterator(); i.hasNext();) {
            String name = (String) i.next();
            TValue binding = parameters.query(name);

            if (!binding.isVerified()) {
                forwardFatalError(dynamicProcess,
                        "Binding \"" + name + "\" has been " +
                        "supplied that does not exist in the template " +
                        "definition declarations");
            }
        }

        model.endDeclarations();
    }
View Full Code Here

    // Javadoc inherited.
    public Object startElement(
            DynamicProcess dynamicProcess, ExpandedName element,
            Attributes attributes) throws SAXException {

        TemplateModel model = getModel(dynamicProcess);

        String ref = attributes.getValue("ref");
        if (ref == null) {
            throw forwardFatalError(dynamicProcess,
                    "A ref must be provided for a value");
        }

        TValue value = model.getParameterBlock().query(ref);
        if (value == null) {
            throw forwardFatalError(dynamicProcess,
                    "Parameter " + ref + " not defined in the current scope");
        }
View Full Code Here

    // Javadoc inherited.
    public Object startElement(
            DynamicProcess dynamicProcess, ExpandedName element,
            Attributes attributes) throws SAXException {

        TemplateModel model = getModel(dynamicProcess);

        String evaluationMode = attributes.getValue("evaluationMode");
        EvaluationMode mode;
        if (evaluationMode == null) {
            mode = EvaluationMode.IMMEDIATE;
        } else {
            mode = EvaluationMode.literal(evaluationMode);
            if (mode == null) {
                throw forwardFatalError(dynamicProcess,
                        "Unknown evaluation mode '" + evaluationMode + "'");
            }
        }

        if (mode != EvaluationMode.IMMEDIATE) {
            dynamicProcess.passThroughElementContents();
        }

        model.startValueDefinition(this.element, mode);
        return model;
    }
View Full Code Here

    // Javadoc inherited.
    protected void endElementImpl(
            DynamicProcess dynamicProcess, ExpandedName element, Object object)
            throws SAXException {

        TemplateModel model = (TemplateModel) object;
        model.endValueDefinition(this.element, complexity);
    }
View Full Code Here

        // create a new stack frame and execute the pending variable
        // declarations
        final ExpressionContext expressionContext =
            dynamicProcess.getPipelineContext().getExpressionContext();
        expressionContext.pushStackFrame();
        final TemplateModel model = getModel(dynamicProcess);
        model.executePendingVariableDeclarations();
        return super.startElement(dynamicProcess, element, attributes);
    }
View Full Code Here

    public Object startElement(
            DynamicProcess dynamicProcess, ExpandedName element,
            Attributes attributes) throws SAXException {

        final TemplateModel model = getModel(dynamicProcess);
        model.startElement(TemplateSchema.BINDING);

        final String name = attributes.getValue("name");
        if (name == null) {
            throw forwardFatalError(dynamicProcess,
                    "A name must be provided for a binding");
        }

        String value = attributes.getValue("value");
        String ref = attributes.getValue("ref");

        TValue tValue;
        if (value != null && ref != null) {
            throw forwardFatalError(dynamicProcess,
                    "Only one of 'value' or 'ref' may be specified");
        } else if (value != null) {
            tValue = model.createSimpleValue(value);
            model.addBindingValue(name, tValue);
        } else if (ref != null) {
            tValue = model.createReferenceValue(ref);
            model.addBindingValue(name, tValue);
        } else {
            model.setValueSetter(new TemplateValueSetter() {

                public void setTemplateValue(TValue value) {
                    model.addBindingValue(name, value);
                }
            });
            tValue = null;
        }
View Full Code Here

    protected void endElementImpl(
            DynamicProcess dynamicProcess, ExpandedName element, Object object)
            throws SAXException {

        final TemplateModel model = getModel(dynamicProcess);

        model.endElement(TemplateSchema.BINDING);
    }
View Full Code Here

TOP

Related Classes of com.volantis.xml.pipeline.sax.impl.template.TemplateModel

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.