Search in sources :

Example 1 with JXPathException

use of org.apache.commons.jxpath.JXPathException in project freud by LMAX-Exchange.

the class JavaSourceJdom method parsePackageDeclaration.

private PackageDeclaration parsePackageDeclaration() {
    try {
        JXPathContext context = JXPathContext.newContext(root);
        packageDeclaration = new PackageDeclarationJdom((Element) context.selectSingleNode("/" + JAVA_SOURCE_ROOT_ELEMENT_NAME + "/" + JavaSourceTokenType.PACKAGE.name()));
    } catch (JXPathException e) {
        packageDeclaration = new PackageDeclarationJdom();
    }
    return packageDeclaration;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Element(org.jdom.Element) JXPathException(org.apache.commons.jxpath.JXPathException)

Example 2 with JXPathException

use of org.apache.commons.jxpath.JXPathException in project freud by LMAX-Exchange.

the class JavaSourceJdom method parseClassDeclaration.

// /////////////////////////////////////////////////////////////////////////////////////////////////////
private ClassDeclaration parseClassDeclaration() {
    JXPathContext context = JXPathContext.newContext(root);
    for (JavaSourceTokenType tokenType : POSSIBLE_CLASS_DECLARATION_TYPES) {
        try {
            final String tokenName = tokenType.name();
            final Element element = (Element) context.selectSingleNode("/" + JAVA_SOURCE_ROOT_ELEMENT_NAME + "/" + tokenName);
            if (element != null) {
                classDeclaration = new ClassDeclarationJdom(element, getDeclarationType(tokenType), null);
            }
        } catch (JXPathException e) {
        // ignore and try another path
        }
    }
    if (classDeclaration == null) {
        throw new IllegalStateException("Internal: could not find class declaration in: " + this);
    }
    return classDeclaration;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Element(org.jdom.Element) JXPathException(org.apache.commons.jxpath.JXPathException) JavaSourceTokenType(org.freud.analysed.javasource.parser.JavaSourceTokenType) JdomTreeAdaptor.documentToString(org.freud.core.parser.JdomTreeAdaptor.documentToString)

Example 3 with JXPathException

use of org.apache.commons.jxpath.JXPathException in project tesb-rt-se by Talend.

the class XPathProcessor method processJXpathParts.

private Map<String, String> processJXpathParts(List<XpathPart> parts, List<XpathNamespace> namespaces, Node body) {
    Map<String, String> resultMap = new HashMap<String, String>();
    JXPathContext messageContext = JXPathContext.newContext(body);
    if (namespaces != null) {
        for (XpathNamespace namespace : namespaces) {
            String prefix = namespace.getPrefix();
            String uri = namespace.getUri();
            if (null != uri && null != prefix) {
                messageContext.registerNamespace(prefix, uri);
            }
        }
    }
    for (XpathPart part : parts) {
        try {
            JXPathContext.compile(part.getXpath());
        } catch (JXPathException ex) {
            throw new RuntimeException("Validation of XPATH expression" + "{ name: " + part.getName() + "; xpath: " + part.getXpath() + " } failed", ex);
        }
        try {
            Object val = messageContext.getValue(part.getXpath());
            String result = (val == null) ? null : val.toString();
            resultMap.put(part.getXpath(), val.toString());
            if ((result == null || result.isEmpty()) && !part.isOptional()) {
                throw new RuntimeException("Can not evaluate Xpath expression" + "{ name: " + part.getName() + "; xpath: " + part.getXpath() + " }");
            }
        } catch (RuntimeException ex) {
            if (!part.isOptional()) {
                throw new RuntimeException("Evaluation of XPATH expression" + "{ name: " + part.getName() + "; xpath: " + part.getXpath() + " } failed", ex);
            }
        }
    }
    return resultMap;
}
Also used : XpathNamespace(org.talend.esb.policy.correlation.impl.xpath.XpathNamespace) JXPathContext(org.apache.commons.jxpath.JXPathContext) HashMap(java.util.HashMap) XpathPart(org.talend.esb.policy.correlation.impl.xpath.XpathPart) JXPathException(org.apache.commons.jxpath.JXPathException)

Example 4 with JXPathException

use of org.apache.commons.jxpath.JXPathException in project freud by LMAX-Exchange.

the class JavaSourceJdom method parseImportDeclaration.

private List<ImportDeclaration> parseImportDeclaration() {
    try {
        final JXPathContext context = JXPathContext.newContext(root);
        final List importNodes = context.selectNodes("/" + JAVA_SOURCE_ROOT_ELEMENT_NAME + "/" + JavaSourceTokenType.IMPORT.name());
        importDeclarations = new ArrayList<ImportDeclaration>(importNodes.size());
        for (Object importNode : importNodes) {
            importDeclarations.add(new ImportDeclarationJdom((Element) importNode));
        }
    } catch (JXPathException e) {
        importDeclarations = emptyList();
    }
    return importDeclarations;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Element(org.jdom.Element) ImportDeclaration(org.freud.analysed.javasource.ImportDeclaration) JXPathException(org.apache.commons.jxpath.JXPathException) Collections.emptyList(java.util.Collections.emptyList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with JXPathException

use of org.apache.commons.jxpath.JXPathException in project freud by LMAX-Exchange.

the class MethodDeclarationJdom method getImplementation.

public CodeBlock getImplementation() {
    if (methodCodeBlock == null) {
        try {
            JXPathContext context = JXPathContext.newContext(methodDeclElement);
            Element codeBlockElement = (Element) context.selectSingleNode("/" + JavaSourceTokenType.BLOCK_SCOPE.getName());
            methodCodeBlock = CodeBlockJdom.createMethodImplementation(codeBlockElement, this, classDeclaration);
        } catch (JXPathException e) {
            return null;
        }
    }
    return methodCodeBlock;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Element(org.jdom.Element) JXPathException(org.apache.commons.jxpath.JXPathException)

Aggregations

JXPathException (org.apache.commons.jxpath.JXPathException)8 JXPathContext (org.apache.commons.jxpath.JXPathContext)7 Element (org.jdom.Element)4 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Invocable (javax.script.Invocable)1 ScriptEngine (javax.script.ScriptEngine)1 ScriptEngineManager (javax.script.ScriptEngineManager)1 ScriptException (javax.script.ScriptException)1 JSONObject (net.sf.json.JSONObject)1 ExpressionEvaluationException (org.apache.camel.ExpressionEvaluationException)1 ExpressionContext (org.apache.commons.jxpath.ExpressionContext)1 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)1 Pointer (org.apache.commons.jxpath.Pointer)1 ImportDeclaration (org.freud.analysed.javasource.ImportDeclaration)1 JavaSourceTokenType (org.freud.analysed.javasource.parser.JavaSourceTokenType)1 JdomTreeAdaptor.documentToString (org.freud.core.parser.JdomTreeAdaptor.documentToString)1