Search in sources :

Example 1 with NamespaceAware

use of org.apache.camel.spi.NamespaceAware in project camel by apache.

the class CamelNamespaceHandler method injectNamespaces.

protected void injectNamespaces(Element element, Binder<Node> binder) {
    NodeList list = element.getChildNodes();
    Namespaces namespaces = null;
    int size = list.getLength();
    for (int i = 0; i < size; i++) {
        Node child = list.item(i);
        if (child instanceof Element) {
            Element childElement = (Element) child;
            Object object = binder.getJAXBNode(child);
            if (object instanceof NamespaceAware) {
                NamespaceAware namespaceAware = (NamespaceAware) object;
                if (namespaces == null) {
                    namespaces = new Namespaces(element);
                }
                namespaces.configure(namespaceAware);
            }
            injectNamespaces(childElement, binder);
        }
    }
}
Also used : Namespaces(org.apache.camel.builder.xml.Namespaces) NamespaceAware(org.apache.camel.spi.NamespaceAware) NodeList(org.w3c.dom.NodeList) ExpressionNode(org.apache.camel.model.ExpressionNode) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Endpoint(org.apache.camel.Endpoint)

Example 2 with NamespaceAware

use of org.apache.camel.spi.NamespaceAware in project camel by apache.

the class ValueBuilder method xtokenize.

public ValueBuilder xtokenize(String path, char mode, Namespaces namespaces) {
    Expression newExp = ExpressionBuilder.tokenizeXMLAwareExpression(path, mode);
    ((NamespaceAware) newExp).setNamespaces(namespaces.getNamespaces());
    return onNewValueBuilder(newExp);
}
Also used : Expression(org.apache.camel.Expression) NamespaceAware(org.apache.camel.spi.NamespaceAware)

Example 3 with NamespaceAware

use of org.apache.camel.spi.NamespaceAware in project camel by apache.

the class CamelNamespaceHandler method injectNamespaces.

protected void injectNamespaces(Element element, Binder<Node> binder) {
    NodeList list = element.getChildNodes();
    Namespaces namespaces = null;
    int size = list.getLength();
    for (int i = 0; i < size; i++) {
        Node child = list.item(i);
        if (child instanceof Element) {
            Element childElement = (Element) child;
            Object object = binder.getJAXBNode(child);
            if (object instanceof NamespaceAware) {
                NamespaceAware namespaceAware = (NamespaceAware) object;
                if (namespaces == null) {
                    namespaces = new Namespaces(element);
                }
                namespaces.configure(namespaceAware);
            }
            injectNamespaces(childElement, binder);
        }
    }
}
Also used : Namespaces(org.apache.camel.builder.xml.Namespaces) NamespaceAware(org.apache.camel.spi.NamespaceAware) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 4 with NamespaceAware

use of org.apache.camel.spi.NamespaceAware in project camel by apache.

the class CreateModelFromXmlTest method assertNamespacesPresent.

private void assertNamespacesPresent(RoutesDefinition routesDefinition, Map<String, String> expectedNamespaces) {
    for (RouteDefinition route : routesDefinition.getRoutes()) {
        Iterator<ExpressionNode> it = filterTypeInOutputs(route.getOutputs(), ExpressionNode.class);
        if (it.hasNext()) {
            ExpressionNode en = it.next();
            ExpressionDefinition ed = en.getExpression();
            NamespaceAware na = null;
            Expression exp = ed.getExpressionValue();
            if (exp != null && exp instanceof NamespaceAware) {
                na = (NamespaceAware) exp;
            } else if (ed instanceof NamespaceAware) {
                na = (NamespaceAware) ed;
            }
            assertNotNull(na);
            assertEquals(expectedNamespaces, na.getNamespaces());
        } else {
            fail("Expected to find at least one ExpressionNode in route");
        }
    }
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) Expression(org.apache.camel.Expression) ExpressionNode(org.apache.camel.model.ExpressionNode) NamespaceAware(org.apache.camel.spi.NamespaceAware) ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition)

Example 5 with NamespaceAware

use of org.apache.camel.spi.NamespaceAware in project camel by apache.

the class ModelHelper method getNamespaceAwareFromExpression.

private static NamespaceAware getNamespaceAwareFromExpression(ExpressionNode expressionNode) {
    ExpressionDefinition ed = expressionNode.getExpression();
    NamespaceAware na = null;
    Expression exp = ed.getExpressionValue();
    if (exp instanceof NamespaceAware) {
        na = (NamespaceAware) exp;
    } else if (ed instanceof NamespaceAware) {
        na = (NamespaceAware) ed;
    }
    return na;
}
Also used : Expression(org.apache.camel.Expression) NamespaceAware(org.apache.camel.spi.NamespaceAware) ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition)

Aggregations

NamespaceAware (org.apache.camel.spi.NamespaceAware)6 Expression (org.apache.camel.Expression)3 Namespaces (org.apache.camel.builder.xml.Namespaces)2 ExpressionNode (org.apache.camel.model.ExpressionNode)2 ExpressionDefinition (org.apache.camel.model.language.ExpressionDefinition)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 Endpoint (org.apache.camel.Endpoint)1 RouteDefinition (org.apache.camel.model.RouteDefinition)1