/** * Tries to find a usage of the variable and returns the maximum depth of the relevant * element inside of the structure. * @param command the Command to start traversal with * @return an int >= 0 or null if not found at all */ public int checkDepth(ICommandWithWhere command) { if (command is IConstruct) { // Check head of Construct foreach (ITripleTemplate template in ((IConstruct)command).getTemplates()) { if (containsVar(template)) { result = 0; } } } else if (command is IModify) { IResource modify = command; if (templateContainsVar(modify.getObject(SP.PropertyInsertPattern))) { result = 0; } if (templateContainsVar(modify.getObject(SP.PropertyDeletePattern))) { result = 0; } } IElementList where = command.getWhere(); if (where != null) { walker = new ElementWalkerWithDepth(el, ex); walker.visit(where); } return(result); }
/** * Checks whether a given query mentions the variable ?this anywhere. * This can be used to check whether ?this needs to be bound before * execution, etc. * @param command the query to test * @return null to indicate it was not found, an int >= 0 representing * the max depth inside query element tree otherwise */ public static int containsThis(ICommandWithWhere command) { return(new ContainsVarChecker(SPIN.Property_this).checkDepth(command)); }