*/
public static OMElement serializeToServiceXML(ServiceDescription description,
OMElement parent, XPathSerializer xPathSerializer) {
OMElement serviceElement;
QNameFactory qNameFactory = QNameFactory.getInstance();
OMNamespaceFactory omNamespaceFactory = OMNamespaceFactory.getInstance();
OMElementHelper omElementHelper = OMElementHelper.getInstance();
if (parent != null) {
// removes existing rule config information in the service.xml
serviceElement = parent;
Iterator iterator = serviceElement.getChildElements();
while (iterator.hasNext()) {
Object o = iterator.next();
if (!(o instanceof OMElement)) {
continue;
}
OMElement child = (OMElement) o;
if (CommonsConstants.ELE_DESCRIPTION.equals(child.getLocalName())) {
omElementHelper.detachChildren(child);
String des = description.getDescription();
if (des != null && !"".equals(des.trim())) {
child.setText(des);
}
}
}
} else {
String name = description.getName();
if (name != null && !"".equals(name.trim())) {
serviceElement = OM_FACTORY.createOMElement(CommonsConstants.ELE_SERVICE,
omNamespaceFactory.createOMNamespace(new QName(name)));
serviceElement.addAttribute(OM_FACTORY.createOMAttribute("name", NULL_NS,
name.trim()));
} else {
throw new LoggedRuntimeException("Service name missing", log);
}
// set description
OMNamespace omNamespace = omNamespaceFactory.createOMNamespace(
serviceElement.getQName());
String des = description.getDescription();
if (des != null && !"".equals(des.trim())) {
OMElement desElement = OM_FACTORY.createOMElement(CommonsConstants.ELE_DESCRIPTION,
omNamespace);
desElement.setText(des.trim());
serviceElement.addChild(desElement);
}
}
// updating existing operations
final List<String> addedOpNames = new ArrayList<String>();
Iterator iterator = serviceElement.getChildrenWithName(
qNameFactory.createQName(CommonsConstants.ELE_OPERATION, serviceElement.getQName()));
while (iterator.hasNext()) {
Object o = iterator.next();
if (!(o instanceof OMElement)) {
continue;
}