示例#1
0
            ///
            ///		 <summary> * apply the parameters in this to all appropriate resources in parentNode or one of parentNode's children
            ///		 *  </summary>
            ///		 * <param name="parentNode"> the node to search in </param>
            ///
            internal virtual void applyResourceCommand(JDFNode parentNode)
            {
                if (parentNode == null)
                {
                    return;
                }

                VElement vNodes = parentNode.getvJDFNode(null, null, false);

                int size = vNodes.Count;

                for (int i = 0; i < size; i++)
                {
                    JDFNode node = (JDFNode)vNodes[i];
                    if (!matchesNode(node))
                    {
                        continue;
                    }
                    JDFResource resCmd = enclosingInstance.getResource(null);
                    if (resCmd == null)
                    {
                        continue;
                    }

                    bool isIncremental = (enclosingInstance.getUpdateMethod() == EnumUpdateMethod.Incremental);

                    // commented out, statements have no effect
                    // double dAmount = -1.0;
                    // if (hasAttribute (AttributeName.PRODUCTIONAMOUNT))
                    // {
                    // dAmount = getProductionAmount (); // TODO: set ProductionAmount
                    // }
                    // final String strProcessUsage = getProcessUsage(); // TODO: use
                    // ProcessUsage
                    // final JDFElement.EnumNodeStatus status = getStatus(); // TODO:
                    // set Status

                    VJDFAttributeMap vamParts  = enclosingInstance.getPartMapVector();
                    JDFResource      resTarget = getTargetResource(node);
                    if (resTarget == null)
                    {
                        resTarget = createNewResource(node, resCmd);
                        if (resTarget == null)
                        {
                            continue;
                        }
                    }

                    // get the most granular list of partIDKeys from the cmd or resource
                    VString vsPartIDKeys    = resTarget.getPartIDKeys();
                    VString vsPartIDKeysCmd = resCmd.getPartIDKeys();
                    int     sizTarget       = vsPartIDKeys == null ? 0 : vsPartIDKeys.Count;
                    int     sizCmd          = vsPartIDKeysCmd == null ? 0 : vsPartIDKeysCmd.Count;
                    if (sizCmd > sizTarget)
                    {
                        vsPartIDKeys = vsPartIDKeysCmd;
                    }

                    int sizeParts = vamParts == null ? 1 : vamParts.Count;
                    for (int j = 0; j < sizeParts; j++)
                    {
                        JDFAttributeMap amParts       = vamParts == null ? null : vamParts[j];
                        JDFResource     resTargetPart = resTarget.getCreatePartition(amParts, vsPartIDKeys);
                        if (resTargetPart == null)
                        {
                            continue;
                        }

                        string id = resTargetPart.getID();
                        if (!isIncremental)
                        {
                            JDFAttributeMap map = resTargetPart.getPartMap();
                            resTargetPart.flush();
                            resTargetPart.setAttributes(map);
                        }

                        JDFResource     resCmdPart = resCmd.getPartition(amParts, EnumPartUsage.Implicit);
                        JDFAttributeMap map2       = resCmdPart.getAttributeMap();
                        VString         keys       = map2.getKeys();
                        if (keys != null)
                        {
                            int keySize = keys.Count;
                            for (int k = 0; k < keySize; k++)
                            {
                                string key    = keys[k];
                                string @value = map2.get(key);
                                if (@value == null || JDFConstants.EMPTYSTRING.Equals(@value))
                                {
                                    resCmdPart.removeAttribute(key);
                                    resTargetPart.removeAttribute(key);
                                }
                            }
                        }

                        resTargetPart.mergeElement(resCmdPart, false);
                        resTarget.setID(id);
                    }

                    if (sizeParts > 0 && resTarget is JDFNodeInfo)
                    {
                        fixNodeStatusFromNodeInfo(node, resTarget);
                    }
                }
            }
示例#2
0
        ///
        ///	 <summary> * append elements to the node that match this DevCap, if they do not exist
        ///	 * yet
        ///	 *  </summary>
        ///	 * <param name="node">
        ///	 *            the node to append the elements to </param>
        ///	 * <param name="bAll">
        ///	 *            if false, only add if minOccurs>=1 and required=true or a
        ///	 *            default exists
        ///	 *  </param>
        ///	 * <returns> KElement - the last element that was appended </returns>
        ///
        public virtual KElement appendMatchingElementsToNode(JDFNode node, bool bAll, org.cip4.jdflib.util.VectorMap <int, JDFResource> indexResMap, bool bLink)
        {
            KElement e = null;

            EnumContext context = getContext();

            if (!bLink && EnumContext.Link.Equals(context))
            {
                return(null);
            }

            if (bLink && !EnumContext.Link.Equals(context))
            {
                return(null);
            }

            JDFDevCap devCap = getDevCap();

            if (devCap == null)
            {
                return(null);
            }

            int minOcc = devCap.getMinOccurs();

            if (minOcc == 0 && bAll)
            {
                minOcc = 1;
            }

            string nam = getName();

            for (int i = 0; i < minOcc; i++)
            {
                if (context.Equals(EnumContext.Element))
                { // vElem - for a common return type in all cases
                    if (nam.Equals(ElementName.JDF))
                    {
                        // nop - should actually never get here
                    }
                    else
                    {
                        e = node.getCreateElement(nam, getDevNS(), i);
                    }
                }
                else if (context.Equals(EnumContext.Resource) || context.Equals(EnumContext.Link))
                {
                    EnumUsage        linkUsage = getLinkUsage();
                    string           procUsage = getProcessUsage();
                    JDFAttributeMap  map       = new JDFAttributeMap();
                    EnumProcessUsage pu        = null;

                    if (procUsage != null && procUsage.Length > 0)
                    {
                        map.put(AttributeName.PROCESSUSAGE, procUsage);
                        pu = EnumProcessUsage.getEnum(procUsage);
                    }

                    if (linkUsage != null)
                    {
                        map.put(AttributeName.USAGE, linkUsage.getName());
                    }

                    VElement links = node.getResourceLinks(nam, map, null);
                    // now look for the correct combinedprocessindex - remove all
                    // non-matching
                    JDFIntegerRangeList tocNum  = getTypeOccurrenceNum();
                    JDFIntegerList      tocNum2 = tocNum == null ? null : tocNum.getIntegerList();
                    if (links != null && tocNum != null)
                    {
                        for (int ll = links.Count - 1; ll >= 0; ll--)
                        {
                            JDFResourceLink rl = (JDFResourceLink)links[ll];
                            JDFIntegerList  il = rl.getCombinedProcessIndex();
                            if (il == null || !il.Contains(tocNum2))
                            {
                                links.RemoveAt(ll);
                            }
                        }
                    }

                    if (links == null || links.Count <= i)
                    {
                        JDFResource r = null;
                        // get a link hook for the matching combinedprocessindex
                        if (bLink)
                        {
                            int kk = (tocNum2 == null || tocNum2.Count == 0) ? -1 : tocNum2.getInt(0);
                            if (EnumUsage.Input.Equals(linkUsage))
                            {
                                kk--;
                            }
                            List <JDFResource> v = null;
                            indexResMap.TryGetValue(kk, out v);
                            if (v != null)
                            {
                                int sv = v.Count;
                                for (int kkk = 0; kkk < sv; kkk++)
                                {
                                    JDFResource rr = v[kkk];
                                    if (rr.LocalName.Equals(nam))
                                    {
                                        r = rr;
                                        break;
                                    }
                                }
                            }
                        }

                        // we found no matching existing res - make a new one
                        if (r == null)
                        {
                            r = node.addResource(nam, null, linkUsage, pu, null, getDevNS(), null);
                            string id = devCap.getAttribute(AttributeName.ID, null, null);
                            if (id != null)
                            {
                                JDFResourceLink rl = node.getLink(r, linkUsage);

                                r.setID(id);
                                if (rl != null)
                                {
                                    rl.setrRef(id);
                                }
                            }

                            if (tocNum2 == null || tocNum2.Count == 0)
                            {
                                indexResMap.putOne(-1, r); //(new int(-1), r);
                            }
                            else
                            {
                                indexResMap.putOne((int)tocNum2.elementAt(0), r); // only
                            }
                            // support
                            // 1
                            // now
                        }
                        else
                        // preexisting resource - just link it
                        {
                            e = node.linkResource(r, linkUsage, pu);
                        }

                        e = node.getLink(r, linkUsage);
                        if (e != null)
                        {
                            JDFResourceLink rl = (JDFResourceLink)e;
                            rl.setCombinedProcessIndex(tocNum2);
                        }

                        // update partititons
                        JDFEnumerationState pidKeys = devCap.getEnumerationState(AttributeName.PARTIDKEYS);
                        if (pidKeys != null)
                        {
                            VString keys = pidKeys.getAllowedValueList();
                            if (keys != null && keys.Count > 0)
                            {
                                JDFAttributeMap keyMap = new JDFAttributeMap();
                                for (int k = 0; k < keys.Count; k++)
                                {
                                    string sk  = "PartKey" + k;
                                    string key = keys.stringAt(k);
                                    if (key.Equals("RunIndex"))
                                    {
                                        sk = "0~-1";
                                    }
                                    keyMap.put(key, sk);
                                }

                                r.getCreatePartition(keyMap, keys);
                            }
                        }
                    }
                }
                else if (context.Equals(EnumContext.JMF))
                {
                    // TODO __Lena__ ...
                }
            }

            return(e);
        }