Search in sources :

Example 1 with CommentMediator

use of org.apache.synapse.mediators.builtin.CommentMediator in project wso2-synapse by wso2.

the class AbstractMediatorSerializer method serializeMediator.

/**
 * Serializes the given mediator into XML element. This method handles
 * adding the common information from the respective mediators to the element it get by
 * delegating the mediator specific serialization to the
 * {@link #serializeSpecificMediator(org.apache.synapse.Mediator)} method, which has tobe
 * implemented by the respective mediators</p>
 *
 * <p>It is treating the {@link org.apache.synapse.config.xml.AnonymousListMediator} as a
 * special case and calls it's children serialization, since there is nothing specific to be
 * serialized in that case</p>
 *
 * <p>This method has been marked as <code>final</code> to avoid mistakenly overwriting
 * this method instead of the {@link #serializeSpecificMediator(org.apache.synapse.Mediator)}
 * by the sub classes
 *
 * @param parent the OMElement to which the serialization should be attached
 * @param m mediator to be serialized
 * @return the serialized Element
 */
public final OMElement serializeMediator(OMElement parent, Mediator m) {
    OMElement serializedElement = null;
    if (m instanceof AnonymousListMediator) {
        ((AnonymousListMediatorSerializer) this).serializeChildren(parent, ((AnonymousListMediator) m).getList());
        serializedElement = parent;
    } else if (m instanceof CommentMediator) {
        // serialize comment mediator
        serializedElement = serializeComments(parent, m);
    } else {
        // delegate the specific serializations to it's serializer
        OMElement elem = serializeSpecificMediator(m);
        if (m.getDescription() != null) {
            OMElement descriptionElem = fac.createOMElement(DESCRIPTION_Q, elem);
            descriptionElem.setText(m.getDescription());
            elem.addChild(descriptionElem);
        }
        if (m.getShortDescription() != null) {
            elem.addAttribute(fac.createOMAttribute("description", nullNS, m.getShortDescription()));
        }
        // attach the serialized element to the parent
        if (parent != null) {
            parent.addChild(elem);
        }
        serializedElement = elem;
    }
    return serializedElement;
}
Also used : OMElement(org.apache.axiom.om.OMElement) CommentMediator(org.apache.synapse.mediators.builtin.CommentMediator)

Example 2 with CommentMediator

use of org.apache.synapse.mediators.builtin.CommentMediator in project wso2-synapse by wso2.

the class AbstractListMediatorFactory method addChildren.

protected static void addChildren(OMElement el, ListMediator m, Properties properties) {
    Iterator it = el.getChildren();
    while (it.hasNext()) {
        OMNode child = (OMNode) it.next();
        if (child instanceof OMElement) {
            if (!DESCRIPTION_Q.equals(((OMElement) child).getQName())) {
                // neglect the description tag
                SynapseConfiguration configuration = null;
                if (properties != null) {
                    configuration = properties.get(SynapseConstants.SYNAPSE_CONFIGURATION) != null ? (SynapseConfiguration) properties.get(SynapseConstants.SYNAPSE_CONFIGURATION) : null;
                }
                Mediator med = MediatorFactoryFinder.getInstance().getMediator((OMElement) child, properties, configuration);
                if (med != null) {
                    m.addChild(med);
                } else {
                    String msg = "Unknown mediator : " + ((OMElement) child).getLocalName();
                    log.error(msg);
                    throw new SynapseException(msg);
                }
            }
        } else if (child instanceof OMComment) {
            CommentMediator commendMediator = new CommentMediator();
            commendMediator.setCommentText(((OMComment) child).getValue());
            m.addChild(commendMediator);
        }
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) SynapseException(org.apache.synapse.SynapseException) OMComment(org.apache.axiom.om.OMComment) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) Mediator(org.apache.synapse.Mediator) ListMediator(org.apache.synapse.mediators.ListMediator) CommentMediator(org.apache.synapse.mediators.builtin.CommentMediator) CommentMediator(org.apache.synapse.mediators.builtin.CommentMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 3 with CommentMediator

use of org.apache.synapse.mediators.builtin.CommentMediator in project wso2-synapse by wso2.

the class AbstractListMediatorFactory method addAllCommentChildrenToMediator.

/**
 * Find and add all comment nodes to the parent mediator as Comment Mediators
 *
 * @param el OMElement to extract OMComment Nodes
 * @param m  Mediator to be updated with extracted OMComment nodes
 */
protected static void addAllCommentChildrenToMediator(OMElement el, ListMediator m) {
    Iterator it = el.getChildren();
    while (it.hasNext()) {
        OMNode child = (OMNode) it.next();
        if (child instanceof OMComment) {
            CommentMediator commendMediator = new CommentMediator();
            commendMediator.setCommentText(((OMComment) child).getValue());
            m.addChild(commendMediator);
        }
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMComment(org.apache.axiom.om.OMComment) Iterator(java.util.Iterator) CommentMediator(org.apache.synapse.mediators.builtin.CommentMediator)

Example 4 with CommentMediator

use of org.apache.synapse.mediators.builtin.CommentMediator in project wso2-synapse by wso2.

the class CommentMediatorFactory method createSpecificMediator.

/**
 * Create Comment Mediator instance using provided XML Element and properties
 *
 * @param elem       configuration element describing the properties of the mediator
 * @param properties bag of properties to pass in any information to the factory
 *
 * @return CommentMediator instance created with the given comment text
 */
@Override
protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
    CommentMediator commentMediator = new CommentMediator();
    commentMediator.setCommentText(elem.getText());
    return commentMediator;
}
Also used : CommentMediator(org.apache.synapse.mediators.builtin.CommentMediator)

Example 5 with CommentMediator

use of org.apache.synapse.mediators.builtin.CommentMediator in project wso2-synapse by wso2.

the class MediatorTreeTraverseUtil method getCorrectedPossition.

/**
 * Developer Studio will send mediator positions without considering "Comment Mediators".
 * Due to that reason, if there are comments in the source view, mediator positions become incorrect.
 * This method will return the corrected mediator position considering "Comment Mediators" as well.
 *
 * @param seqMediator
 * @param position
 * @return correctedPossition considering comment mediators
 */
private static int getCorrectedPossition(AbstractListMediator seqMediator, int position) {
    int positionWithComments = 0;
    int positionWithoutComments = 0;
    for (Mediator mediator : seqMediator.getList()) {
        if (!(mediator instanceof CommentMediator)) {
            if (positionWithoutComments == position) {
                return positionWithComments;
            }
            ++positionWithoutComments;
        }
        ++positionWithComments;
    }
    return position;
}
Also used : SwitchMediator(org.apache.synapse.mediators.filters.SwitchMediator) InvokeMediator(org.apache.synapse.mediators.template.InvokeMediator) ForEachMediator(org.apache.synapse.mediators.builtin.ForEachMediator) IterateMediator(org.apache.synapse.mediators.eip.splitter.IterateMediator) CommentMediator(org.apache.synapse.mediators.builtin.CommentMediator) FilterMediator(org.apache.synapse.mediators.filters.FilterMediator) CloneMediator(org.apache.synapse.mediators.eip.splitter.CloneMediator) Mediator(org.apache.synapse.Mediator) AggregateMediator(org.apache.synapse.mediators.eip.aggregator.AggregateMediator) AbstractListMediator(org.apache.synapse.mediators.AbstractListMediator) CommentMediator(org.apache.synapse.mediators.builtin.CommentMediator)

Aggregations

CommentMediator (org.apache.synapse.mediators.builtin.CommentMediator)5 Iterator (java.util.Iterator)2 OMComment (org.apache.axiom.om.OMComment)2 OMElement (org.apache.axiom.om.OMElement)2 OMNode (org.apache.axiom.om.OMNode)2 Mediator (org.apache.synapse.Mediator)2 SynapseException (org.apache.synapse.SynapseException)1 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)1 AbstractListMediator (org.apache.synapse.mediators.AbstractListMediator)1 ListMediator (org.apache.synapse.mediators.ListMediator)1 ForEachMediator (org.apache.synapse.mediators.builtin.ForEachMediator)1 AggregateMediator (org.apache.synapse.mediators.eip.aggregator.AggregateMediator)1 CloneMediator (org.apache.synapse.mediators.eip.splitter.CloneMediator)1 IterateMediator (org.apache.synapse.mediators.eip.splitter.IterateMediator)1 FilterMediator (org.apache.synapse.mediators.filters.FilterMediator)1 SwitchMediator (org.apache.synapse.mediators.filters.SwitchMediator)1 InvokeMediator (org.apache.synapse.mediators.template.InvokeMediator)1