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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations