use of org.apache.synapse.mediators.eip.aggregator.AggregateMediator in project wso2-synapse by wso2.
the class MediatorTreeTraverseUtil method getMediatorReference.
/**
* Returns mediator referece associated with position while traversing the mediator tree.
*
* @param synCfg synapse configuration reference
* @param seqMediator sequence mediator which traverse happens
* @param position array of tree nodes specifying position integer with respect to it's parent node
* starting from the root parent.
* @return Mediator reference
*/
public static Mediator getMediatorReference(SynapseConfiguration synCfg, Mediator seqMediator, int[] position) {
Mediator current_mediator = null;
for (int counter = 0; counter < position.length; counter++) {
if (counter == 0) {
int mediatorCount = ((AbstractListMediator) seqMediator).getList().size();
int correctedPosition = getCorrectedPossition((AbstractListMediator) seqMediator, position[counter]);
if (mediatorCount > correctedPosition) {
current_mediator = ((AbstractListMediator) seqMediator).getChild(correctedPosition);
} else {
log.warn("Mediator position requested is larger than last index : " + position[counter]);
}
}
if (current_mediator != null && counter != 0) {
if (current_mediator instanceof InvokeMediator) {
current_mediator = synCfg.getSequenceTemplate(((InvokeMediator) current_mediator).getTargetTemplate());
} else if (current_mediator instanceof FilterMediator) {
if (position[counter] == 0) {
if (((FilterMediator) current_mediator).getElseMediator() != null) {
current_mediator = ((FilterMediator) current_mediator).getElseMediator();
} else if (((FilterMediator) current_mediator).getElseKey() != null) {
current_mediator = synCfg.getSequence(((FilterMediator) current_mediator).getElseKey());
}
continue;
} else if (position[counter] == 1) {
if (((FilterMediator) current_mediator).getThenKey() != null) {
current_mediator = synCfg.getSequence(((FilterMediator) current_mediator).getThenKey());
} else {
counter = counter + 1;
if (counter < position.length) {
int mediatorCount = ((AbstractListMediator) current_mediator).getList().size();
int correctedPosition = getCorrectedPossition((AbstractListMediator) current_mediator, position[counter]);
if (mediatorCount > correctedPosition) {
current_mediator = ((AbstractListMediator) current_mediator).getChild(correctedPosition);
} else {
log.warn("Mediator position requested is larger than last index : " + position[counter]);
}
}
}
continue;
}
} else if (current_mediator instanceof SwitchMediator) {
if (position[counter] == 0) {
SwitchCase switchCase = ((SwitchMediator) current_mediator).getDefaultCase();
if (switchCase != null) {
current_mediator = switchCase.getCaseMediator();
} else {
current_mediator = null;
}
} else {
SwitchCase switchCase = ((SwitchMediator) current_mediator).getCases().get(position[counter] - 1);
if (switchCase != null) {
current_mediator = switchCase.getCaseMediator();
} else {
current_mediator = null;
}
}
continue;
} else if (current_mediator instanceof AggregateMediator) {
if (((AggregateMediator) current_mediator).getOnCompleteSequence() != null) {
current_mediator = ((AggregateMediator) current_mediator).getOnCompleteSequence();
} else if (((AggregateMediator) current_mediator).getOnCompleteSequenceRef() != null) {
current_mediator = synCfg.getSequence(((AggregateMediator) current_mediator).getOnCompleteSequenceRef());
}
} else if (current_mediator instanceof ForEachMediator) {
if (((ForEachMediator) current_mediator).getSequence() != null) {
current_mediator = ((ForEachMediator) current_mediator).getSequence();
} else if (((ForEachMediator) current_mediator).getSequenceRef() != null) {
current_mediator = synCfg.getSequence(((ForEachMediator) current_mediator).getSequenceRef());
}
} else if (current_mediator instanceof IterateMediator) {
if (((IterateMediator) current_mediator).getTarget().getSequence() != null) {
current_mediator = ((IterateMediator) current_mediator).getTarget().getSequence();
} else if (((IterateMediator) current_mediator).getTarget().getSequenceRef() != null) {
current_mediator = synCfg.getSequence(((IterateMediator) current_mediator).getTarget().getSequenceRef());
}
} else if (current_mediator instanceof CloneMediator) {
if (((CloneMediator) current_mediator).getTargets().get(position[counter]).getSequence() != null) {
current_mediator = ((CloneMediator) current_mediator).getTargets().get(position[counter]).getSequence();
} else if (((CloneMediator) current_mediator).getTargets().get(position[counter]).getSequenceRef() != null) {
current_mediator = synCfg.getSequence(((CloneMediator) current_mediator).getTargets().get(position[counter]).getSequenceRef());
}
continue;
} else if (current_mediator.getType().equals("ThrottleMediator")) {
current_mediator = ((EnclosedInlinedSequence) current_mediator).getInlineSequence(synCfg, position[counter]);
continue;
} else if (current_mediator.getType().equals("EntitlementMediator")) {
current_mediator = ((EnclosedInlinedSequence) current_mediator).getInlineSequence(synCfg, position[counter]);
continue;
} else if (current_mediator.getType().equals("CacheMediator")) {
current_mediator = ((EnclosedInlinedSequence) current_mediator).getInlineSequence(synCfg, 0);
}
if (current_mediator != null && (current_mediator instanceof AbstractListMediator)) {
int mediatorCount = ((AbstractListMediator) current_mediator).getList().size();
int correctedPosition = getCorrectedPossition((AbstractListMediator) current_mediator, position[counter]);
if (mediatorCount > correctedPosition) {
current_mediator = ((AbstractListMediator) current_mediator).getChild(correctedPosition);
} else {
log.warn("Mediator position requested is larger than last index : " + position[counter]);
}
} else {
current_mediator = null;
break;
}
}
}
return current_mediator;
}
use of org.apache.synapse.mediators.eip.aggregator.AggregateMediator in project wso2-synapse by wso2.
the class AggregateMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
AggregateMediator mediator = new AggregateMediator();
processAuditStatus(mediator, elem);
OMAttribute id = elem.getAttribute(ID_Q);
if (id != null) {
mediator.setId(id.getAttributeValue());
}
OMElement corelateOn = elem.getFirstChildWithName(CORELATE_ON_Q);
if (corelateOn != null) {
OMAttribute corelateExpr = corelateOn.getAttribute(EXPRESSION_Q);
if (corelateExpr != null) {
try {
mediator.setCorrelateExpression(SynapseXPathFactory.getSynapseXPath(corelateOn, EXPRESSION_Q));
} catch (JaxenException e) {
handleException("Unable to load the corelate XPATH expression", e);
}
}
}
OMElement completeCond = elem.getFirstChildWithName(COMPLETE_CONDITION_Q);
if (completeCond != null) {
OMAttribute completeTimeout = completeCond.getAttribute(TIMEOUT_Q);
if (completeTimeout != null) {
mediator.setCompletionTimeoutMillis(Long.parseLong(completeTimeout.getAttributeValue()) * 1000);
}
OMElement messageCount = completeCond.getFirstChildWithName(MESSAGE_COUNT_Q);
if (messageCount != null) {
OMAttribute min = messageCount.getAttribute(MIN_Q);
if (min != null) {
mediator.setMinMessagesToComplete(new ValueFactory().createValue("min", messageCount));
}
OMAttribute max = messageCount.getAttribute(MAX_Q);
if (max != null) {
mediator.setMaxMessagesToComplete(new ValueFactory().createValue("max", messageCount));
}
}
}
OMElement onComplete = elem.getFirstChildWithName(ON_COMPLETE_Q);
if (onComplete != null) {
OMAttribute aggregateExpr = onComplete.getAttribute(EXPRESSION_Q);
if (aggregateExpr != null) {
try {
mediator.setAggregationExpression(SynapseXPathFactory.getSynapseXPath(onComplete, EXPRESSION_Q));
} catch (JaxenException e) {
handleException("Unable to load the aggregating XPATH", e);
}
}
OMAttribute enclosingElementPropertyName = onComplete.getAttribute(ENCLOSING_ELEMENT_PROPERTY);
if (enclosingElementPropertyName != null) {
mediator.setEnclosingElementPropertyName(enclosingElementPropertyName.getAttributeValue());
}
OMAttribute onCompleteSequence = onComplete.getAttribute(SEQUENCE_Q);
if (onCompleteSequence != null) {
mediator.setOnCompleteSequenceRef(onCompleteSequence.getAttributeValue());
} else if (onComplete.getFirstElement() != null) {
mediator.setOnCompleteSequence((new SequenceMediatorFactory()).createAnonymousSequence(onComplete, properties));
} else {
SequenceMediator sequence = new SequenceMediator();
sequence.addChild(new DropMediator());
mediator.setOnCompleteSequence(sequence);
}
}
addAllCommentChildrenToList(elem, mediator.getCommentsList());
return mediator;
}
use of org.apache.synapse.mediators.eip.aggregator.AggregateMediator in project wso2-synapse by wso2.
the class AggregateMediatorSerializer method serializeSpecificMediator.
public OMElement serializeSpecificMediator(Mediator m) {
AggregateMediator mediator = null;
if (!(m instanceof AggregateMediator)) {
handleException("Unsupported mediator passed in for serialization : " + m.getType());
} else {
mediator = (AggregateMediator) m;
}
assert mediator != null;
OMElement aggregator = fac.createOMElement("aggregate", synNS);
saveTracingState(aggregator, mediator);
if (mediator.getId() != null) {
aggregator.addAttribute("id", mediator.getId(), nullNS);
}
if (mediator.getCorrelateExpression() != null) {
OMElement corelateOn = fac.createOMElement("correlateOn", synNS);
SynapseXPathSerializer.serializeXPath(mediator.getCorrelateExpression(), corelateOn, "expression");
aggregator.addChild(corelateOn);
}
OMElement completeCond = fac.createOMElement("completeCondition", synNS);
if (mediator.getCompletionTimeoutMillis() != 0) {
completeCond.addAttribute("timeout", Long.toString(mediator.getCompletionTimeoutMillis() / 1000), nullNS);
}
OMElement messageCount = fac.createOMElement("messageCount", synNS);
if (mediator.getMinMessagesToComplete() != null) {
new ValueSerializer().serializeValue(mediator.getMinMessagesToComplete(), "min", messageCount);
}
if (mediator.getMaxMessagesToComplete() != null) {
new ValueSerializer().serializeValue(mediator.getMaxMessagesToComplete(), "max", messageCount);
}
completeCond.addChild(messageCount);
aggregator.addChild(completeCond);
OMElement onCompleteElem = fac.createOMElement("onComplete", synNS);
if (mediator.getAggregationExpression() != null) {
SynapseXPathSerializer.serializeXPath(mediator.getAggregationExpression(), onCompleteElem, "expression");
}
if (mediator.getOnCompleteSequenceRef() != null) {
onCompleteElem.addAttribute("sequence", mediator.getOnCompleteSequenceRef(), nullNS);
} else if (mediator.getOnCompleteSequence() != null) {
new SequenceMediatorSerializer().serializeChildren(onCompleteElem, mediator.getOnCompleteSequence().getList());
}
String enclosingElementPropertyName = mediator.getEnclosingElementPropertyName();
if (enclosingElementPropertyName != null) {
onCompleteElem.addAttribute("enclosingElementProperty", enclosingElementPropertyName, nullNS);
}
aggregator.addChild(onCompleteElem);
serializeComments(aggregator, mediator.getCommentsList());
return aggregator;
}
Aggregations