示例#1
0
        public virtual void testIsEqual()
        {
            XMLDoc   d  = new XMLDoc("doc", null);
            KElement e  = d.getRoot();
            KElement e1 = e.appendElement("e1");

            e1.setAttribute("a", "b");
            KElement e2 = e.appendElement("e1");

            e2.setAttribute("a", "c");
            KElement e3 = e.appendElement("e1");

            e3.setAttribute("a", "c");
            KElement e4 = e.appendElement("e1");

            e4.setAttribute("a", "d");
            VElement v = new VElement();

            v.Add(e1);
            v.Add(e2);
            VElement v2 = new VElement(v);

            Assert.IsTrue(v.isEqual(v2));
            v2[1] = e3;
            Assert.IsTrue(v.isEqual(v2));
            v2[1] = e4;
            Assert.IsFalse(v.isEqual(v2));
        }
示例#2
0
        public virtual void testGetTargetVectorNullPart()
        {
            JDFDoc          d  = JDFTestCaseBase.creatXMDoc();
            JDFNode         n  = d.getJDFRoot();
            JDFResourceLink rl = n.getMatchingLink("ExposedMedia", EnumProcessUsage.Plate, 0);

            rl.appendPart();
            VElement v = rl.getTargetVector(0);

            Assert.AreEqual(1, v.Count, "The target vector is the node with two leaves");
            JDFResource linkRoot = rl.getLinkRoot();

            Assert.AreEqual(linkRoot, v[0], "The target vector is the node with two leaves");
            linkRoot.setPartUsage(EnumPartUsage.Implicit);
            v = rl.getTargetVector(0);
            Assert.AreEqual(1, v.Count, "The target vector is the node with two leaves");
            Assert.AreEqual(linkRoot, v[0], "The target vector is the node with two leaves");

            linkRoot.setPartUsage(EnumPartUsage.Explicit);

            JDFAttributeMap mPart = new JDFAttributeMap("SignatureName", "Sig1");

            mPart.put("SheetName", "S1");
            rl.setPartMap(mPart);
            rl.appendPart();

            v = rl.getTargetVector(0);
            Assert.AreEqual(2, v.Count, "The target vector is the node with two leaves");
            Assert.IsTrue(v.Contains(linkRoot));
            Assert.IsTrue(v.Contains(linkRoot.getPartition(mPart, null)));
            linkRoot.setPartUsage(EnumPartUsage.Implicit);
            v = rl.getTargetVector(0);
            Assert.IsTrue(v.Contains(linkRoot));
            Assert.IsTrue(v.Contains(linkRoot.getPartition(mPart, null)));
        }
示例#3
0
        ///
        ///	 <summary> * are the two vectors equivalent, i.e. do thay only contain elements that are isEqual() or if this is empty and the
        ///	 * comparison is against null
        ///	 *  </summary>
        ///	 * <param name="v"> the vector to compare </param>
        ///	 * <returns> true, if v is equal to this </returns>
        ///
        public virtual bool isEqual(VElement v)
        {
            int size = Count;

            if (v == null)
            {
                return(size == 0);
            }
            if (size != v.Count)
            {
                return(false);
            }
            VElement v0 = new VElement(this);
            VElement v1 = new VElement(v);

            v0.Sort();
            v1.Sort();
            for (int i = 0; i < size; i++)
            {
                if (!v0[i].isEqual(v1[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#4
0
        ///
        ///	 <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 = getChildElementVector(null, null, null, true, 0, false);
            VElement vElem  = new VElement();

            for (int i = 0; i < vChild.Count; i++)
            {
                if (!(vChild[i] is JDFRefElement))
                {
                    continue;
                }

                JDFRefElement l = (JDFRefElement)vChild[i];
                JDFResource   r = l.getTarget();
                r = r == null ? null : r.getResourceRoot();
                if (r != null && r.includesAttributes(mResAtt, true))
                {
                    vElem.Add(r); // vElem.push_back(r);
                    if (bFollowRefs)
                    {
                        vElem.appendUnique(r.getvHRefRes(bFollowRefs, true));
                    }
                }
            }
            return(vElem);
        }
示例#5
0
        public virtual void testContainsElement()
        {
            XMLDoc   d  = new XMLDoc("doc", null);
            KElement e  = d.getRoot();
            KElement e1 = e.appendElement("e1");

            e1.setAttribute("a", "b");
            VElement v = new VElement();

            v.appendUnique(e1);
            e1 = e.appendElement("e1");
            e1.setAttribute("a", "b");
            Assert.IsTrue(v.containsElement(e1), "containsElement");
            Assert.IsFalse(v.Contains(e1), "contains");
            e1.setText("foo");
            Assert.IsFalse(v.containsElement(e1), "containsElement");
            v.appendUnique(e1);
            Assert.AreEqual(2, v.Count, "size");
            e1 = e.appendElement("e1");
            e1.setAttribute("a", "b");
            e1.setText("foo");
            Assert.IsTrue(v.containsElement(e1), "containsElement");
            e1.setText("bar");
            Assert.IsFalse(v.containsElement(e1), "containsElement");
        }
示例#6
0
        ///
        ///	 <summary> * gets the subscription query for a given messagetype or creates one if not yet there note that newly created query
        ///	 * do not contain a subscription
        ///	 *  </summary>
        ///	 * <param name="queryType"> </param>
        ///	 * <returns> the appropriate query </returns>
        ///
        public virtual JDFQuery getCreateJMFQuery(EnumType queryType)
        {
            JDFQuery q = null;
            VElement v = getChildElementVector(ElementName.JMF, null);

            if (v != null)
            {
                int siz = v.Count;
                for (int i = 0; i < siz; i++)
                {
                    JDFJMF jmf = (JDFJMF)v[i];
                    q = (JDFQuery)jmf.getMessageElement(EnumFamily.Query, queryType, 0);
                    if (q != null)
                    {
                        break;
                    }
                }
            }

            if (q == null)
            {
                q = appendJMF().appendQuery(queryType);
            }

            return(q);
        }
示例#7
0
        public virtual void testGetTargetVectorSparse()
        {
            JDFNode         n    = new JDFDoc("JDF").getJDFRoot();
            JDFExposedMedia xm   = (JDFExposedMedia)n.getCreateResource("ExposedMedia", EnumUsage.Input, 0);
            JDFExposedMedia xmb  = (JDFExposedMedia)xm.addPartition(EnumPartIDKey.Separation, "Black");
            JDFExposedMedia xmbe = (JDFExposedMedia)xmb.addPartition(EnumPartIDKey.PartVersion, "EN");
            JDFExposedMedia xmbd = (JDFExposedMedia)xmb.addPartition(EnumPartIDKey.PartVersion, "DE");
            JDFExposedMedia xmc  = (JDFExposedMedia)xm.addPartition(EnumPartIDKey.Separation, "Cyan");

            xm.setPartUsage(EnumPartUsage.Sparse);
            JDFResourceLink rl = n.getLink(xm, null);

            rl.setPartMap(new JDFAttributeMap("PartVersion", "DE"));
            VElement v = rl.getTargetVector(-1);

            Assert.AreEqual(2, v.Count, "DE/Black + Cyan");
            Assert.AreEqual(xmbd, v[0]);
            Assert.AreEqual(xmc, v[1]);
            rl.setPartMap(new JDFAttributeMap("PartVersion", "EN"));
            v = rl.getTargetVector(-1);
            Assert.AreEqual(2, v.Count);
            Assert.AreEqual(xmbe, v[0]);
            Assert.AreEqual(xmc, v[1]);
            rl.setPartMap(new JDFAttributeMap("PartVersion", "FR"));
            v = rl.getTargetVector(-1);
            Assert.AreEqual(1, v.Count);
            Assert.AreEqual(xmc, v[0]);
            xm.setPartUsage(EnumPartUsage.Implicit);
            v = rl.getTargetVector(-1);
            Assert.AreEqual(2, v.Count);
            // TODO should be xmb?
            Assert.AreEqual(xm, v[0]);
            Assert.AreEqual(xmc, v[1]);
        }
示例#8
0
        ///
        ///	 <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 v  = getChildElementVector(null, null, null, true, 0, false);
            VElement vL = new VElement();

            for (int i = 0; i < v.Count; i++)
            {
                if ((v[i]) is JDFRefElement)
                {
                    JDFRefElement l = (JDFRefElement)v[i];
                    JDFResource   r = l.getTarget();
                    r = r == null ? null : r.getResourceRoot();

                    if (r != null && r.includesAttributes(mResAtt, true))
                    {
                        vL.Add(r);
                        if (bFollowRefs)
                        {
                            vL.appendUnique(r.getvHRefRes(bFollowRefs, true));
                        }
                    }
                }
            }

            return(vL);
        }
示例#9
0
 ///
 ///	 <summary> * addAll ignoring null collections
 ///	 *  </summary>
 ///	 * <param name="v"> the vector of elements to append </param>
 ///
 public virtual void addAll(VElement elem)
 {
     if (elem == null)
     {
         return;
     }
     base.AddRange(elem);
 }
示例#10
0
 public virtual void appendUniqueNotNull(VElement v)
 {
     if (v != null)
     {
         for (int i = 0; i < v.Count; i++)
         {
             appendUniqueNotNull(v[i]);
         }
     }
 }
示例#11
0
 ///
 ///	 <summary> * Remove elements listed in v from this
 ///	 *  </summary>
 ///	 * <param name="v"> elements to remove </param>
 ///
 public virtual void removeElements(VElement v)
 {
     for (int i = Count - 1; i >= 0; i--)
     {
         if (v.containsElement(this[i]))
         {
             RemoveAt(i);
         }
     }
 }
示例#12
0
        public virtual void testGetChildElementVector()
        {
            _setUp();
            VElement velem = m_jdfRoot.getChildElementVector(null, null, null, true, 0, false);

            Assert.AreEqual(5, velem.Count);
            KElement elem = velem[0];

            Assert.AreEqual("AuditPool", elem.Name);
            velem = m_jdfRoot.getChildElementVector(null, null, null, true, 3, false);
            Assert.AreEqual(3, velem.Count);
        }
示例#13
0
 /// <summary>
 /// Convert a generic list of elements to VElement
 /// </summary>
 /// <typeparam name="T">Type of Element</typeparam>
 /// <param name="list">List of elements</param>
 /// <returns>VElement list</returns>
 public static VElement ToVElement <T>(List <T> list) where T : KElement
 {
     if (list != null)
     {
         VElement vList = new VElement();
         foreach (KElement element in list)
         {
             vList.Add(element);
         }
         return(vList);
     }
     return(null);
 }
示例#14
0
        public virtual void testGetTargetVector()
        {
            JDFDoc          d     = JDFTestCaseBase.creatXMDoc();
            JDFNode         n     = d.getJDFRoot();
            JDFAttributeMap mPart = new JDFAttributeMap("SignatureName", "Sig1");

            mPart.put("SheetName", "S1");
            JDFResourceLink rl = n.getMatchingLink("ExposedMedia", EnumProcessUsage.Plate, 0);

            rl.setPartMap(mPart);
            VElement v = rl.getTargetVector(0);

            Assert.AreEqual(1, v.Count, "The target vector is the node with two leaves");
        }
示例#15
0
        public virtual void testgetNodeNames()
        {
            XMLDoc   d = new XMLDoc("doc", null);
            KElement e = d.getRoot();

            e.appendElement("a1");
            e.appendElement("b:a2", "b");
            VElement v = e.getChildElementVector(null, null, null, true, 0, true);
            VString  s = v.getElementNameVector(false);

            CollectionAssert.AreEqual(new VString("a1 b:a2", " "), s);
            s = v.getElementNameVector(true);
            CollectionAssert.AreEqual(new VString("a1 a2", " "), s);
        }
示例#16
0
        ///
        ///	 <summary> * AppendUnique - append a vector but ignore multiple entries
        ///	 *  </summary>
        ///	 * <param name="v"> the vector of elements to append </param>
        ///
        public virtual void appendUnique(VElement v)
        {
            if (v == null)
            {
                return;
            }

            int size = v.Count;

            for (int i = 0; i < size; i++)
            {
                appendUnique(v.item(i));
            }
        }
示例#17
0
        ///
        ///	 <summary> * Get a list of all separation names in the SeparationSpec elements
        ///	 *  </summary>
        ///	 * <returns> the vector of separation names </returns>
        ///
        public virtual VString getSeparations()
        {
            VString  vName = new VString();
            VElement v     = getChildElementVector(ElementName.SEPARATIONSPEC, null, null, false, 0, false);
            int      nSep  = v.Count;

            for (int i = 0; i < nSep; i++)
            {
                JDFSeparationSpec sep     = (JDFSeparationSpec)v[i];
                string            sepName = sep.getName();
                vName.appendUnique(sepName);
            }
            return(vName);
        }
示例#18
0
        public virtual void testAddAll()
        {
            XMLDoc   d = new XMLDoc("doc", null);
            KElement e = d.getRoot();
            VElement v = new VElement();

            v.addAll((VElement)null);
            Assert.AreEqual(0, v.Count);
            v.Add(e);
            Assert.AreEqual(1, v.Count);
            v.addAll(v);
            Assert.AreEqual(2, v.Count);
            v.addAll(v);
            Assert.AreEqual(4, v.Count);
        }
示例#19
0
        public virtual void testGetContactVectorWithContactType()
        {
            JDFDoc          doc  = new JDFDoc("JDF");
            JDFCustomerInfo info = prepareInfo(doc);

            VElement v = info.getContactVectorWithContactType("Customer");

            Assert.IsNotNull(v);
            Assert.AreEqual(3, v.Count);
            v = info.getContactVectorWithContactType("Administrator");
            Assert.IsNotNull(v);
            Assert.AreEqual(1, v.Count);
            v = info.getContactVectorWithContactType("beagle");
            Assert.IsNull(v);
        }
示例#20
0
        public virtual void testSort()
        {
            XMLDoc   d  = new XMLDoc("doc", null);
            KElement e  = d.getRoot();
            KElement e1 = e.appendElement("e1");

            e1.setAttribute("a", "z");
            KElement e2 = e.appendElement("e1");

            e2.setAttribute("a", "c");
            VElement v = new VElement();

            v.Add(e1);
            v.Add(e2);
            v.Sort();
            Assert.AreEqual(e2, v[0]);
        }
示例#21
0
        ///
        ///	 <summary> * get a list of contacts with at least one contacttype set
        ///	 *  </summary>
        ///	 * <param name="contactType"> the contatcttype to look for </param>
        ///	 * <returns> VElement the vector of matching JDFContacts, null if none are found </returns>
        ///
        public virtual VElement getContactVectorWithContactType(string contactType)
        {
            VElement v   = getChildElementVector(ElementName.CONTACT, null, null, true, 0, true);
            VElement v2  = new VElement();
            int      siz = v.Count;

            for (int i = 0; i < siz; i++)
            {
                JDFContact contact      = (JDFContact)v[i];
                VString    contactTypes = contact.getContactTypes();
                if (contactTypes.Contains(contactType))
                {
                    v2.Add(contact);
                }
            }
            return(v2.Count > 0 ? v2 : null);
        }
示例#22
0
        public virtual void testUnify()
        {
            XMLDoc   d  = new XMLDoc("doc", null);
            KElement e  = d.getRoot();
            KElement e1 = e.appendElement("e1");

            e1.setAttribute("a", "b");
            VElement v = new VElement();

            v.Add(e1);
            v.Add(e1);
            e1 = e.appendElement("e1");
            e1.setAttribute("a", "b");
            v.Add(e1);
            Assert.AreEqual(3, v.Count);
            v.unify();
            Assert.AreEqual(2, v.Count);
            v.unifyElement();
            Assert.AreEqual(1, v.Count);
        }
示例#23
0
        /// <summary>
        /// Check if all the elements in the list are in this VElement instance
        /// </summary>
        /// <param name="list">VElement list</param>
        /// <returns>true if all of the Elements in the list are in this VElement instance</returns>
        public virtual bool ContainsAll(VElement list)
        {
            if (list == null)
            {
                return(true);
            }

            if (list.Count > this.Count)
            {
                return(false);
            }

            foreach (KElement item in list)
            {
                if (!this.Contains(item))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#24
0
        ///
        ///	 <summary> * ToVector - parse a node list for elements spezified through parameters note that the vector is static - i.e. the
        ///	 * elements are NOT modified by operations to the nodeList. This behavior is different than that of the actual
        ///	 * nodelist!
        ///	 *  </summary>
        ///	 * <param name="element"> name of the element typ you want </param>
        ///	 * <param name="mAttrib"> a attribute typ you want </param>
        ///	 * <param name="bAnd"> true, if you want to add the element if mAttrib was found in the element </param>
        ///	 * <param name="nameSpaceURI"> the namespace to search in </param>
        ///	 * <returns> VElement - vector of all elements matching the conditions above </returns>
        ///
        public virtual VElement toVector(string element, JDFAttributeMap mAttrib, bool bAnd, string nameSpaceURI)
        {
            VElement v         = new VElement();
            bool     bWantName = KElement.isWildCard(element);
            bool     bWantNS   = KElement.isWildCard(nameSpaceURI);

            // loop over the list
            int len = Count;

            // optimize -> walk tree once to set it up!
            if (len > 0)
            {
                KElement temp = this[len - 1];
            }
            for (int i = 0; i < len; i++)
            {
                KElement k = this[i];
                if (bWantName)
                {
                    // want only named elements
                    if (!k.Name.Equals(element))
                    {
                        continue;
                    }
                }
                if (bWantNS)
                {
                    // want only named elements
                    if (!k.getNamespaceURI().Equals(nameSpaceURI))
                    {
                        continue;
                    }
                }
                if (k.includesAttributes(mAttrib, bAnd))
                {
                    v.Add(k);
                }
            }
            return(v);
        }
示例#25
0
        public virtual void testGetChildElementVector_or()
        {
            JDFDoc          d       = new JDFDoc("AmountPool");
            JDFAmountPool   ap      = (JDFAmountPool)d.getRoot();
            JDFAttributeMap partMap = new JDFAttributeMap("a", "a1");

            partMap.put("b", "b1");
            JDFPartAmount pa1 = ap.appendPartAmount();

            pa1.setAttributes(partMap);
            partMap.put("a", "a2");
            partMap.put("b", "b2");
            JDFPartAmount pa2 = ap.appendPartAmount();

            pa2.setAttributes(partMap);
            VElement v = ap.getChildElementVector(ElementName.PARTAMOUNT, null, partMap, false, 0, false);

            Assert.AreEqual(1, v.Count);
            partMap.put("b", "b1");
            v = ap.getChildElementVector(ElementName.PARTAMOUNT, null, partMap, false, 0, false);
            Assert.AreEqual(2, v.Count);
        }
示例#26
0
        public virtual void testgetContactVector()
        {
            JDFDoc          doc  = new JDFDoc("JDF");
            JDFCustomerInfo info = prepareInfo(doc);

            VElement v = null;

            info = doc.getJDFRoot().getCustomerInfo();
            if (info != null)
            {
                v = info.getChildElementVector(ElementName.CONTACT, null, null, true, 0, false);
                Assert.AreEqual(4, v.Count, "v does not contain 4 contact");
            }

            v    = null;
            info = doc.getJDFRoot().getCustomerInfo();
            if (info != null)
            {
                v = info.getChildElementVector(ElementName.CONTACT, null, null, true, 0, false);
                Assert.IsTrue(v.Count == 4, "v does not contain 4 contacts");
            }
        }
示例#27
0
        ///
        ///	 <summary> * remove duplicate warnings from the list and set schemaloction
        ///	 *  </summary>
        ///	 * <param name="schemaLocation"> </param>
        ///
        public virtual void cleanXML(string schemaLocation)
        {
            VElement v = root.getChildElementVector(null, null, null, true, 0, false);

            v.unifyElement();
            root.removeChildren(null, null, null);
            int size = v.Count;

            for (int i = 0; i < size; i++)
            {
                root.appendChild(v.item(i));
            }
            if (schemaLocation == null)
            {
                root.setAttribute("ValidationResult", "NotPerformed");
            }
            else
            {
                root.setAttribute("SchemaLocation", schemaLocation);
                if (root.hasChildElement("FatalError", null))
                {
                    root.setAttribute("ValidationResult", "FatalError");
                }
                else if (root.hasChildElement("Error", null))
                {
                    root.setAttribute("ValidationResult", "Error");
                }
                else if (root.hasChildElement("Warning", null))
                {
                    root.setAttribute("ValidationResult", "Warning");
                }
                else
                {
                    root.setAttribute("ValidationResult", "Valid");
                }
            }
        }
示例#28
0
        ///
        ///	 <summary> * inline this refElement by replacing it with a copy of its target
        ///	 *  </summary>
        ///	 * <returns> JDFElement - the newly created element </returns>
        ///
        public virtual JDFElement inlineRef()
        {
            int         i;
            JDFResource targetRes = getTarget();

            if (targetRes == null)
            {
                throw new JDFException("inlineRef: inlining null refElement rRef=" + getrRef());
            }
            JDFResource newInline = (JDFResource)appendElement(targetRes.Name, null);

            // copy elements and attributes
            newInline.setAttributes(targetRes);
            VElement v = targetRes.getChildElementVector(null, null, null, true, 0, false);

            for (i = 0; i < v.Count; i++)
            {
                newInline.copyElement(v.item(i), null);
            }

            newInline.cleanResourceAttributes();
            VString partNames = targetRes.getPartIDKeys();

            for (i = 0; i < partNames.Count; i++)
            {
                newInline.removeAttribute(partNames[i], null);
            }

            // replace this (the refElement) with newInline.
            // This effectively repositions newInline from the back to the original
            // position of this
            replaceElement(newInline);

            targetRes.deleteUnLinked();
            return(newInline);
        }
示例#29
0
 ///
 ///	 <summary> * are the two vectors equivalent, i.e. do thay only contain elements that are isEqual() or if this is empty and the
 ///	 * comparison is against null
 ///	 *  </summary>
 ///    * <param name="other"> the vector to compare </param>
 ///	 * <returns> true, if v is equal to this </returns>
 ///
 public bool Equals(VElement other)
 {
     return(!Object.ReferenceEquals(other, null) &&
            (Object.ReferenceEquals(this, other) ||
             (GetType() == other.GetType() && isEqual(other))));
 }
示例#30
0
 ///
 ///	 <summary> * constructor
 ///	 *  </summary>
 ///	 * <param name="m"> </param>
 ///
 public VElement(VElement m)
     : base()
 {
     addAll(m);
 }