use of org.apache.axiom.om.impl.intf.AxiomElement in project webservices-axiom by apache.
the class SOAP11BuilderHelper method handleEvent.
@Override
public Class<? extends AxiomElement> handleEvent(OMElement parent, int elementLevel, String namespaceURI, String localName) throws SOAPProcessingException {
Class<? extends AxiomElement> elementType = null;
if (elementLevel == 4) {
if (SOAP_FAULT_CODE_LOCAL_NAME.equals(localName)) {
elementType = AxiomSOAP11FaultCode.class;
faultcodePresent = true;
} else if (SOAP_FAULT_STRING_LOCAL_NAME.equals(localName)) {
elementType = AxiomSOAP11FaultReason.class;
faultstringPresent = true;
} else if (SOAP_FAULT_ACTOR_LOCAL_NAME.equals(localName)) {
elementType = AxiomSOAP11FaultRole.class;
} else if (SOAP_FAULT_DETAIL_LOCAL_NAME.equals(localName)) {
elementType = AxiomSOAP11FaultDetail.class;
} else {
elementType = AxiomElement.class;
}
} else if (elementLevel == 5) {
String parentTagName = "";
if (parent instanceof Element) {
parentTagName = ((Element) parent).getTagName();
} else {
parentTagName = parent.getLocalName();
}
if (parentTagName.equals(SOAP_FAULT_CODE_LOCAL_NAME)) {
throw new SOAPProcessingException("faultcode element should not have children");
} else if (parentTagName.equals(SOAP_FAULT_STRING_LOCAL_NAME)) {
throw new SOAPProcessingException("faultstring element should not have children");
} else if (parentTagName.equals(SOAP_FAULT_ACTOR_LOCAL_NAME)) {
throw new SOAPProcessingException("faultactor element should not have children");
} else {
elementType = AxiomElement.class;
}
} else if (elementLevel > 5) {
elementType = AxiomElement.class;
}
return elementType;
}
use of org.apache.axiom.om.impl.intf.AxiomElement in project webservices-axiom by apache.
the class CustomBuilderManager method getAction.
private Runnable getAction(CoreNode node, int depth, int firstCustomBuilder) {
lastCandidateElement = null;
lastCandidateDepth = -1;
if (node instanceof AxiomElement && (node instanceof AxiomSOAPHeaderBlock || !(node instanceof AxiomSOAPElement))) {
final AxiomElement element = (AxiomElement) node;
if (registrations != null) {
for (int i = firstCustomBuilder; i < registrations.size(); i++) {
CustomBuilderRegistration registration = registrations.get(i);
final String namespaceURI = element.coreGetNamespaceURI();
final String localName = element.coreGetLocalName();
if (registration.getSelector().accepts(element.getParent(), depth, namespaceURI, localName)) {
final CustomBuilder customBuilder = registration.getCustomBuilder();
if (log.isDebugEnabled()) {
log.debug("Custom builder " + customBuilder + " accepted element {" + namespaceURI + "}" + localName + " at depth " + depth);
}
return new Runnable() {
@Override
public void run() {
if (log.isDebugEnabled()) {
log.debug("Invoking custom builder " + customBuilder);
}
OMDataSource dataSource = customBuilder.create(element);
Class<? extends AxiomSourcedElement> type;
if (element instanceof AxiomSOAP11HeaderBlock) {
type = AxiomSOAP11HeaderBlock.class;
} else if (element instanceof AxiomSOAP12HeaderBlock) {
type = AxiomSOAP12HeaderBlock.class;
} else {
type = AxiomSourcedElement.class;
}
if (log.isDebugEnabled()) {
log.debug("Replacing element with new sourced element of type " + type);
}
AxiomSourcedElement newElement = element.coreCreateNode(type);
newElement.init(localName, new OMNamespaceImpl(namespaceURI, null), dataSource);
try {
element.coreReplaceWith(newElement, AxiomSemantics.INSTANCE);
} catch (CoreModelException ex) {
throw AxiomExceptionTranslator.translate(ex);
}
}
};
}
}
}
// Save a reference to the element so that we can process it when another custom builder is registered
lastCandidateElement = element;
lastCandidateDepth = depth;
}
return null;
}
use of org.apache.axiom.om.impl.intf.AxiomElement 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.impl.intf.AxiomElement 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.impl.intf.AxiomElement in project webservices-axiom by apache.
the class SOAP12BuilderHelper method handleEvent.
@Override
public Class<? extends AxiomElement> handleEvent(OMElement parent, int elementLevel, String namespaceURI, String localName) throws SOAPProcessingException {
Class<? extends AxiomElement> elementType = null;
if (elementLevel == 4) {
if (localName.equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) {
if (codePresent) {
throw new SOAPProcessingException("Multiple Code element encountered");
} else {
elementType = AxiomSOAP12FaultCode.class;
codePresent = true;
codeprocessing = true;
}
} else if (localName.equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) {
if (!codeprocessing && !subCodeProcessing) {
if (codePresent) {
if (reasonPresent) {
throw new SOAPProcessingException("Multiple Reason Element encountered");
} else {
elementType = AxiomSOAP12FaultReason.class;
reasonPresent = true;
reasonProcessing = true;
}
} else {
throw new SOAPProcessingException("Wrong element order encountred at " + localName);
}
} else {
if (codeprocessing) {
throw new SOAPProcessingException("Code doesn't have a value");
} else {
throw new SOAPProcessingException("A subcode doesn't have a Value");
}
}
} else if (localName.equals(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME)) {
if (!reasonProcessing) {
if (reasonPresent && !rolePresent && !detailPresent) {
if (nodePresent) {
throw new SOAPProcessingException("Multiple Node element encountered");
} else {
elementType = AxiomSOAP12FaultNode.class;
nodePresent = true;
}
} else {
throw new SOAPProcessingException("wrong element order encountered at " + localName);
}
} else {
throw new SOAPProcessingException("Reason element Should have a text");
}
} else if (localName.equals(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME)) {
if (!reasonProcessing) {
if (reasonPresent && !detailPresent) {
if (rolePresent) {
throw new SOAPProcessingException("Multiple Role element encountered");
} else {
elementType = AxiomSOAP12FaultRole.class;
rolePresent = true;
}
} else {
throw new SOAPProcessingException("Wrong element order encountered at " + localName);
}
} else {
throw new SOAPProcessingException("Reason element should have a text");
}
} else if (localName.equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) {
if (!reasonProcessing) {
if (reasonPresent) {
if (detailPresent) {
throw new SOAPProcessingException("Multiple detail element encountered");
} else {
elementType = AxiomSOAP12FaultDetail.class;
detailPresent = true;
}
} else {
throw new SOAPProcessingException("wrong element order encountered at " + localName);
}
} else {
throw new SOAPProcessingException("Reason element should have a text");
}
} else {
throw new SOAPProcessingException(localName + " unsupported element in SOAPFault element");
}
} else if (elementLevel == 5) {
if (parent.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) {
if (localName.equals(SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME)) {
if (!valuePresent) {
elementType = AxiomSOAP12FaultValue.class;
valuePresent = true;
codeprocessing = false;
} else {
throw new SOAPProcessingException("Multiple value Encountered in code element");
}
} else if (localName.equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME)) {
if (!subcodePresent) {
if (valuePresent) {
elementType = AxiomSOAP12FaultSubCode.class;
subcodePresent = true;
subCodeProcessing = true;
} else {
throw new SOAPProcessingException("Value should present before the subcode");
}
} else {
throw new SOAPProcessingException("multiple subcode Encountered in code element");
}
} else {
throw new SOAPProcessingException(localName + " is not supported inside the code element");
}
} else if (parent.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) {
if (localName.equals(SOAP12Constants.SOAP_FAULT_TEXT_LOCAL_NAME)) {
elementType = AxiomSOAP12FaultText.class;
reasonProcessing = false;
} else {
throw new SOAPProcessingException(localName + " is not supported inside the reason");
}
} else if (parent.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) {
elementType = AxiomElement.class;
processingDetailElements = true;
detailElementNames = new Vector<String>();
detailElementNames.add(localName);
} else {
throw new SOAPProcessingException(parent.getLocalName() + " should not have child element");
}
} else if (elementLevel > 5) {
if (parent.getLocalName().equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME)) {
if (localName.equals(SOAP12Constants.SOAP_FAULT_VALUE_LOCAL_NAME)) {
if (subcodeValuePresent) {
throw new SOAPProcessingException("multiple subCode value encountered");
} else {
elementType = AxiomSOAP12FaultValue.class;
subcodeValuePresent = true;
subSubcodePresent = false;
subCodeProcessing = false;
}
} else if (localName.equals(SOAP12Constants.SOAP_FAULT_SUB_CODE_LOCAL_NAME)) {
if (subcodeValuePresent) {
if (!subSubcodePresent) {
elementType = AxiomSOAP12FaultSubCode.class;
subcodeValuePresent = false;
subSubcodePresent = true;
subCodeProcessing = true;
} else {
throw new SOAPProcessingException("multiple subcode encountered");
}
} else {
throw new SOAPProcessingException("Value should present before the subcode");
}
} else {
throw new SOAPProcessingException(localName + " is not supported inside the subCode element");
}
} else if (processingDetailElements) {
int detailElementLevel = 0;
boolean localNameExist = false;
for (int i = 0; i < detailElementNames.size(); i++) {
if (parent.getLocalName().equals(detailElementNames.get(i))) {
localNameExist = true;
detailElementLevel = i + 1;
}
}
if (localNameExist) {
detailElementNames.setSize(detailElementLevel);
elementType = AxiomElement.class;
detailElementNames.add(localName);
}
} else {
throw new SOAPProcessingException(parent.getLocalName() + " should not have child at element level " + elementLevel);
}
}
return elementType;
}
Aggregations