private static final QName EP_URI_QNAME = new QName("uri");
@SuppressWarnings({"UnusedDeclaration"})
public static SynapseEventSource createEventSource(OMElement elem, Properties properties) {
SynapseEventSource eventSource = null;
OMAttribute name = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name == null) {
handleException("The 'name' attribute is required for a event source de");
} else {
eventSource = new SynapseEventSource(name.getAttributeValue());
}
OMElement subscriptionManagerElem = elem.getFirstChildWithName(SUBSCRIPTION_MANAGER_QNAME);
if (eventSource != null && subscriptionManagerElem != null) {
OMAttribute clazz = subscriptionManagerElem
.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "class"));
if (clazz != null) {
String className = clazz.getAttributeValue();
try {
Class subscriptionManagerClass = Class.forName(className);
SubscriptionManager manager =
(SubscriptionManager) subscriptionManagerClass.newInstance();
Iterator itr = subscriptionManagerElem.getChildrenWithName(PROPERTIES_QNAME);
while (itr.hasNext()) {
OMElement propElem = (OMElement) itr.next();
String propName =
propElem.getAttribute(new QName("name")).getAttributeValue();
String propValue =
propElem.getAttribute(new QName("value")).getAttributeValue();
if (propName != null && !"".equals(propName.trim()) &&
propValue != null && !"".equals(propValue.trim())) {
propName = propName.trim();
propValue = propValue.trim();
PasswordManager passwordManager =
PasswordManager.getInstance();
String key = eventSource.getName() + "." + propName;
if (passwordManager.isInitialized()
&& passwordManager.isTokenProtected(key)) {
eventSource.putConfigurationProperty(propName, propValue);
propValue = passwordManager.resolve(propValue);
}
manager.addProperty(propName, propValue);
}
}
eventSource.setSubscriptionManager(manager);
eventSource.getSubscriptionManager()
.init(); // Initialise before doing further processing, required for static subscriptions
} catch (ClassNotFoundException e) {
handleException("SubscriptionManager class not found", e);
} catch (IllegalAccessException e) {
handleException("Unable to access the SubscriptionManager object", e);