Ejemplo n.º 1
0
        ///
        ///	 <summary> * get a span, create it if it does not exist
        ///	 *  </summary>
        ///	 * <param name="String">
        ///	 *            strName name of the span element </param>
        ///	 * <param name="JDFSpanBase">
        ///	 *            ::EnumDataType nType datatype of the new span </param>
        ///	 * <returns> JDFSpanBase the JDFSpanBase </returns>
        ///
        internal virtual JDFSpanBase getCreateSpan(string strName, JDFSpanBase.EnumDataType nType)
        {
            // / note that this is the inherited version from JDFResource!
            JDFSpanBase e = (JDFSpanBase)this.getCreateElement_JDFResource(strName, JDFConstants.EMPTYSTRING, 0);

            e.setDataType(nType);
            return(e);
        }
Ejemplo n.º 2
0
        ///
        ///	 <summary> * Append a span if it does not yet exist, else return the existing element
        ///	 *  </summary>
        ///	 * <param name="String">
        ///	 *            strName name of the span element </param>
        ///	 * <param name="JDFSpanBase">
        ///	 *            .EnumDataType nType datatype of the new span </param>
        ///	 * <returns> JDFSpanBase the JDFSpanBase </returns>
        ///
        public virtual JDFSpanBase appendSpan(string strName, JDFSpanBase.EnumDataType nType)
        {
            // / note that this is the inherited version from JDFResource!
            JDFSpanBase e = (JDFSpanBase)appendElement(strName, JDFConstants.EMPTYSTRING);

            if (nType != null)
            {
                e.setDataType(nType);
            }
            return(e);
        }
Ejemplo n.º 3
0
        ///
        ///	 <summary> * get a span
        ///	 *  </summary>
        ///	 * <param name="String">
        ///	 *            strName name of the span element </param>
        ///	 * <returns> JDFSpanBase the JDFSpanBase </returns>
        ///
        public virtual JDFSpanBase getSpan(string strName, JDFSpanBase.EnumDataType nType)
        {
            // / note that this is the inherited version from JDFResource!
            JDFSpanBase e = (JDFSpanBase)getElement(strName, JDFConstants.EMPTYSTRING, 0);

            if (e != null && nType != null)
            {
                JDFSpanBase.EnumDataType dataType = e.getDataType();
                if (!dataType.Equals(nType))
                {
                    throw new JDFException("JDFIntentResource.getSpan incompatible datatypes" + e.getAttribute(AttributeName.DATATYPE));
                }
            }
            return(e);
        }
Ejemplo n.º 4
0
        ///
        ///	 <summary> * set actual values to the preset defined in preferred
        ///	 *  </summary>
        ///	 * <param name="String">
        ///	 *            key the key of the span resource to modify, if null do all </param>
        ///	 * <returns> number of elements modified </returns>
        ///
        public virtual int preferredToActual(string key)
        {
            int nDone = 0;

            if (!isLeaf())
            {
                VElement leaves = getLeaves(false);
                for (int i = 0; i < leaves.Count; i++)
                {
                    JDFIntentResource ri = (JDFIntentResource)leaves[i];
                    nDone += ri.preferredToActual(key);
                }
                return(nDone);
            }
            VString vKeys = new VString();

            if (KElement.isWildCard(key))
            {
                VElement v = getChildrenByTagName(null, null, new JDFAttributeMap(AttributeName.DATATYPE, (string)null), true, true, 0);
                for (int i = 0; i < v.Count; i++)
                {
                    vKeys.Add(v[i].Name);
                }
            }
            else
            {
                vKeys.Add(key);
            }
            for (int i = 0; i < vKeys.Count; i++)
            {
                JDFSpanBase @base = (JDFSpanBase)getElement(vKeys[i], JDFConstants.EMPTYSTRING, 0);
                if (@base.preferredToActual())
                {
                    nDone++;
                }
            }
            return(nDone);
        }
Ejemplo n.º 5
0
        ///
        ///	 <summary> * set the default values specified in this in element
        ///	 *  </summary>
        ///	 * <param name="element">
        ///	 *            the element to set the defaults on </param>
        ///	 * <returns> true if successful </returns>
        ///
        public virtual bool setDefaultsFromCaps(KElement element, bool bAll)
        {
            string def = getAttribute(AttributeName.DEFAULTVALUE, null, null);

            if (!bAll && def == null)
            {
                return(false);
            }
            if (def == null)
            {
                def = getAttribute(AttributeName.CURRENTVALUE, null, null);
            }

            if (def == null)
            {
                def = getAttribute(AttributeName.ALLOWEDVALUELIST, null, null);
                if (def != null && (def.IndexOf("~") >= 0 || def.IndexOf(" ") >= 0)) // allowedvaluelist
                // is
                // a
                // list
                // or
                // range
                {
                    string lt = getListType().getName();
                    if (!lt.EndsWith("List") && def.IndexOf(" ") >= 0)
                    {
                        def = StringUtil.token(def, 0, " ");
                    }
                    else if (lt.IndexOf("Range") < 0 && def.IndexOf("~") >= 0)
                    {
                        def = null;
                    }
                }
                if (def == null)
                {
                    def = getXPathAttribute("Value/@AllowedValue", null);
                }
            }
            if (def == null)
            {
                if ((this is JDFIntegerState) || (this is JDFNumberState))
                {
                    def = "1";
                }
                else if (this is JDFXYPairState)
                {
                    def = "1 1";
                }
                else if (this is JDFBooleanState)
                {
                    def = "true";
                }
                else if (this is JDFMatrixState)
                {
                    def = JDFMatrix.unitMatrix.ToString();
                }
                else if (this is JDFShapeState)
                {
                    def = "1 2 3";
                }
                else if (this is JDFDateTimeState)
                {
                    def = new JDFDate().DateTimeISO;
                }
                else if (this is JDFDurationState)
                {
                    def = new JDFDuration(42).getDurationISO();
                }
                else
                {
                    def = "some_value"; // TODO add better type dependent value
                    // generator
                }
            }
            object theValue = getMatchingObjectInNode(element);

            if (theValue != null)
            {
                return(false);
            }

            string nam   = getName();
            string nsURI = getDevNS();

            if (nsURI.Equals(JDFElement.getSchemaURL()))
            {
                nsURI = null;
            }
            if (nsURI != null)
            {
                string prefix = KElement.xmlnsPrefix(nam);
                if (prefix == null)
                {
                    nam = StringUtil.token(nsURI, -1, "/") + ":" + nam;
                }
            }

            if (getListType().Equals(EnumListType.Span))
            {
                JDFIntentResource ir   = (JDFIntentResource)element;
                JDFSpanBase       span = ir.appendSpan(nam, null);
                span.setAttribute(AttributeName.PREFERRED, def);
            }
            else
            // some attribute...
            {
                element.setAttribute(nam, def, nsURI);
            }
            return(true);
        }