/// /// <summary> * Evaluates the boolean expression (child Term element) if it fits the /// * JDFNode 'jdf' a value of true corresponds to a failed test, i.e. the test /// * describes INVALID states for the jdf /// * </summary> /// * <param name="jdf"> /// * JDFNode to test to know if the Device can accept it </param> /// * <param name="reportRoot"> /// * the report to generate. Set to <code>null</code> if no report /// * is requested. </param> /// * <returns> boolean - true, if boolean expression (child Term element) /// * evaluates to “true” </returns> /// public override bool fitsJDF(KElement jdf, KElement reportRoot) { KElement reportRootLocal = reportRoot; if (reportRootLocal != null) { reportRootLocal = reportRootLocal.appendElement("TestReport"); } JDFTerm t = getTerm(); if (t == null) { return(true); // no term --> assume it is a non test; i.e. ok } bool checkContext = true; if (hasAttribute(AttributeName.CONTEXT)) { checkContext = !jdf.matchesPath(getContext(), true); } if (checkContext && !t.fitsContext(jdf)) { return(true); } bool b = t.fitsJDF(jdf, reportRootLocal); if (reportRootLocal != null) { reportRootLocal.setAttribute("Value", b, null); } return(b); }
/// /// <summary> * check whether the boolean logic defined by a Test and a test's /// * subelements makes sense in the context of the tested element jdf </summary> /// public override bool fitsContext(KElement testElement) { if (hasAttribute(AttributeName.CONTEXT)) { return(testElement.matchesPath(getContext(), true)); } return(base.fitsContext(testElement)); }
/// /// <summary> * gets the XPath to the attributes of a given JDF node /// * </summary> /// * <param name="jdf"> /// * JDF node to test </param> /// * <returns> String - the XPath to the attributes </returns> /// protected internal virtual string getEvalXPath(KElement jdf) { ICapabilityElement stateDC = getRefTarget(); if (stateDC == null) { return(null); } VString vPath = null; bool bElement = false; string attName = null; if (stateDC is JDFDevCap) { if (!(this is JDFIsPresentEvaluation)) // only ispresent may // reference a // devcap, all // others must // reference a state { return(null); } bElement = true; JDFDevCap dc = (JDFDevCap)stateDC; vPath = dc.getNamePathVector(true); // fix up for the fact that ispresent for a resource is actually a // link if (vPath != null) { for (int i = 0; i < vPath.Count; i++) { string path = vPath.stringAt(i); VString tokens = new VString(StringUtil.tokenize(path, "/", false)); if (tokens.Count == 3 && tokens.stringAt(1).Equals(ElementName.RESOURCEPOOL)) { tokens[1] = ElementName.RESOURCELINKPOOL; tokens[2] = tokens.stringAt(2) + "Link"; vPath[i] = StringUtil.setvString(tokens, "/", null, null); } } } } else if (stateDC is JDFDevCaps) { if (!(this is JDFIsPresentEvaluation)) // only ispresent may // reference a // devcap, all // others must // reference a state { return(null); } bElement = true; JDFDevCaps dc = (JDFDevCaps)stateDC; vPath = dc.getNamePathVector(); // fix up for the fact that ispresent for a resource is actually a // link if (vPath != null) { for (int i = 0; i < vPath.Count; i++) { string path = vPath.stringAt(i); VString tokens = new VString(StringUtil.tokenize(path, "/", false)); if (tokens.Count == 3 && tokens.stringAt(1).Equals(ElementName.RESOURCEPOOL)) { tokens[1] = ElementName.RESOURCELINKPOOL; string link = tokens.stringAt(2) + "Link"; EnumUsage lu = dc.getLinkUsage(); if (lu != null) { link += "[@Usage=\"" + lu.getName() + "\"]"; } tokens[2] = link; vPath[i] = StringUtil.setvString(tokens, "/", null, null); } } } } else { // we have found our state -> take its xPath and look for // corresponding elem in JDFNode, we test JDFAbstractState state = (JDFAbstractState)stateDC; if (state.getListType().Equals(EnumListType.Span)) { vPath = state.getNamePathVector(true); bElement = true; } else { KElement kdc = state.getParentNode_KElement(); if (kdc is IDeviceCapable) { vPath = ((IDeviceCapable)kdc).getNamePathVector(); } else if (kdc is ICapabilityElement) { vPath = ((ICapabilityElement)kdc).getNamePathVector(); } attName = state.getName(); } } if (vPath != null) { for (int i = 0; i < vPath.Count; i++) { string xPath = vPath.stringAt(i); int slash = xPath.Length; string finalS = null; do { string xPath2 = xPath.Substring(0, slash); if (jdf.matchesPath(xPath2, true)) { finalS = "." + xPath.Substring(slash); } slash = xPath2.LastIndexOf("/"); } while (slash >= 0 && finalS == null); if (finalS != null && !bElement) { finalS += "/@" + attName; } if (finalS != null) { return(finalS); } } } return(null); }