/** * Collects all queries or template calls at a given class. * @param cls the class to get the queries at * @param predicate the predicate such as <code>spin:rule</code> * @param results the List to add the results to */ public static void addQueryOrTemplateCalls(IResource cls, INode predicate, List <QueryOrTemplateCall> results) { IEnumerable <Triple> ss = cls.listProperties(predicate); // Special case: we might have an instance of a template call like spl:Attribute // Then try to find the Template in the registry if (!ss.Any() && cls != null && cls.isUri()) { ITemplate template = SPINModuleRegistry.getTemplate(cls.Uri(), null); if (template != null) { ss = template.listProperties(predicate); } } foreach (Triple s in ss) { if (!(s.Object is ILiteralNode)) { ITemplateCall templateCall = SPINFactory.asTemplateCall(Resource.Get(s.Object, cls.getModel())); if (templateCall != null) { results.Add(new QueryOrTemplateCall(cls, templateCall)); } else { IQuery query = SPINFactory.asQuery(Resource.Get(s.Object, cls.getModel())); if (query != null) { results.Add(new QueryOrTemplateCall(cls, query)); } } } } }
private static List <ITemplateCall> getFixes(IGraph cm, SpinProcessor model, INode vio) { List <ITemplateCall> fixes = new List <ITemplateCall>(); IEnumerator <Triple> fit = cm.GetTriplesWithSubjectPredicate(vio, SPIN.fix).GetEnumerator(); while (fit.MoveNext()) { Triple fs = fit.Current; if (!(fs.Object is IValuedNode)) { // ????????????? What is it for ? /* * MultiUnion union = JenaUtil.createMultiUnion(new Graph[] { * model.getGraph(), * cm.getGraph() * }); * Model unionModel = ModelFactory.createModelForGraph(union); */ IResource r = Resource.Get(fs.Object, model); ITemplateCall fix = SPINFactory.asTemplateCall(r); fixes.Add(fix); } } return(fixes); }
/** * Attempts to convert a given INode to a String so that it can be parsed into * a Jena query object. The node must be either a string Literal, or a sp:Query node * or a template call. If it's a template call then the resulting query string will * "hard-bind" the template variables. * @param node the INode to convert * @param usePrefixes true to use qname abbreviations * @return the String representation of node * @throws ArgumentException if the node is not a valid SPIN Query or a String * @deprecated for the same reason as {@link TemplateCall.getQueryString} */ public static String getQueryString(IResource node, bool usePrefixes) { if (node.isLiteral()) { return(((IValuedNode)node.getSource()).AsString()); } else { ICommand spinCommand = SPINFactory.asCommand(node); if (spinCommand != null) { if (usePrefixes) { //StringSparqlPrinter p = new StringSparqlPrinter(); //p.setUsePrefixes(usePrefixes); //spinCommand.print(p); //return p.getString(); return(String.Empty); } else { return("");//ARQFactory.get().createCommandString(spinCommand); } } else { ITemplateCall templateCall = SPINFactory.asTemplateCall(node); if (templateCall != null) { return(templateCall.getQueryString()); } else { throw new ArgumentException("INode must be either literal or a SPIN query or a SPIN template call"); } } } }