}
SynapseConfiguration config = new SynapseConfiguration();
config.setDefaultQName(definitions.getQName());
SequenceMediator rootSequence = new SequenceMediator();
rootSequence.setName(org.apache.synapse.SynapseConstants.MAIN_SEQUENCE_KEY);
Iterator iter = definitions.getChildren();
while (iter.hasNext()) {
Object o = iter.next();
if (o instanceof OMElement) {
OMElement elt = (OMElement) o;
if (XMLConfigConstants.SEQUENCE_ELT.equals(elt.getQName())) {
String key = elt.getAttributeValue(
new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
// this could be a sequence def or a mediator of the main sequence
if (key != null) {
Mediator m = MediatorFactoryFinder.getInstance().getMediator(elt);
rootSequence.addChild(m);
} else {
defineSequence(config, elt);
}
} else if (XMLConfigConstants.ENDPOINT_ELT.equals(elt.getQName())) {
defineEndpoint(config, elt);
} else if (XMLConfigConstants.ENTRY_ELT.equals(elt.getQName())) {
defineEntry(config, elt);
} else if (XMLConfigConstants.PROXY_ELT.equals(elt.getQName())) {
defineProxy(config, elt);
} else if (XMLConfigConstants.REGISTRY_ELT.equals(elt.getQName())) {
defineRegistry(config, elt);
} else if (XMLConfigConstants.TASK_ELT.equals(elt.getQName())) {
defineStartup(config, elt);
} else {
Mediator m = MediatorFactoryFinder.getInstance().getMediator(elt);
rootSequence.addChild(m);
}
}
}
if (config.getLocalRegistry().isEmpty() && config.getProxyServices().isEmpty() &&
rootSequence.getList().isEmpty() && config.getRegistry() != null) {
OMNode remoteConfigNode = config.getRegistry().lookup("synapse.xml");
try {
config = XMLConfigurationBuilder.getConfiguration(SynapseConfigUtils
.getStreamSource(remoteConfigNode).getInputStream());
} catch (XMLStreamException xse) {
throw new SynapseException("Problem loading remote synapse.xml ", xse);
}
}
// if there is no sequence named main defined locally look for the set of mediators in
// the root level before trying to look in the registry (hence config.getMainSequence
// can not be used here)
if (!config.getLocalRegistry().containsKey(SynapseConstants.MAIN_SEQUENCE_KEY)) {
// if the root tag does not contain any mediators & registry does not have a
// entry with key main then use the defualt main sequence
if (rootSequence.getList().isEmpty() && config.getMainSequence() == null) {
setDefaultMainSequence(config);
} else {
config.addSequence(rootSequence.getName(), rootSequence);
}
} else if (!rootSequence.getList().isEmpty()) {
handleException("Invalid Synapse Configuration : Conflict in resolving the \"main\" " +
"mediator\n\tSynapse Configuration cannot have sequence named \"main\" and " +
"toplevel mediators simultaniously");
}