use of org.apache.axiom.om.OMNamespace in project wso2-axis2-transports by wso2.
the class SimpleInOutMessageReceiver method invokeBusinessLogic.
public void invokeBusinessLogic(MessageContext inMessageContext, MessageContext outMessageContext) throws AxisFault {
log.debug("Got The message to the MessageReceiver");
String soapNamespace = inMessageContext.getEnvelope().getNamespace().getNamespaceURI();
// creating a soap factory according the the soap namespce uri
SOAPFactory soapFactory = null;
if (soapNamespace.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
soapFactory = OMAbstractFactory.getSOAP11Factory();
} else if (soapNamespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
soapFactory = OMAbstractFactory.getSOAP12Factory();
} else {
System.out.println("Unknow soap message");
}
SOAPEnvelope responseEnvelope = soapFactory.getDefaultEnvelope();
// creating a body element
OMFactory omFactory = OMAbstractFactory.getOMFactory();
OMNamespace omNamespace = omFactory.createOMNamespace("http://sms.test", "ns1");
OMElement omElement = omFactory.createOMElement("Response", omNamespace);
omElement.setText("Sucess");
responseEnvelope.getBody().addChild(omElement);
outMessageContext.setEnvelope(responseEnvelope);
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class OMFactoryImpl method importChildNode.
private AxiomChildNode importChildNode(OMNode child) {
int type = child.getType();
switch(type) {
case OMNode.ELEMENT_NODE:
{
OMElement element = (OMElement) child;
AxiomElement importedElement = createNode(AxiomElement.class);
copyName(element, importedElement);
for (Iterator<OMAttribute> it = element.getAllAttributes(); it.hasNext(); ) {
importedElement.coreAppendAttribute(importAttribute(it.next()));
}
for (Iterator<OMNamespace> it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
OMNamespace ns = it.next();
AxiomNamespaceDeclaration nsDecl = createNode(AxiomNamespaceDeclaration.class);
nsDecl.coreSetDeclaredNamespace(ns.getPrefix(), ns.getNamespaceURI());
importedElement.coreAppendAttribute(nsDecl);
}
importChildren(element, importedElement);
return importedElement;
}
case OMNode.TEXT_NODE:
case OMNode.SPACE_NODE:
case OMNode.CDATA_SECTION_NODE:
{
OMText text = (OMText) child;
Object content;
if (text.isBinary()) {
content = new TextContent(text.getContentID(), text.getDataHandler(), text.isOptimized());
} else {
content = text.getText();
}
return createAxiomText(null, content, type);
}
case OMNode.PI_NODE:
{
OMProcessingInstruction pi = (OMProcessingInstruction) child;
AxiomProcessingInstruction importedPI = createNode(AxiomProcessingInstruction.class);
importedPI.setTarget(pi.getTarget());
importedPI.setValue(pi.getValue());
return importedPI;
}
case OMNode.COMMENT_NODE:
{
OMComment comment = (OMComment) child;
AxiomComment importedComment = createNode(AxiomComment.class);
importedComment.setValue(comment.getValue());
return importedComment;
}
case OMNode.DTD_NODE:
{
OMDocType docType = (OMDocType) child;
AxiomDocType importedDocType = createNode(AxiomDocType.class);
importedDocType.coreSetRootName(docType.getRootName());
importedDocType.coreSetPublicId(docType.getPublicId());
importedDocType.coreSetSystemId(docType.getSystemId());
importedDocType.coreSetInternalSubset(docType.getInternalSubset());
return importedDocType;
}
case OMNode.ENTITY_REFERENCE_NODE:
AxiomEntityReference importedEntityRef = createNode(AxiomEntityReference.class);
importedEntityRef.coreSetName(((OMEntityReference) child).getName());
return importedEntityRef;
default:
throw new IllegalArgumentException("Unsupported node type");
}
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class OMFactoryImpl method createOMElement.
@Override
public final OMElement createOMElement(QName qname, OMContainer parent) {
AxiomElement element = createNode(AxiomElement.class);
if (parent != null) {
parent.addChild(element);
}
element.internalSetLocalName(qname.getLocalPart());
String prefix = qname.getPrefix();
String namespaceURI = qname.getNamespaceURI();
if (namespaceURI.length() > 0) {
// The goal here is twofold:
// * check if the namespace needs to be declared;
// * locate an existing OMNamespace object, so that we can avoid creating a new one.
OMNamespace ns = element.findNamespace(namespaceURI, prefix.length() == 0 ? null : prefix);
if (ns == null) {
if ("".equals(prefix)) {
prefix = generatePrefix(namespaceURI);
}
ns = element.declareNamespace(namespaceURI, prefix);
}
element.internalSetNamespace(ns);
} else if (prefix.length() > 0) {
throw new IllegalArgumentException("Cannot create a prefixed element with an empty namespace name");
} else {
if (element.getDefaultNamespace() != null) {
element.declareDefaultNamespace("");
}
element.internalSetNamespace(null);
}
return element;
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class DeferredNamespace method equals.
@Override
public boolean equals(Object obj) {
if (!(obj instanceof OMNamespace)) {
return false;
}
OMNamespace other = (OMNamespace) obj;
String otherPrefix = other.getPrefix();
String thisPrefix = getPrefix();
return (uri.equals(other.getNamespaceURI()) && (thisPrefix == null ? otherPrefix == null : thisPrefix.equals(otherPrefix)));
}
use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.
the class OMChildrenWithSpecificAttributeIteratorTest method testChildrenRetrievalWithNoDetaching.
public void testChildrenRetrievalWithNoDetaching() {
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace testNamespace = factory.createOMNamespace("http://test.ws.org", "test");
OMElement documentElement = getSampleDocumentElement(testNamespace);
Iterator childrenIter = new OMChildrenWithSpecificAttributeIterator(documentElement.getFirstOMChild(), new QName(testNamespace.getNamespaceURI(), "myAttr", testNamespace.getPrefix()), "Axis2", false);
int childCount = getChidrenCount(childrenIter);
assertEquals("Iterator must return 5 children with the given attribute", childCount, 5);
Iterator children = documentElement.getChildren();
childCount = getChidrenCount(children);
assertEquals("Iterator must return 6 children, having not detached the children", childCount, 6);
}
Aggregations