public virtual void testCopyNodeData() { JDFDoc d = new JDFDoc("JDF"); JDFNode n = d.getJDFRoot(); n.setType(EnumType.Product); JDFNode n1 = n = n.addJDFNode(EnumType.BlockPreparation); n1.setAttribute("foo:bar", "fnarf", "www.foobar.com"); JDFDoc dA = new JDFDoc("JDF"); JDFAncestorPool ap = dA.getJDFRoot().appendAncestorPool(); ap.appendAncestor().setNodeID(n1.getID()); ap.copyNodeData(n, true, true, false); JDFAncestor a0 = ap.getAncestor(0); Assert.AreEqual("fnarf", a0.getAttribute("foo:bar")); Assert.AreEqual(n1.getID(), a0.getNodeID()); string s = dA.write2String(2); JDFParser p = new JDFParser(); JDFDoc test = p.parseString(s); Assert.IsNotNull(test); }
/// /// <summary> * Get the linked resources matching some conditions /// * </summary> /// * <param name="mResAtt"> map of Resource attributes to search for </param> /// * <param name="bFollowRefs"> true if internal references shall be followed /// * </param> /// * <returns> vResource: vector with all elements matching the conditions /// * /// * default: GetLinkedResources(new JDFAttributeMap(), false) </returns> /// public virtual VElement getLinkedResources(JDFAttributeMap mResAtt, bool bFollowRefs) { VElement vChild = getPoolChildren(mResAtt); VElement vElem = new VElement(); for (int i = 0; i < vChild.Count; i++) { JDFAncestor anc = (JDFAncestor)vChild[i]; vElem.appendUnique(anc.getLinkedResources(mResAtt, bFollowRefs)); } return(vElem); }
/// /// <summary> * Get all Ancestor from the current element /// * </summary> /// * <returns> Collection<JDFAncestor> </returns> /// public virtual ICollection <JDFAncestor> getAllAncestor() { List <JDFAncestor> v = new List <JDFAncestor>(); JDFAncestor kElem = (JDFAncestor)getFirstChildElement(ElementName.ANCESTOR, null); while (kElem != null) { v.Add(kElem); kElem = (JDFAncestor)kElem.getNextSiblingElement(ElementName.ANCESTOR, null); } return(v); }
/// /// <summary> * searches for the first attribute occurence in the ancestor elements /// * </summary> /// * <param name="attrib"> the attribute name </param> /// * <param name="nameSpaceURI"> the XML-namespace </param> /// * <param name="def"> the default if it does not exist /// * @since 180502 </param> /// * <returns> value of attribute found, value of def if not available </returns> /// public virtual string getAncestorAttribute(string attrib, string nameSpaceURI, string def) { VElement v = getPoolChildren(null); // the last in list is the direct parent, the first is the original root for (int i = v.Count - 1; i >= 0; i--) { JDFAncestor ancestor = (JDFAncestor)v[i]; if (ancestor.hasAttribute(attrib, nameSpaceURI, false)) { return(ancestor.getAttribute(attrib, nameSpaceURI, JDFConstants.EMPTYSTRING)); } } // not found, return the default return(def); }
/// /// <summary> * searches for the first attribute occurence in the ancestor elements subelements<br> /// * e.g. the JobPriority in NodeInfo /// * </summary> /// * <param name="element"> node name to look in </param> /// * <param name="attrib"> the attribute name </param> /// * <param name="nameSpaceURI"> the XML-namespace </param> /// * <param name="def"> the default if it does not exist /// * @since 200503 </param> /// * <returns> value of attribute found, empty string if not available </returns> /// public virtual string getAncestorElementAttribute(string element, string attrib, string nameSpaceURI, string def) { VElement v = getPoolChildren(null); // the last in list is the direct parent, the first is the original root for (int i = v.Count - 1; i >= 0; i--) { JDFAncestor ancestor = (JDFAncestor)v[i]; KElement e = ancestor.getElement(element, nameSpaceURI, 0); if ((e != null) && (e.hasAttribute(attrib, nameSpaceURI, false))) { return(e.getAttribute(attrib, nameSpaceURI, JDFConstants.EMPTYSTRING)); } } return(def); }
/// /// <summary> * searches for the first element occurence in the ancestor elements /// * </summary> /// * <param name="element"> the element name </param> /// * <param name="nameSpaceURI"> the XML-namespace of the element </param> /// * <param name="xPath"> the xpath of a required attribute /// * @since 290502 </param> /// * <returns> value of attribute found, empty string if not available </returns> /// public virtual KElement getAncestorElement(string element, string nameSpaceURI, string xPath) { VElement v = getPoolChildren(null); bool bWildCard = isWildCard(xPath); // the last in list is the direct parent, the first is the original root for (int i = v.Count - 1; i >= 0; i--) { JDFAncestor ancestor = (JDFAncestor)v[i]; KElement e = ancestor.getElement(element, nameSpaceURI, 0); if ((e != null) && (bWildCard || e.hasXPathNode(xPath))) { return(e); } } // not found, return an empty element return(null); }
public virtual void testStatusEquals() { // test if the auto classes implement the correct status // compare EnumNodeStatus JDFAuditPool myAuditPool = null; JDFDoc jdfDoc = new JDFDoc(ElementName.JDF); JDFNode jdfRoot = (JDFNode)jdfDoc.getRoot(); Assert.IsTrue(jdfRoot != null, "No Root found"); if (jdfRoot == null) { return; // soothe findbugs ;) } JDFAncestor ancestor = jdfRoot.appendAncestorPool().appendAncestor(); ancestor.setStatus(EnumNodeStatus.Completed); myAuditPool = jdfRoot.getCreateAuditPool(); JDFPhaseTime phaseTime = myAuditPool.addPhaseTime(JDFElement.EnumNodeStatus.Completed, null, null); JDFSpawned spawned = myAuditPool.addSpawned(jdfRoot, null, null, null, null); spawned.setStatus(JDFElement.EnumNodeStatus.Completed); Assert.AreEqual(spawned.getStatus(), phaseTime.getStatus()); Assert.AreEqual(spawned.getStatus(), ancestor.getStatus()); JDFDoc jmfDoc = new JDFDoc(ElementName.JMF); JDFJMF jmfRoot = jmfDoc.getJMFRoot(); Assert.IsTrue(jmfRoot != null, "No Root found"); if (jmfRoot == null) { return; // soothe findbugs ;) } JDFAcknowledge acknowledge = jmfRoot.appendAcknowledge(); acknowledge.setType("PipePush"); // Type is required and its existance // is validated for messages JDFJobPhase jobPhase = acknowledge.appendJobPhase(); jobPhase.setStatus(EnumNodeStatus.Completed); JDFMessage message = jmfRoot.appendMessageElement(EnumFamily.Command, null); message.setType("PipePush"); // Type is required and its existance is // validated for messages JDFPipeParams pipeParams = message.appendPipeParams(); pipeParams.setStatus(EnumNodeStatus.Completed); Assert.AreEqual(jobPhase.getStatus(), pipeParams.getStatus()); Assert.AreEqual(spawned.getStatus(), pipeParams.getStatus()); // compare EnumResStatus JDFDoc responseDoc = new JDFDoc(ElementName.RESPONSE); JDFResponse responseRoot = (JDFResponse)responseDoc.getRoot(); Assert.IsTrue(responseRoot != null, "No Root found"); if (responseRoot == null) { return; // soothe findbugs ;) } responseRoot.setType(ElementName.RESOURCE); JDFResourceInfo resInfo = responseRoot.appendResourceInfo(); resInfo.setResStatus(EnumResStatus.Available); JDFDoc commandDoc = new JDFDoc(ElementName.COMMAND); JDFCommand commandRoot = (JDFCommand)commandDoc.getRoot(); Assert.IsTrue(commandRoot != null, "No Root found"); if (commandRoot == null) { return; // soothe findbugs ;) } commandRoot.setType(ElementName.RESOURCE); JDFResourceCmdParams resCmdParams = commandRoot.appendResourceCmdParams(); resCmdParams.setResStatus(EnumResStatus.Available); Assert.AreEqual(resInfo.getStatus(), resCmdParams.getStatus()); // check EnumQueueStatus JDFDoc queueDoc = new JDFDoc(ElementName.QUEUE); JDFQueue queueRoot = (JDFQueue)queueDoc.getRoot(); Assert.IsTrue(queueRoot != null, "No Root found"); if (queueRoot == null) { return; // soothe findbugs ;) } queueRoot.setQueueStatus(EnumQueueStatus.Running); // check EnumQueueEntryStatus JDFQueueEntry queueEntry = queueRoot.appendQueueEntry(); queueEntry.setQueueEntryStatus(EnumQueueEntryStatus.Running); }
/// /// <summary> * Copy all data from parentNode into the ancestor elements of this /// * </summary> /// * <param name="parentNode"> the closest parent Node that contains the information to be copied </param> /// * <param name="bCopyNodeInfo"> if true, also copy the NodeInfo into the ancestor </param> /// * <param name="bCopyCustomerInfo"> if true, also copy the CustomerInfo into the ancestor </param> /// * <param name="bCopyComments"> if true, also copy the comments into the ancestor /// * @default copyNodeData(parentNode, false, false, false); </param> /// public virtual void copyNodeData(JDFNode parentNode, bool bCopyNodeInfo, bool bCopyCustomerInfo, bool bCopyComments) { VElement vAncestors = getPoolChildren(null); JDFNode node = parentNode; JDFNode thisParentNode = getParentJDF(); int i; for (i = vAncestors.Count - 1; i >= 0; i--) { JDFAncestor ancestor = (JDFAncestor)vAncestors[i]; if (!node.getID().Equals(ancestor.getNodeID())) { throw new JDFException("JDFAncestorPool::CopyNodeData: Invalid pairing"); } ancestor.setAttributes(node); ancestor.removeAttribute(AttributeName.XSITYPE); ancestor.renameAttribute(AttributeName.ID, AttributeName.NODEID, null, null); // only copy nodeinfo and customerinfo in real parent nodes, not in // this of partitioned spawns if (!thisParentNode.getID().Equals(node.getID())) { if (bCopyNodeInfo) { JDFNodeInfo nodeInfo = node.getNodeInfo(); if (nodeInfo != null) { if (nodeInfo.getParentNode_KElement() is JDFResourcePool) { // add a low level refelement, the copying takes // place inaddspawnedresources JDFRefElement re = (JDFRefElement)ancestor.appendElement(ElementName.NODEINFO + JDFConstants.REF); re.setrRef(nodeInfo.getID()); re.setPartMap(nodeInfo.getPartMap()); } else { ancestor.copyElement(nodeInfo, null); } } } if (bCopyCustomerInfo) { JDFCustomerInfo customerInfo = node.getCustomerInfo(); if (customerInfo != null) { if (customerInfo.getParentNode_KElement() is JDFResourcePool) { // add a low level refelement, the copying takes // place inaddspawnedresources JDFRefElement re = (JDFRefElement)ancestor.appendElement(ElementName.CUSTOMERINFO + JDFConstants.REF); re.setrRef(customerInfo.getID()); re.setPartMap(customerInfo.getPartMap()); } else { ancestor.copyElement(customerInfo, null); } } } if (bCopyComments) { VElement v = node.getChildElementVector(ElementName.COMMENT, null, null, true, 0, false); for (int j = 0; j < v.Count; j++) { ancestor.copyElement(v[j], null); } } } JDFNode node2 = node.getParentJDF(); // 100602 RP added i-- if (node2 == null) { i--; break; } node = node2; } // the original node was already spawned --> also copy the elements of // the original nodes Ancestorpool if (i >= 0) { VElement parentAncestors = node.getAncestorPool().getPoolChildren(null); int parentAncestorSize = parentAncestors.Count; if (parentAncestorSize < i + 1) { throw new JDFException("JDFAncestorPool.CopyNodeData: Invalid AncestorPool pairing"); } // now copy the ancestorpool elements that have not yet been added // from the original nodes for (; i >= 0; i--) { JDFAncestor ancestor = (JDFAncestor)vAncestors[i]; JDFAncestor parentAncestor = (JDFAncestor)parentAncestors[i]; ancestor.mergeElement(parentAncestor, false); } } }