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;
}
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);
}
}
}
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);
}
}
}
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;
}
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;
}
Aggregations