loadPart(element, definition);
definition.setVersion(XMLUtil.getStringAttr(element, "version", definition.getVersion()));
if (m_definitionMap.put(definition.getNamePrefix(), definition) != null)
{
throw new MetadataException("err.meta.soa.definitionDup",
new Object[] {definition.getName(), definition.getVersion(), definition.getNamePrefix()});
}
Element child = XMLUtil.findChildElement(element, "Types");
if (child != null)
{
XMLUtil.forEachChildElement(child, "Type", new XMLUtil.ElementHandler()
{
public void handleElement(Element typeElement)
{
final ModelType type = new ModelType(definition);
loadPart(typeElement, type);
if (!definition.addType(type))
{
throw new MetadataException("err.meta.soa.typeDup",
new Object[] {type.getName(), definition.getNamePrefix()});
}
m_globalMap.put(type.getGlobalName(), type);
String sBases = StringUtil.trimToNull(XMLUtil.getStringAttr(typeElement, "bases"));
if (sBases != null)
{
final String[] sBaseArray = SPACE_PATTERN.split(sBases);
m_resolutionFixupList.add(new ContextFixup(m_helper)
{
public void fixup()
{
for (int i = 0; i < sBaseArray.length; i++)
{
String sBaseTypeName = definition.resolveTypeRef(sBaseArray[i]);
ModelType baseType = (ModelType)m_globalMap.get(sBaseTypeName);
if (baseType == null)
{
throw new MetadataException("err.meta.soa.unknownType",
new Object[] {sBaseTypeName, type.getGlobalName(), definition.getNamePrefix()});
}
type.addBase(baseType);
}
}
});
}
Element attributesElement = XMLUtil.findChildElement(typeElement, "Attributes");
if (attributesElement != null)
{
XMLUtil.forEachChildElement(attributesElement, "Attribute", new XMLUtil.ElementHandler()
{
public void handleElement(Element attributeElement)
{
Attribute attribute = new Attribute();
loadPart(attributeElement, attribute);
attribute.setType(XMLUtil.getReqStringAttr(attributeElement, "type")); // TODO: Resolve later
attribute.setCollection(XMLUtil.getBooleanAttr(attributeElement, "collection", attribute.isCollection()));
attribute.setRequired(XMLUtil.getBooleanAttr(attributeElement, "required", attribute.isRequired()));
if (!type.addAttribute(attribute))
{
throw new MetadataException("err.meta.soa.attributeDup",
new Object[] {attribute.getName(), type.getName(), definition.getNamePrefix()});
}
}
});
}
}
});
}
child = XMLUtil.findChildElement(element, "Interfaces");
if (child != null)
{
XMLUtil.forEachChildElement(child, "Interface", new XMLUtil.ElementHandler()
{
public void handleElement(Element interfaceElement)
{
final Interface iface = new Interface(definition);
loadPart(interfaceElement, iface);
if (!definition.addInterface(iface))
{
throw new MetadataException("err.meta.soa.interfaceDup",
new Object[] {iface.getName(), definition.getNamePrefix()});
}
m_globalMap.put(iface.getGlobalName(), iface);
XMLUtil.forEachChildElement(interfaceElement, "Method", new XMLUtil.ElementHandler()
{
public void handleElement(Element methodElement)
{
final Method method = new Method();
loadPart(methodElement, method);
Element argumentsElement = XMLUtil.findChildElement(methodElement, "Arguments");
if (argumentsElement != null)
{
XMLUtil.forEachChildElement(argumentsElement, "Argument", new XMLUtil.ElementHandler()
{
public void handleElement(Element argumentElement)
{
Argument argument = new Argument();
loadPart(argumentElement, argument);
if (!method.addArgument(argument))
{
throw new MetadataException("err.meta.soa.argumentDup",
new Object[] {argument.getName(), method.getName(), iface.getName(), definition.getNamePrefix()});
}
argument.setType(XMLUtil.getReqStringAttr(argumentElement, "type")); // TODO: Resolve later
argument.setCollection(XMLUtil.getBooleanAttr(argumentElement, "collection", argument.isCollection()));
}
});
}
if (!iface.addMethod(method))
{
throw new MetadataException("err.meta.soa.methodDup",
new Object[] {method.getName(), method.getArgString(), iface.getName(), definition.getNamePrefix()});
}
Element resultElement = XMLUtil.findChildElement(methodElement, "Result");
if (resultElement != null)
{
Result result = new Result();
method.setResult(result);
result.setType(XMLUtil.getReqStringAttr(resultElement, "type")); // TODO: Resolve later
result.setCollection(XMLUtil.getBooleanAttr(resultElement, "collection", result.isCollection()));
result.setDescription(XMLUtil.getStringAttr(resultElement, "description", result.getDescription()));
}
Element faultsElement = XMLUtil.findChildElement(methodElement, "Faults");
if (faultsElement != null)
{
XMLUtil.forEachChildElement(faultsElement, "Fault", new XMLUtil.ElementHandler()
{
public void handleElement(Element faultElement)
{
Fault fault = new Fault();
fault.m_sRef = XMLUtil.getReqStringAttr(faultElement, "type"); // TODO: Resolve later
method.addFault(fault);
}
});
}
}
});
}
});
}
child = XMLUtil.findChildElement(element, "Services");
if (child != null)
{
XMLUtil.forEachChildElement(child, "Service", new XMLUtil.ElementHandler()
{
public void handleElement(Element serviceElement)
{
final Service service = new Service(definition);
loadPart(serviceElement, service);
if (!definition.addService(service))
{
throw new MetadataException("err.meta.soa.serviceDup",
new Object[] {service.getName(), definition.getNamePrefix()});
}
m_globalMap.put(service.getGlobalName(), service);
Element interfacesElement = XMLUtil.findChildElement(serviceElement, "Interfaces");
final int nCounter[] = {0};
XMLUtil.forEachChildElement(interfacesElement, "Interface", new XMLUtil.ElementHandler()
{
public void handleElement(Element interfaceElement)
{
final String sInterfaceName = definition.resolveInterfaceRef(XMLUtil.getReqStringAttr(interfaceElement, "ref"));
final InterfaceRef ref = new InterfaceRef();
ref.setDefault(XMLUtil.getBooleanAttr(interfaceElement, "default", ref.isDefault()));
service.addInterfaceRef(ref);
if (ref.isDefault())
{
nCounter[0]++;
}
m_resolutionFixupList.add(new ContextFixup(m_helper)
{
public void fixup()
{
Interface iface = (Interface)m_globalMap.get(sInterfaceName);
if (iface == null)
{
throw new MetadataException("err.meta.soa.unknownInterface",
new Object[] {sInterfaceName, service.getName(), definition.getNamePrefix()});
}
ref.setInterface(iface);
}
});
}
});
if (nCounter[0] == 0)
{
throw new MetadataException("err.meta.soa.missingDefaultInterface",
new Object[] {service.getName(), definition.getNamePrefix()});
}
else if (nCounter[0] >= 2)
{
throw new MetadataException("err.meta.soa.multipleDefaultInterface",
new Object[] {service.getName(), definition.getNamePrefix()});
}
}
});
}
child = XMLUtil.findChildElement(element, "Bindings");
XMLUtil.forEachChildElement(child, "Binding", new XMLUtil.ElementHandler()
{
public void handleElement(Element bindingElement)
{
String sBindingName = XMLUtil.getReqStringAttr(bindingElement, "protocol");
if (!definition.addBinding(sBindingName))
{
throw new MetadataException("err.meta.soa.bindingDup",
new Object[] {sBindingName, definition.getNamePrefix()});
}
}
});