Ejemplo n.º 1
0
        /// <summary>
        /// Creates a child element, if supported by this node
        /// </summary>
        /// <param name="parentPointer"></param>
        /// <param name="formatter"></param>
        /// <param name="version"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public INodePointer CreateChild(INodePointer parentPointer, SifFormatter formatter, SifVersion version,
                                        SifXPathContext context)
        {
            // 1) Create an instance of the SimpleField with a null value (It's assigned later)

            //
            // STEP 2
            // Find the actual field to set the value to
            //
            SifElement parent        = (SifElement)((SifElementPointer)parentPointer).Element;
            SifElement targetElement = parent;

            if (!fElementDef.Field)
            {
                //	This indicates a child SifElement that needs to be created
                targetElement = SifElement.Create(parent, fElementDef);

                formatter.AddChild(parent, targetElement, version);
            }

            IElementDef fieldDef = null;

            if (fValueXpath.Equals("."))
            {
                fieldDef = fElementDef;
            }
            else
            {
                String fieldName = fValueXpath;
                if (fValueXpath.StartsWith("@"))
                {
                    fieldName = fValueXpath.Substring(1);
                }
                fieldDef = Adk.Dtd.LookupElementDef(fElementDef, fieldName);
            }


            if (fieldDef == null)
            {
                throw new ArgumentException("Support for value path {" + fValueXpath +
                                            "} is not supported by XPathSurrogate.");
            }

            SifSimpleType ssf = fieldDef.TypeConverter.GetSifSimpleType(null);
            SimpleField   sf  = ssf.CreateField(targetElement, fieldDef);

            targetElement.SetField(sf);


            // 2) built out a fake set of node pointers representing the SIF 1.5r1 path and
            //    return the root pointer from that stack
            return(BuildLegacyPointers(parentPointer, sf));
        }
Ejemplo n.º 2
0
        public override INodePointer CreateAttribute(SifXPathContext context, String name)
        {
            IElementDef subEleDef  = GetChildDef(name);
            SifElement  sifElement = (SifElement)fElement;

            if (subEleDef.Field)
            {
                SifSimpleType ssf = subEleDef.TypeConverter.GetSifSimpleType(null);
                SimpleField   sf  = ssf.CreateField(sifElement, subEleDef);
                sifElement.SetField(sf);
                return(SimpleFieldPointer.Create(this, sf));
            }

            throw new ArgumentException(
                      "Factory could not create a child node for path: " + Name
                      + "/" + name);
        }