Package org.apache.synapse.mediators

Examples of org.apache.synapse.mediators.MediatorProperty


    private static String buildPropertyString(AbstractEndpoint ep) {

        Iterator<MediatorProperty> itr = ep.getProperties().iterator();
        String ret = "";
        while (itr.hasNext()) {
            MediatorProperty prop = itr.next();
            if (ret.equals("")) {
                ret = prop.getName() + "," + prop.getValue() + "," + prop.getScope();
            } else {
                ret = ret + "::" + prop.getName() + "," + prop.getValue() + "," + prop.getScope();
            }
        }
        return ret;
    }
View Full Code Here


            return "";
        }
        Iterator<MediatorProperty> itr = props.iterator();
        String ret = "";
        while (itr.hasNext()) {
            MediatorProperty prop = itr.next();
            if (ret.equals("")) {
                ret = prop.getName() + "," + prop.getValue() + "," + prop.getScope();
            } else {
                ret = ret + "::" + prop.getName() + "," + prop.getValue() + "," + prop.getScope();
            }
        }
        return ret;
    }
View Full Code Here

        assertTrue(ClassMediatorTestMediator.invoked);
    }

    public void testCreationWithLiteralProperties() throws Exception {
        ClassMediator cm = new ClassMediator();
        MediatorProperty mp = new MediatorProperty();
        mp.setName("testProp");
        mp.setValue("testValue");
        cm.addProperty(mp);
        cm.setClazz(ClassMediatorTestMediator.class);
        cm.mediate(new TestMessageContext());
        assertTrue(ClassMediatorTestMediator.testProp.equals("testValue"));
    }
View Full Code Here

        assertTrue(ClassMediatorTestMediator.testProp.equals("testValue"));
    }

    public void testCreationWithXPathProperties() throws Exception {
        ClassMediator cm = new ClassMediator();
        MediatorProperty mp = new MediatorProperty();
        mp.setName("testProp");
        mp.setExpression(new AXIOMXPath("concat('XPath ','is ','FUN!')"));
        cm.addProperty(mp);
        cm.setClazz(ClassMediatorTestMediator.class);
        cm.mediate(new TestMessageContext());
        assertTrue(ClassMediatorTestMediator.testProp.equals("XPath is FUN!"));
    }
View Full Code Here

            OMElement propEle = (OMElement) iter.next();
            OMAttribute attName  = propEle.getAttribute(MediatorProperty.ATT_NAME_Q);
            OMAttribute attValue = propEle.getAttribute(MediatorProperty.ATT_VALUE_Q);
            OMAttribute attExpr  = propEle.getAttribute(MediatorProperty.ATT_EXPR_Q);

            MediatorProperty prop = new MediatorProperty();

            if (attName == null || attName.getAttributeValue() == null ||
                attName.getAttributeValue().trim().length() == 0) {
                String msg = "Entry name is a required attribute for a Log property";
                log.error(msg);
                throw new SynapseException(msg);
            } else {
                prop.setName(attName.getAttributeValue());
            }

            // if a value is specified, use it, else look for an expression
            if (attValue != null) {
                if (attValue.getAttributeValue() == null || attValue.getAttributeValue().trim().length() == 0) {
                    String msg = "Entry attribute value (if specified) is required for a Log property";
                    log.error(msg);
                    throw new SynapseException(msg);
                } else {
                    prop.setValue(attValue.getAttributeValue());
                }

            } else if (attExpr != null) {

                if (attExpr.getAttributeValue() == null || attExpr.getAttributeValue().trim().length() == 0) {
                    String msg = "Entry attribute expression (if specified) is required for a mediator property";
                    log.error(msg);
                    throw new SynapseException(msg);

                } else {
                    try {
                        AXIOMXPath xp = new AXIOMXPath(attExpr.getAttributeValue());
                        OMElementUtils.addNameSpaces(xp, propEle, log);
                        prop.setExpression(xp);

                    } catch (JaxenException e) {
                        String msg = "Invalid XPapth expression : " + attExpr.getAttributeValue();
                        log.error(msg);
                        throw new SynapseException(msg, e);
View Full Code Here

    public void serializeMediatorProperties(OMElement parent, Collection props) {

        Iterator iter = props.iterator();
        while (iter.hasNext()) {
            MediatorProperty mp = (MediatorProperty) iter.next();
            OMElement prop = fac.createOMElement("property", synNS, parent);
            if (mp.getName() != null) {
                prop.addAttribute(fac.createOMAttribute("name", nullNS, mp.getName()));
            } else {
                handleException("Mediator property name missing");
            }

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

            } else if (mp.getExpression() != null) {
                prop.addAttribute(fac.createOMAttribute("expression", nullNS,
                    mp.getExpression().toString()));
                serializeNamespaces(prop, mp.getExpression());

            } else {
                handleException("Mediator property must have a literal value or be an expression");
            }
        }
View Full Code Here

            factory.setErrorHandler(errorHandler);

            // set any features on/off as requested
            iter = properties.iterator();
            while (iter.hasNext()) {
                MediatorProperty prop = (MediatorProperty) iter.next();
                factory.setFeature(
                    prop.getName(), prop.getValue() != null && "true".equals(prop.getValue()));
            }

            Schema schema = null;

            StreamSource[] sources = new StreamSource[schemaKeys.size()];
View Full Code Here

     * @return property string value (usually true|false)
     */
    public Object getProperty(String key) {
        Iterator iter = properties.iterator();
        while (iter.hasNext()) {
            MediatorProperty prop = (MediatorProperty) iter.next();
            if (key.equals(prop.getName())) {
                return prop.getValue();
            }
        }
        return null;
    }
View Full Code Here

     * @param key   the property key / feature name
     * @param value property string value (usually true|false)
     * @see #getProperty(String)
     */
    public void setProperty(String key, Object value) {
        MediatorProperty prop = new MediatorProperty();
        prop.setName(key);
        prop.setValue(value.toString());
        properties.add(prop);
    }
View Full Code Here

    public void addAllProperties(List list) {
        Iterator iter = list.iterator();
        while (iter.hasNext()) {
            Object o = iter.next();
            if (o instanceof MediatorProperty) {
                MediatorProperty prop = (MediatorProperty) o;
                setProperty(prop.getName(), prop.getValue());
            } else {
                handleException("Attempt to set invalid property type. " +
                    "Expected MediatorProperty type got " + o.getClass().getName());
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.synapse.mediators.MediatorProperty

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.