use of org.apache.axiom.om.OMComment in project webservices-axiom by apache.
the class OMElementTest method testAddLLOMTextChildToDOOM.
public void testAddLLOMTextChildToDOOM() throws XMLStreamException {
OMFactory doomFactory = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getOMFactory();
OMFactory llomFactory = OMAbstractFactory.getOMFactory();
String text = "This was a DOOM Text";
OMElement doomRoot = doomFactory.createOMElement("root", null);
OMText llomText = llomFactory.createOMText(text);
OMComment comment = llomFactory.createOMComment(null, "comment");
doomRoot.addChild(llomText);
doomRoot.addChild(comment);
OMElement newElement = (OMXMLBuilderFactory.createStAXOMBuilder(this.factory, doomRoot.getXMLStreamReader())).getDocumentElement();
newElement.build();
assertEquals(newElement.getText(), text);
}
use of org.apache.axiom.om.OMComment in project webservices-axiom by apache.
the class WriteCommentScenario method validate.
@Override
public void validate(OMElement element, boolean dataHandlersPreserved) throws Throwable {
OMNode child = element.getFirstOMChild();
Assert.assertTrue(child instanceof OMComment);
Assert.assertEquals("comment", ((OMComment) child).getValue());
}
use of org.apache.axiom.om.OMComment in project webservices-axiom by apache.
the class TestGetDocumentElement method runTest.
@Override
protected void runTest() throws Throwable {
OMXMLParserWrapper builder = builderFactory.getBuilder(metaFactory, new InputSource(new StringReader("<!--comment1--><root/><!--comment2-->")));
OMElement element;
if (discardDocument == null) {
element = builder.getDocumentElement();
} else {
element = builder.getDocumentElement(discardDocument.booleanValue());
}
assertNotNull("Document element can not be null", element);
assertEquals("Name of the document element is wrong", "root", element.getLocalName());
if (Boolean.TRUE.equals(discardDocument)) {
if (builderFactory.isDeferredParsing()) {
assertFalse(element.isComplete());
}
assertNull(element.getParent());
// Note: we can't test getNextOMSibling here because this would build the element
assertNull(element.getPreviousOMSibling());
OMElement newParent = element.getOMFactory().createOMElement("newParent", null);
newParent.addChild(element);
if (builderFactory.isDeferredParsing()) {
assertFalse(element.isComplete());
assertFalse(builder.isCompleted());
}
assertAbout(xml()).that(xml(OMElement.class, newParent)).hasSameContentAs("<newParent><root/></newParent>");
assertTrue(element.isComplete());
// Since we discarded the document, the nodes in the epilog will not be accessible.
// Therefore we expect that when the document element changes its completion status,
// the builder will consume the epilog and change its completion status as well.
// This gives the underlying parser a chance to release some resources.
assertTrue(builder.isCompleted());
} else {
// The getDocumentElement doesn't detach the document element from the document:
assertSame(builder.getDocument(), element.getParent());
assertSame(builder.getDocument().getOMDocumentElement(), element);
assertTrue(element.getPreviousOMSibling() instanceof OMComment);
assertTrue(element.getNextOMSibling() instanceof OMComment);
}
}
use of org.apache.axiom.om.OMComment in project webservices-axiom by apache.
the class TestInsertSibling method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("parent", null);
OMText child = factory.createOMText(parent, "test");
OMComment orgSibling = altMetaFactory.getOMFactory().createOMComment(null, "test");
if (before) {
child.insertSiblingBefore(orgSibling);
} else {
child.insertSiblingAfter(orgSibling);
}
OMComment sibling = (OMComment) (before ? child.getPreviousOMSibling() : child.getNextOMSibling());
assertThat(sibling).isNotSameAs(orgSibling);
assertThat(sibling.getValue()).isEqualTo("test");
}
use of org.apache.axiom.om.OMComment in project wso2-synapse by wso2.
the class SynapseXMLConfigurationFactory method getConfiguration.
public SynapseConfiguration getConfiguration(OMElement definitions, Properties properties) {
if (!definitions.getQName().equals(XMLConfigConstants.DEFINITIONS_ELT)) {
throw new SynapseException("Wrong QName for this configuration factory " + definitions.getQName());
}
SynapseConfiguration config = SynapseConfigUtils.newConfiguration();
config.setDefaultQName(definitions.getQName());
Iterator itr = definitions.getChildren();
while (itr.hasNext()) {
Object o = itr.next();
if (o instanceof OMElement) {
OMElement elt = (OMElement) o;
if (XMLConfigConstants.SEQUENCE_ELT.equals(elt.getQName())) {
String key = elt.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
// this could be a sequence def or a referred sequence
if (key != null) {
handleException("Referred sequences are not allowed at the top level");
} else {
defineSequence(config, elt, properties);
}
} else if (XMLConfigConstants.TEMPLATE_ELT.equals(elt.getQName())) {
defineTemplate(config, elt, properties);
} else if (XMLConfigConstants.IMPORT_ELT.equals(elt.getQName())) {
defineImport(config, elt, properties);
} else if (XMLConfigConstants.ENDPOINT_ELT.equals(elt.getQName())) {
defineEndpoint(config, elt, properties);
} else if (XMLConfigConstants.ENTRY_ELT.equals(elt.getQName())) {
defineEntry(config, elt, properties);
} else if (XMLConfigConstants.PROXY_ELT.equals(elt.getQName())) {
defineProxy(config, elt, properties);
} else if (XMLConfigConstants.REGISTRY_ELT.equals(elt.getQName())) {
defineRegistry(config, elt, properties);
} else if (XMLConfigConstants.EVENT_SOURCE_ELT.equals(elt.getQName())) {
defineEventSource(config, elt, properties);
} else if (XMLConfigConstants.EXECUTOR_ELT.equals(elt.getQName())) {
defineExecutor(config, elt, properties);
} else if (XMLConfigConstants.MESSAGE_STORE_ELT.equals(elt.getQName())) {
defineMessageStore(config, elt, properties);
} else if (XMLConfigConstants.TASK_MANAGER_ELT.equals(elt.getQName())) {
defineTaskManager(config, elt, properties);
} else if (XMLConfigConstants.MESSAGE_PROCESSOR_ELT.equals(elt.getQName())) {
defineMessageProcessor(config, elt, properties);
} else if (StartupFinder.getInstance().isStartup(elt.getQName())) {
defineStartup(config, elt, properties);
} else if (XMLConfigConstants.API_ELT.equals(elt.getQName())) {
defineAPI(config, elt, properties);
} else if (XMLConfigConstants.DESCRIPTION_ELT.equals(elt.getQName())) {
config.setDescription(elt.getText());
} else if (XMLConfigConstants.INBOUND_ENDPOINT_ELT.equals(elt.getQName())) {
defineInboundEndpoint(config, elt, properties);
} else {
handleException("Invalid configuration element at the top level, one of \'sequence\', " + "\'endpoint\', \'proxy\', \'eventSource\', \'localEntry\', \'priorityExecutor\'" + ", \'registry\' or \'inboundEndpoint\' is expected");
}
} else if (o instanceof OMComment) {
OMComment commentNode = (OMComment) o;
defineComments(config, commentNode);
}
}
return config;
}
Aggregations