/** * Ask whether this query uses the context item * * @return true if the context item is referenced either in the query body or in the initializer * of any global variable */ public boolean usesContextItem() { if ((expression.getDependencies() & StaticProperty.DEPENDS_ON_FOCUS) != 0) { return true; } HashMap map = executable.getCompiledGlobalVariables(); if (map != null) { Iterator iter = map.values().iterator(); while (iter.hasNext()) { GlobalVariable var = (GlobalVariable) iter.next(); Expression select = var.getSelectExpression(); if (select != null && (select.getDependencies() & StaticProperty.DEPENDS_ON_FOCUS) != 0) { return true; } } } return false; }
private static List<String> analyzeExpression(Expression expression, String xpathString) { if (expression instanceof ComputedExpression) { try { final PathMap pathmap = new PathMap((ComputedExpression) expression, new Configuration()); logger.info("TEST XPATH PATHS - path for expression: " + xpathString); pathmap.diagnosticDump(System.out); final int dependencies = expression.getDependencies(); if ((dependencies & StaticProperty.DEPENDS_ON_CONTEXT_ITEM) != 0) { System.out.println(" xxx DEPENDS_ON_CONTEXT_ITEM"); return null; } if ((dependencies & StaticProperty.DEPENDS_ON_CURRENT_ITEM) != 0) { System.out.println(" xxx DEPENDS_ON_CURRENT_ITEM"); return null; } if ((dependencies & StaticProperty.DEPENDS_ON_CONTEXT_DOCUMENT) != 0) { System.out.println(" xxx DEPENDS_ON_CONTEXT_DOCUMENT"); return null; } if ((dependencies & StaticProperty.DEPENDS_ON_LOCAL_VARIABLES) != 0) { System.out.println(" xxx DEPENDS_ON_LOCAL_VARIABLES"); // Some day we'll have variables return null; } if ((dependencies & StaticProperty.NON_CREATIVE) != 0) { System.out.println(" xxx NON_CREATIVE"); } final List<String> instancesList = new ArrayList<String>(); final PathMap.PathMapRoot[] roots = pathmap.getPathMapRoots(); for (final PathMap.PathMapRoot root : roots) { final Expression rootExpression = root.getRootExpression(); if (rootExpression instanceof Instance || rootExpression instanceof XXFormsInstance) { final FunctionCall functionCall = (FunctionCall) rootExpression; // TODO: Saxon 9.0 expressions should test "instanceof StringValue" to "instanceof // StringLiteral" if (functionCall.getArguments()[0] instanceof StringValue) { final String instanceName = ((StringValue) functionCall.getArguments()[0]).getStringValue(); instancesList.add(instanceName); } else { // Instance name is not known at compile time return null; } } else if (rootExpression instanceof Doc) { // don't need document() function as that is XSLT final FunctionCall functionCall = (FunctionCall) rootExpression; // TODO: Saxon 9.0 expressions should test "instanceof StringValue" to "instanceof // StringLiteral" if (functionCall.getArguments()[0] instanceof StringValue) { // final String literalURI = ((StringValue) // functionCall.getArguments()[0]).getStringValue(); return null; } else { // Document name is not known at compile time return null; } } else if (rootExpression instanceof ContextItemExpression) { return null; } else if (rootExpression instanceof RootExpression) { // We depend on the current XForms model. return null; } // final PathMap.PathMapArc[] rootArcs = root.getArcs(); // // for (int j = 0; j < rootArcs.length; j++) { // final PathMapArc currentArc = rootArcs[j]; // final AxisExpression getStep // } } return instancesList; } catch (Exception e) { logger.error("EXCEPTION WHILE ANALYZING PATHS: " + xpathString); return null; } } else { logger.info("TEST XPATH PATHS - expression not a ComputedExpression: " + xpathString); return Collections.emptyList(); } }