public static OMElement serializeHandlerConfiguration(HandlerConfigurationBean bean) { OMFactory factory = OMAbstractFactory.getOMFactory(); OMElement handler = factory.createOMElement("handler", null); handler.addAttribute(factory.createOMAttribute("class", null, bean.getHandlerClass())); if (bean.getTenant() != null) { handler.addAttribute(factory.createOMAttribute("tenant", null, bean.getTenant())); } StringBuilder sb = new StringBuilder(); for (String method : bean.getMethods()) { if (method != null && method.length() > 0) { sb.append(method).append(","); } } // Remove last "," if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); handler.addAttribute(factory.createOMAttribute("methods", null, sb.toString())); } for (String property : bean.getPropertyList()) { OMElement temp = factory.createOMElement("property", null); temp.addAttribute(factory.createOMAttribute("name", null, property)); OMElement xmlProperty = bean.getXmlProperties().get(property); if (xmlProperty != null) { // The serialization happens by adding the whole XML property value to the // bean. // Therefore if it is a XML property, we take that whole element. handler.addChild(xmlProperty); } else { String nonXMLProperty = bean.getNonXmlProperties().get(property); if (nonXMLProperty != null) { temp.setText(nonXMLProperty); handler.addChild(temp); } } } OMElement filter = factory.createOMElement("filter", null); filter.addAttribute( factory.createOMAttribute("class", null, bean.getFilter().getFilterClass())); for (String property : bean.getFilter().getPropertyList()) { OMElement temp = factory.createOMElement("property", null); temp.addAttribute(factory.createOMAttribute("name", null, property)); OMElement xmlProperty = bean.getFilter().getXmlProperties().get(property); if (xmlProperty != null) { temp.addAttribute(factory.createOMAttribute("type", null, "xml")); temp.addChild(xmlProperty); filter.addChild(temp); } else { String nonXMLProperty = bean.getFilter().getNonXmlProperties().get(property); if (nonXMLProperty != null) { temp.setText(nonXMLProperty); filter.addChild(temp); } } } handler.addChild(filter); return handler; }
private OMElement getTextElement(String content) { OMFactory factory = OMAbstractFactory.getOMFactory(); OMElement textElement = factory.createOMElement(TEXT_ELEMENT); if (content == null) { content = ""; } textElement.setText(content); return textElement; }
public static OMElement addExtraElements(OMElement data, HttpServletRequest request) { OMFactory fac = OMAbstractFactory.getOMFactory(); // adding required fields at the top of the xml which will help to easily read in service side OMElement operation = fac.createOMElement("operation", null); OMElement currentName = fac.createOMElement("currentName", null); OMElement currentNamespace = fac.createOMElement("currentNamespace", null); String operationValue = request.getParameter("operation"); if (operationValue != null) { operation.setText(operationValue); data.addChild(operation); } String name = request.getParameter("currentname"); if (name != null) { currentName.setText(name); data.addChild(currentName); } String namespace = request.getParameter("currentnamespace"); if (namespace != null) { currentNamespace.setText(namespace); data.addChild(currentNamespace); } return data; }