Package org.wso2.carbon.mediator.service

Examples of org.wso2.carbon.mediator.service.MediatorException


    public void build(OMElement elem) {
        OMAttribute name = elem.getAttribute(ATT_NAME);
        if (name == null) {
            String msg = "The name of the actual POJO command implementation class" +
                    " is a required attribute";
            throw new MediatorException(msg);
        }

        this.command = name.getAttributeValue();

        // setting the properties to the command. these properties will be instantiated
        // at the mediation time
        for (Iterator it = elem.getChildElements(); it.hasNext();) {
            OMElement child = (OMElement) it.next();
            if("property".equals(child.getLocalName())) {

                OMAttribute nameAttr = child.getAttribute(ATT_NAME);
                if (nameAttr != null && nameAttr.getAttributeValue() != null
                    && !"".equals(nameAttr.getAttributeValue())) {

                    handlePropertyAction(nameAttr.getAttributeValue(), child);
                } else {
                    throw new MediatorException("A POJO command mediator " +
                        "property must specify the name attribute");
                }
            }
        }
    }
View Full Code Here


        try {
            if (exprAttr != null) {
                xpath = SynapseXPathFactory.getSynapseXPath(propElem, ATT_EXPRN);
            }
        } catch (JaxenException e) {
            throw new MediatorException("Error in building the expression as an SynapseXPath" + e);
        }

        // if there is a value attribute there is no action (action is implied as read value)
        if (valueAttr != null) {
            String value = valueAttr.getAttributeValue();
            // all other three attributes can not co-exists
            if (exprAttr != null && ctxNameAttr != null) {
                throw new MediatorException("Command properties can not contain all three 'value', " +
                    "'expression' and 'context-name' attributes. Only one or " +
                    "combination of two can be there.");
            } else {
                addStaticSetterProperty(name, value);
                if (exprAttr != null) {
                    // action ==> ReadValueAndUpdateMesssage
                    addMessageGetterProperty(name, xpath);
                } else if (ctxNameAttr != null) {
                    // action ==> ReadValueAndUpdateContext
                    addContextGetterProperty(name, ctxNameAttr.getAttributeValue());
                } // else the action ==> ReadValue
            }
        } else if (propElem.getFirstElement() != null) {
            // all other two attributes can not co-exists
            if (exprAttr != null && ctxNameAttr != null) {
                throw new MediatorException("Command properties can not contain all the " +
                    "'expression' and 'context-name' attributes with a child. Only one " +
                    "attribute of those can co-exists with a child");
            } else {
                addStaticSetterProperty(name, propElem.getFirstElement());
                if (exprAttr != null) {
                    // action ==> ReadValueAndUpdateMesssage
                    addMessageGetterProperty(name, xpath);
                } else if (ctxNameAttr != null) {
                    // action ==> ReadValueAndUpdateContext
                    addContextGetterProperty(name, ctxNameAttr.getAttributeValue());
                } // else the action ==> ReadValue
            }
        } else {
            // if both context-name and expression is there
            if (exprAttr != null && ctxNameAttr != null) {
                if (actionAttr != null && actionAttr.getAttributeValue() != null) {
                    String action = actionAttr.getAttributeValue();
                    if (RM_ACTION.equals(action) || UC_ACTION.equals(action)) {
                        // action ==> ReadMessageAndUpdateContext
                        addMessageSetterProperty(name, xpath);
                        addContextGetterProperty(name, ctxNameAttr.getAttributeValue());
                    } else if (RC_ACTION.equals(action) || UM_ACTION.equals(action)) {
                        // action ==> ReadContextAndUpdateMessage
                        addContextSetterProperty(name, ctxNameAttr.getAttributeValue());
                        addMessageGetterProperty(name, xpath);
                    } else {
                        throw new MediatorException("Invalid action for " +
                            "the command property with the name " + name);
                    }
                } else {
                    throw new MediatorException("Action attribute " +
                        "is required for the command property with name " + name);
                }
            } else {
                // only one of expression or context-name is present
                if (actionAttr != null && actionAttr.getAttributeValue() != null) {
                    String action = actionAttr.getAttributeValue();
                    if (exprAttr != null) {
                        if (RM_ACTION.equals(action)) {
                            // action ==> ReadMessage
                            addMessageSetterProperty(name, xpath);
                        } else if (UM_ACTION.equals(action)) {
                            // action ==> UpdateMessage
                            addMessageGetterProperty(name, xpath);
                        } else if (RAUM_ACTION.equals(action)) {
                            // action ==> ReadAndUpdateMessage
                            addMessageSetterProperty(name, xpath);
                            addMessageGetterProperty(name, xpath);
                        } else {
                            throw new MediatorException("Invalid action for " +
                                "the command property with the name " + name);
                        }
                    } else if (ctxNameAttr != null) {
                        String ctxName = ctxNameAttr.getAttributeValue();
                        if (RC_ACTION.equals(action)) {
                            // action ==> ReadContext
                            addContextSetterProperty(name, ctxName);
                        } else if (UC_ACTION.equals(action)) {
                            // action ==> UpdateContext
                            addContextGetterProperty(name, ctxName);
                        } else if (RAUC_ACTION.equals(action)) {
                            // action ==> ReadAndUpdateContext
                            addContextSetterProperty(name, ctxName);
                            addContextGetterProperty(name, ctxName);
                        } else {
                            throw new MediatorException("Invalid action for " +
                                "the command property with the name " + name);
                        }
                    } else {
                        throw new MediatorException("Unrecognized command property with the name " + name);
                    }
                } else {
                    // action ==> ReadAndUpdateMessage/Context
                    if (exprAttr != null) {
                        addMessageSetterProperty(name, xpath);
                        addMessageGetterProperty(name, xpath);
                    } else if (ctxNameAttr != null) {
                        String ctxName = ctxNameAttr.getAttributeValue();
                        addContextSetterProperty(name, ctxName);
                        addContextGetterProperty(name, ctxName);
                    } else {
                        throw new MediatorException("Unrecognized command property with the name " + name);
                    }
                }
            }
        }
    }
View Full Code Here

                        && !sourceXpathAttr.getAttributeValue().equals("")) {
                    try {
                        sourceExpression = SynapseXPathFactory.getSynapseXPath(childElem, new QName(XPATH));
                    } catch (JaxenException e) {
                        String msg = "Invalid XPath expression for 'source' attribute 'xpath' : " + sourceXpathAttr.getAttributeValue();
                        throw new MediatorException(msg);
                    }
                }

                OMAttribute sourcePropertyAttr = childElem.getAttribute(new QName(PROPERTY));
                if (sourcePropertyAttr != null && sourcePropertyAttr.getAttributeValue() != null) {
                    sourceProperty = sourcePropertyAttr.getAttributeValue();
                }

                OMElement inlineXMLElement = childElem.getFirstElement();
                if (inlineXMLElement != null) {
                    sourceInlineXML = inlineXMLElement.toString();
                } else if (childElem.getAttributeValue(new QName(null, INLINE_REG_KEY)) != null) {
                    inlineSourceRegKey = childElem.getAttributeValue(new QName(null, INLINE_REG_KEY));
                }
            }

            if (childElem.getLocalName().equals(TARGET)) {
                OMAttribute actionAttr = childElem.getAttribute(new QName(ACTION));
                if (actionAttr != null && actionAttr.getAttributeValue() != null) {
                    targetAction = actionAttr.getAttributeValue();
                } else {
                    targetAction = DEFAULT_TARGET_ACTION_TYPE;
                }

                OMAttribute targetTypeAttr = childElem.getAttribute(new QName(TYPE));
                if (targetTypeAttr != null && targetTypeAttr.getAttributeValue() != null) {
                    targetType = targetTypeAttr.getAttributeValue();
                } else {
                    targetType = DEFAULT_TARGET_TYPE;
                }

                OMAttribute targetXpathAttr = childElem.getAttribute(new QName(XPATH));
                if (targetXpathAttr != null
                        && targetXpathAttr.getAttributeValue() != null
                        && !targetXpathAttr.getAttributeValue().equals("")) {
                    try {
                        targetExpression = SynapseXPathFactory.getSynapseXPath(childElem, new QName(XPATH));
                    } catch (JaxenException e) {
                        String msg = "Invalid XPath expression for 'target' attribute 'xpath' : " + targetXpathAttr.getAttributeValue();
                        throw new MediatorException(msg);
                    }

                }

                OMAttribute targetPropertyAttr = childElem.getAttribute(new QName(PROPERTY));
View Full Code Here

            for (MediatorProperty mp : explicityFeatures) {
                OMElement feature = fac.createOMElement("feature", synNS, validate);
                if (mp.getName() != null) {
                    feature.addAttribute(fac.createOMAttribute("name", nullNS, mp.getName()));
                } else {
                    throw new MediatorException("The Feature name is missing");
                }
                if (mp.getValue() != null) {
                    feature.addAttribute(fac.createOMAttribute("value", nullNS, mp.getValue()));
                } else {
                    throw new MediatorException("The Feature value is missing");
                }
            }
        }
        OMElement onFail = fac.createOMElement("on-fail", synNS, validate);
        serializeChildren(onFail, getList());
View Full Code Here

                    ValueFactory keyFactory = new ValueFactory();
                    Value key = keyFactory.createValue(XMLConfigConstants.KEY, omElem);
                    schemaKeys.add(key);

                } else {
                    throw new MediatorException("A 'schema' definition must contain a local property 'key'");
                }
            } else {
                throw new MediatorException("Invalid 'schema' declaration for validate mediator");
            }
        }

        if (schemaKeys.size() == 0) {
            throw new MediatorException("No schemas specified for the validate mediator");
        } else {
            this.schemaKeys = schemaKeys;
        }

        // process source XPath attribute if present
        OMAttribute attSource = elem.getAttribute(ATT_SOURCE);

        if (attSource != null) {
            try {
                source = SynapseXPathFactory.getSynapseXPath(elem, ATT_SOURCE);
            } catch (JaxenException e) {
                throw new MediatorException("Invalid XPath expression specified for attribute 'source'");
            }
        }

        // process on-fail
        OMElement onFail = null;
        Iterator iterator = elem.getChildrenWithName(ON_FAIL_Q);
        if (iterator.hasNext()) {
            onFail = (OMElement) iterator.next();
        }

        if (onFail != null && onFail.getChildElements().hasNext()) {
            addChildren(onFail, this);
        } else {
            throw new MediatorException("A non-empty <on-fail> child element is required for " +
                    "the <validate> mediator");
        }

        // after successfully creating the mediator
        // set its common attributes such as tracing etc
        processAuditStatus(this, elem);
        // set the features
        for (Map.Entry<String, String> entry : collectNameValuePairs(elem, FEATURE_Q).entrySet()) {
            String value = entry.getValue();
            boolean isFeatureEnabled;
            if ("true".equals(value)) {
                isFeatureEnabled = true;
            } else if ("false".equals(value)) {
                isFeatureEnabled = false;
            } else {
                throw new MediatorException("The feature must have value true or false");
            }
            addFeature(entry.getKey(), isFeatureEnabled);
        }
    }
View Full Code Here

        if (executor != null) {
            enqueue.addAttribute(fac.createOMAttribute(
                    "executor", nullNS, executor));
        } else {
            throw new MediatorException("executor not specified");
        }


        enqueue.addAttribute(fac.createOMAttribute(
                "priority", nullNS, Integer.toString(priority)));


        if (sequence != null) {
            enqueue.addAttribute(fac.createOMAttribute("sequence", nullNS, sequence));
        } else {
            throw new MediatorException("sequence not specified");
        }

        if (parent != null) {
            parent.addChild(enqueue);
        }
View Full Code Here

        OMAttribute executor = elem.getAttribute(new QName("executor"));

        if (sequence == null) {
            String msg = "The 'sequence' attribute is required for the " +
                    "configuration of a enqueue mediator";
            throw new MediatorException(msg);
        }
        this.sequence = sequence.getAttributeValue();

        if (priority == null) {
            String msg = "The 'priority' attribute is required for the " +
                    "configuration of a enqueue mediator";
            throw new MediatorException(msg);
        }
        this.priority = Integer.parseInt(priority.getAttributeValue());

        if (executor == null) {
            String msg = "The 'executor' attribute is required for the " +
                    "configuration of a enqueue mediator";
            throw new MediatorException(msg);
        }
        this.executor = executor.getAttributeValue();

        // after successfully creating the mediator
        // set its common attributes such as tracing etc
View Full Code Here

            } else if ("TIME".equals(type)) {
                this.type = Types.TIME;
             } else if ("TIMESTAMP".equals(type)) {
                this.type = Types.TIMESTAMP;
            } else {
                throw new MediatorException("Unknown or unsupported JDBC type : " + type);
            }
        }
View Full Code Here

                    key = keyFactory.createValue(XMLConfigConstants.KEY, elem);

                    if (e != null) {
                        String msg = "A sequence mediator with a reference to another " +
                                "sequence can not have 'ErrorHandler'";
                        throw new MediatorException(msg);
                    }
                } else {
                    String msg = "A sequence mediator should be a named sequence or a reference " +
                            "to another sequence (i.e. a name attribute or key attribute is required)";
                    throw new MediatorException(msg);
                }
            }
        } else {
            if (e != null) {
                errorHandler = e.getAttributeValue();
View Full Code Here

        for (MediatorProperty mp : props) {
            OMElement prop = fac.createOMElement(childElementName, parent);
            if (mp.getName() != null) {
                prop.addAttribute(fac.createOMAttribute("name", nullNS, mp.getName()));
            } else {
                throw new MediatorException("Mediator property name missing");
            }

            if (mp.getValue() != null) {
                prop.addAttribute(fac.createOMAttribute("value", nullNS, mp.getValue()));

            } else if (mp.getExpression() != null) {
                SynapseXPathSerializer.serializeXPath(mp.getExpression(), prop, "expression");
            } else {
                throw new MediatorException("Mediator property must have a " +
                        "literal value or be an expression");
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.mediator.service.MediatorException

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.