in core/src/main/java/flex/messaging/config/ServerConfigurationParser.java [663:786]
private void service(Node service) {
// Validation
requiredAttributesOrElements(service, SERVICE_REQ_CHILDREN);
allowedAttributesOrElements(service, SERVICE_CHILDREN);
String id = getAttributeOrChildElement(service, ID_ATTR);
if (isValidID(id)) {
ServiceSettings serviceSettings = config.getServiceSettings(id);
if (serviceSettings == null) {
serviceSettings = new ServiceSettings(id);
serviceSettings.setSourceFile(getSourceFileOf(service));
config.addServiceSettings(serviceSettings);
} else {
// Duplicate service definition '{0}'.
ConfigurationException e = new ConfigurationException();
e.setMessage(DUPLICATE_SERVICE_ERROR, new Object[]{id});
throw e;
}
// Service Class Name
String className = getAttributeOrChildElement(service, CLASS_ATTR);
if (className.length() > 0) {
serviceSettings.setClassName(className);
// Sniff for AdvancedMessagingSupport.
if (className.equals("flex.messaging.services.AdvancedMessagingSupport"))
advancedMessagingSupportRegistered = true;
} else {
// Class not specified for {SERVICE_ELEMENT} '{id}'.
ConfigurationException ex = new ConfigurationException();
ex.setMessage(CLASS_NOT_SPECIFIED, new Object[]{SERVICE_ELEMENT, id});
throw ex;
}
// Service Message Types - deprecated
// Service Properties
NodeList properties = selectNodeList(service, PROPERTIES_ELEMENT + "/*");
if (properties.getLength() > 0) {
ConfigMap map = properties(properties, getSourceFileOf(service));
serviceSettings.addProperties(map);
}
// Default Channels
Node defaultChannels = selectSingleNode(service, DEFAULT_CHANNELS_ELEMENT);
if (defaultChannels != null) {
allowedChildElements(defaultChannels, DEFAULT_CHANNELS_CHILDREN);
NodeList channels = selectNodeList(defaultChannels, CHANNEL_ELEMENT);
for (int c = 0; c < channels.getLength(); c++) {
Node chan = channels.item(c);
allowedAttributes(chan, new String[]{REF_ATTR});
defaultChannel(chan, serviceSettings);
}
}
// Fall back on application's default channels
else if (config.getDefaultChannels().size() > 0) {
for (Object o : config.getDefaultChannels()) {
String channelId = (String) o;
ChannelSettings channel = config.getChannelSettings(channelId);
serviceSettings.addDefaultChannel(channel);
}
}
// Default Security Constraint
Node defaultSecurityConstraint = selectSingleNode(service, DEFAULT_SECURITY_CONSTRAINT_ELEMENT);
if (defaultSecurityConstraint != null) {
// Validation
requiredAttributesOrElements(defaultSecurityConstraint, new String[]{REF_ATTR});
allowedAttributesOrElements(defaultSecurityConstraint, new String[]{REF_ATTR});
String ref = getAttributeOrChildElement(defaultSecurityConstraint, REF_ATTR);
if (ref.length() > 0) {
SecurityConstraint sc = ((MessagingConfiguration) config).getSecuritySettings().getConstraint(ref);
if (sc == null) {
// {SECURITY_CONSTRAINT_DEFINITION_ELEMENT} not found for reference '{ref}'.
ConfigurationException e = new ConfigurationException();
e.setMessage(REF_NOT_FOUND, new Object[]{SECURITY_CONSTRAINT_DEFINITION_ELEMENT, ref});
throw e;
}
serviceSettings.setConstraint(sc);
} else {
//Invalid default-security-constraint reference ''{0}'' in service ''{1}''.
ConfigurationException ex = new ConfigurationException();
ex.setMessage(INVALID_SECURITY_CONSTRAINT_REF, new Object[]{ref, id});
throw ex;
}
}
// Adapter Definitions
Node adapters = selectSingleNode(service, ADAPTERS_ELEMENT);
if (adapters != null) {
allowedChildElements(adapters, ADAPTERS_CHILDREN);
NodeList serverAdapters = selectNodeList(adapters, ADAPTER_DEFINITION_ELEMENT);
for (int a = 0; a < serverAdapters.getLength(); a++) {
Node adapter = serverAdapters.item(a);
adapterDefinition(adapter, serviceSettings);
}
NodeList adapterIncludes = selectNodeList(adapters, ADAPTER_INCLUDE_ELEMENT);
for (int a = 0; a < adapterIncludes.getLength(); a++) {
Node include = adapterIncludes.item(a);
adapterInclude(include, serviceSettings);
}
}
// Destinations
NodeList list = selectNodeList(service, DESTINATION_ELEMENT);
for (int i = 0; i < list.getLength(); i++) {
Node dest = list.item(i);
destination(dest, serviceSettings);
}
// Destination Includes
list = selectNodeList(service, DESTINATION_INCLUDE_ELEMENT);
for (int i = 0; i < list.getLength(); i++) {
Node dest = list.item(i);
destinationInclude(dest, serviceSettings);
}
} else {
//Invalid {SERVICE_ELEMENT} id '{id}'.
ConfigurationException ex = new ConfigurationException();
ex.setMessage(INVALID_ID, new Object[]{SERVICE_ELEMENT, id});
throw ex;
}
}