/// <summary>
        /// Sets the value of this field
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <returns></returns>

        public override SimpleField SetField(IElementDef id, SifSimpleType value)
        {
            // verify the parameter values
            if (id == null || !(CommonDTD.PARTIALDATETYPE.Name.Equals(id.Name)))
            {
                throw new ArgumentException("ElementDef must be CommonDTD.PARTIALDATETYPE");
            }
            if (value != null && value.DataType != SifDataType.String)
            {
                throw new ArgumentException("Value type must be SIFDataType.STRING");
            }

            // Allow any datatype to be set, but convert it to a string
            // This is important, because the value of this could be set to
            // an int from mappings, because it was an int in SIF 1.5
            if (value != null && value.DataType != SifDataType.String)
            {
                value = new SifString(value.ToString());
            }
            // Parse the text value into its representative parts
            SimpleField returnValue = base.SetField(id, value);

            parseTextValue();
            return(returnValue);
        }
Example #2
0
        public void TestxsiNill_SDOObjectXML()
        {
            LearnerPersonal lp = new LearnerPersonal();

            // Add a null UPN
            SifString str = new SifString(null);

            lp.SetField(LearnerDTD.LEARNERPERSONAL_UPN, str);

            // Add a null AlertMsg
            AlertMsg msg = new AlertMsg(AlertMsgType.DISCIPLINE, null);

            lp.AlertMsgList = new AlertMsgList(msg);
            msg.SetField(CommonDTD.ALERTMSG, new SifString(null));



            //  Write the object to a file
            Console.WriteLine("Writing to file...");
            using (Stream fos = File.Open("SifWriterTest.Temp.xml", FileMode.Create, FileAccess.Write))
            {
                SifWriter writer = new SifWriter(fos);
                lp.SetChanged(true);
                writer.Write(lp);
                writer.Flush();
                fos.Close();
            }

            //  Parse the object from the file
            Console.WriteLine("Parsing from file...");
            SifParser p = SifParser.NewInstance();

            using (Stream fis = File.OpenRead("SifWriterTest.Temp.xml"))
            {
                lp = (LearnerPersonal)p.Parse(fis, null);
            }


            SimpleField upn = lp.GetField(LearnerDTD.LEARNERPERSONAL_UPN);

            Assert.IsNotNull(upn);

            SifString rawValue = (SifString)upn.SifValue;

            Assert.IsNotNull(rawValue);
            Assert.IsNull(rawValue.Value);
            Assert.IsNull(upn.Value);

            AlertMsgList alertMsgs = lp.AlertMsgList;

            Assert.IsNotNull(alertMsgs);
            Assert.IsTrue(alertMsgs.Count == 1);
            msg = (AlertMsg)alertMsgs.GetChildList()[0];

            Assert.IsNull(msg.Value);
            SifSimpleType msgValue = msg.SifValue;

            Assert.IsNotNull(msgValue);
            Assert.IsNull(msgValue.RawValue);
        }
        public override INodePointer CreateChild(SifXPathContext context, string name, int i)
        {
            SifVersion   version    = Version;
            IElementDef  subEleDef  = GetChildDef(name);
            SifFormatter formatter  = Adk.Dtd.GetFormatter(version);
            SifElement   sifElement = (SifElement)fElement;

            // Check to see if this child has a render surrogate defined
            IRenderSurrogate rs = subEleDef.GetVersionInfo(version).GetSurrogate();

            if (rs != null)
            {
                return(rs.CreateChild(this, formatter, version, context));
            }

            if (subEleDef.Field)
            {
                SifSimpleType ssf = subEleDef.TypeConverter.GetSifSimpleType(null);
                SimpleField   sf  = formatter.SetField(sifElement, subEleDef, ssf, version);
                return(SimpleFieldPointer.Create(this, sf));
            }
            else
            {
                SifElement newEle = SifElement.Create(sifElement, subEleDef);
                formatter.AddChild(sifElement, newEle, version);
                return(new SifElementPointer(this, newEle, version));
            }
        }
Example #4
0
        public SifSimpleType Evaluate(SifXPathContext xpathContext, SifVersion version, bool returnDefault)
        {
            SifSimpleType value = null;

            if (fRule != null)
            {
                value = fRule.Evaluate(xpathContext, version);
            }
            if (value == null && fDefValue != null && returnDefault)
            {
                // TODO: Support all data types
                try
                {
                    return(SifTypeConverters.GetConverter(fDatatype).Parse(Adk.TextFormatter, fDefValue));
                }
                catch (AdkParsingException adkpe)
                {
                    throw new AdkSchemaException(
                              "Error parsing default value: '" + fDefValue + "' for field " + fField + " : " + adkpe, null,
                              adkpe);
                }
            }

            return(value);
        }
Example #5
0
 /// <summary>
 /// Adds a SimpleField parsed from a specific version of SIF to the parent.
 /// </summary>
 /// <param name="contentParent">The element to add content to</param>
 /// <param name="fieldDef">The metadata definition of the field to set</param>
 /// <param name="data">The value to set to the field</param>
 /// <param name="version">The version of SIF that the SIFElement is being constructed
 /// from</param>
 /// <returns></returns>
 public override SimpleField SetField(SifElement contentParent,
                                      IElementDef fieldDef,
                                      SifSimpleType data,
                                      SifVersion version)
 {
     return(GetContainer(contentParent, fieldDef, version).SetField(fieldDef, data));
 }
Example #6
0
 private object ExtractRawValue(SifSimpleType data)
 {
     if (data == null)
     {
         return(null);
     }
     return(data.RawValue);
 }
Example #7
0
        public override void SetValue(object rawValue)
        {
            SifElementPointer immediateParent = (SifElementPointer)Parent;
            SifElement        parentElement   = immediateParent.Element as SifElement;
            SifSimpleType     sst             = GetSIFSimpleTypeValue(fElementDef, rawValue);

            parentElement.SetField(fElementDef, sst);
        }
 /// <summary>
 /// Sets the specified value
 /// </summary>
 /// <param name="fieldName"></param>
 /// <param name="resultingValue"></param>
 /// <param name="mapping"></param>
 public void SetSifValue(String fieldName, SifSimpleType resultingValue, FieldMapping mapping)
 {
     if (fOverwriteValues || !fMap.Contains(fieldName))
     {
         Object mapValue = ToMapValue(resultingValue);
         fMap[fieldName] = mapValue;
     }
 }
Example #9
0
        /// <summary>
        /// Sets a value that has been retrieved from a SIF Element in an inbound field
        /// mapping operation.
        /// </summary>
        /// <param name="fieldName">The field name that is mapped to a SIFElement</param>
        /// <param name="value">The value of the SIF element</param>
        /// <param name="mapping">The FieldMappings that will be used to set this value or null</param>
        public override void SetSifValue(string fieldName, SifSimpleType value, FieldMapping mapping)
        {
            int ordinal = SafeGetOrdinal(fieldName);

            if (ordinal > -1)
            {
                fDataRow[ordinal] = value.RawValue;
            }
        }
Example #10
0
        protected SifSimpleType GetSIFSimpleTypeValue(IElementDef def, object rawValue)
        {
            if (rawValue is SifSimpleType)
            {
                return((SifSimpleType)rawValue);
            }
            SifSimpleType sst = def.TypeConverter.GetSifSimpleType(rawValue);

            return(sst);
        }
Example #11
0
        private void assertByXPath(SifXPathContext context, String xPath,
                                   String assertedValue)
        {
            Element e = (Element)context.GetValue(xPath);

            Assertion.AssertNotNull("Field is null for path " + xPath, e);
            SifSimpleType value = e.SifValue;

            Assertion.AssertNotNull("Value is null for path " + xPath, value);
            Assertion.AssertEquals(xPath, assertedValue, value.ToString());
        }
Example #12
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));
        }
Example #13
0
        public void testCourseCodeSIF15r1()
        {
            Adk.SifVersion = SifVersion.SIF15r1;
            SchoolCourseInfo sci = new SchoolCourseInfo();

            sci.SetCourseCredits(CreditType.C0108_0585, 2);

            SifXPathContext spc   = SifXPathContext.NewSIFContext(sci);
            Element         value = (Element)spc.GetValue("CourseCredits[@Code='0585']");

            SifSimpleType elementValue = value.SifValue;

            Assertion.AssertNotNull("Value by XPath", elementValue);
            Assertion.AssertEquals("Value By XPath", 2, elementValue.RawValue);
        }
Example #14
0
        protected void SetFieldValue(Element field, Object value)
        {
            SifSimpleType sifValue = null;

            if (value is SifSimpleType)
            {
                sifValue = (SifSimpleType)value;
            }
            else
            {
                sifValue = field.ElementDef.TypeConverter.GetSifSimpleType(value);
            }

            field.SifValue = sifValue;
        }
        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);
        }
 /// <summary>
 /// Converts a SIF datatype value to the java native type to be stored
 /// in the Map. The default implementation of this class stores the
 /// native Java value, but subclasses can override this method to convert
 /// the value to the form they want to use.
 /// </summary>
 /// <param name="value">The SIF value to stored in the Map</param>
 /// <returns>The converted value stored in the Map</returns>
 protected virtual Object ToMapValue(SifSimpleType value)
 {
     return(value.RawValue);
 }
 /// <summary>
 /// Converts a SIF datatype value to the java native type to be stored
 /// in the Map. The default implementation of this class stores the
 /// native Java value, but subclasses can override this method to convert
 /// the value to the form they want to use. 
 /// </summary>
 /// <param name="value">The SIF value to stored in the Map</param>
 /// <returns>The converted value stored in the Map</returns>
 protected virtual Object ToMapValue(SifSimpleType value)
 {
     return value.RawValue;
 }
 /// <summary>
 /// Sets the specified value
 /// </summary>
 /// <param name="fieldName"></param>
 /// <param name="resultingValue"></param>
 /// <param name="mapping"></param>
 public void SetSifValue(String fieldName, SifSimpleType resultingValue, FieldMapping mapping)
 {
     if (fOverwriteValues || !fMap.Contains(fieldName))
     {
         Object mapValue = ToMapValue(resultingValue);
         fMap[fieldName] = mapValue;
     }
 }
Example #19
0
 /// <summary>
 /// Adds a SimpleField parsed from a specific version of SIF to the parent.
 /// </summary>
 /// <param name="contentParent">The element to add content to</param>
 /// <param name="fieldDef">The metadata definition of the field to set</param>
 /// <param name="data">The value to set to the field</param>
 /// <param name="version">The version of SIF that the SIFElement is being constructed
 /// from</param>
 /// <returns></returns>
 public override SimpleField SetField(SifElement contentParent,
     IElementDef fieldDef,
     SifSimpleType data,
     SifVersion version)
 {
     return GetContainer(contentParent, fieldDef, version).SetField(fieldDef, data);
 }
        public override void SetValue(object rawValue)
        {
            SifSimpleType sst = GetSIFSimpleTypeValue(fElementDef, rawValue);

            fElement.SifValue = sst;
        }
Example #21
0
 /// <summary>
 /// Sets a value that has been retrieved from a SIF Element in an inbound field
 /// mapping operation.
 /// </summary>
 /// <param name="fieldName">The field name that is mapped to a SIFElement</param>
 /// <param name="value">The value of the SIF element</param>
 /// <param name="mapping">The FieldMappings that will be used to set this value or null</param>
 public override void SetSifValue(string fieldName, SifSimpleType value, FieldMapping mapping)
 {
     int ordinal = SafeGetOrdinal(fieldName);
     if( ordinal > -1 )
     {
         fDataRow[ordinal] = value.RawValue;
     }
 }
Example #22
0
 /// <summary>
 /// Sets a value that has been retrieved from a SIF Element in an inbound field
 /// mapping operation.
 /// </summary>
 /// <param name="fieldName">The field name that is mapped to a SIFElement</param>
 /// <param name="value">The value of the SIF element</param>
 /// <param name="mapping">The FieldMappings that will be used to set this value or null</param>
 public abstract void SetSifValue(string fieldName, SifSimpleType value, FieldMapping mapping);
 /// <summary>
 /// Sets a value that has been retrieved from a SIF Element in an inbound field
 /// mapping operation.
 /// </summary>
 /// <param name="fieldName">The field name that is mapped to a SIFElement</param>
 /// <param name="value">The value of the SIF element</param>
 /// <param name="mapping">The FieldMappings that will be used to set this value or null</param>
 public void SetSifValue(string fieldName, SifSimpleType value, FieldMapping mapping)
 {
     throw new NotSupportedException("Unable to set values to a DataReader");
 }
Example #24
0
 /// <summary>
 /// Sets a value that has been retrieved from a SIF Element in an inbound field
 /// mapping operation.
 /// </summary>
 /// <param name="fieldName">The field name that is mapped to a SIFElement</param>
 /// <param name="value">The value of the SIF element</param>
 /// <param name="mapping">The FieldMappings that will be used to set this value or null</param>
 public abstract void SetSifValue(string fieldName, SifSimpleType value, FieldMapping mapping);
Example #25
0
        public bool ReadRaw(
            XmlReader reader,
            SifVersion version,
            SifElement parent,
            SifFormatter formatter)
        {
            String value = null;

            //
            // STEP 1
            // Determine if this surrogate can handle the parsing of this node.
            // Retrieve the node value as a string
            //

            String[]    xPathParts = fLegacyXpath.Split('/');
            XmlNodeType eventType  = reader.NodeType;
            String      localName  = reader.LocalName;

            if (eventType == XmlNodeType.Element &&
                localName.Equals(xPathParts[0]))
            {
                try
                {
                    int currentSegment = 0;
                    int lastSegment    = xPathParts.Length - 1;
                    if (xPathParts[lastSegment].StartsWith("@"))
                    {
                        lastSegment--;
                    }
                    while (currentSegment < lastSegment)
                    {
                        reader.Read();
                        currentSegment++;

                        if (!reader.LocalName.Equals(xPathParts[currentSegment]))
                        {
                            ThrowParseException
                                ("Element {" + reader.LocalName +
                                "} is not supported by XPathSurrogate path " + fLegacyXpath,
                                version);
                        }
                    }

                    // New we are at the last segment in the XPath, and the XMLStreamReader
                    // should be positioned on the proper node. The last segment is either
                    // an attribute or an element, which need to be read differently
                    String finalSegment = xPathParts[xPathParts.Length - 1];
                    if (finalSegment.StartsWith("@"))
                    {
                        value = reader.GetAttribute(finalSegment.Substring(1));
                    }
                    else
                    {
                        value = ReadElementTextValue(reader);
                    }

                    // Note: Unlike the Java ADK, Surrogates in the the .NET ADK do not have to worry about
                    // completely consuming the XMLElement and advancing to the next tag. The .NET
                    // Surrogates are handed a reader that only allows reading the current node and
                    // the parent reader is automatically advanced when the surrogate is done.
                }
                catch (Exception xse)
                {
                    ThrowParseException(xse, reader.LocalName, version);
                }
            }
            else
            {
                // No match was found
                return(false);
            }

            //
            // STEP 2
            // Find the actual field to set the value to
            //
            IElementDef fieldDef;
            SifElement  targetElement = parent;

            if (fValueXpath.Equals(".") && fElementDef.Field)
            {
                fieldDef = fElementDef;
            }
            else
            {
                //	This indicates a child SifElement that needs to be created
                try
                {
                    targetElement = SifElement.Create(parent, fElementDef);
                }
                catch (AdkSchemaException adkse)
                {
                    ThrowParseException(adkse, reader.LocalName, version);
                }

                formatter.AddChild(parent, targetElement, version);

                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 InvalidOperationException
                          ("Support for value path {" + fValueXpath +
                          "} is not supported by XPathSurrogate.");
            }


            //
            // STEP 3
            // Set the value to the field
            //
            TypeConverter converter = fieldDef.TypeConverter;

            if (converter == null)
            {
                // TODO: Determine if we should be automatically creating a converter
                // for elementDefs that don't have one, or whether we should just throw the
                // spurious data away.
                converter = SifTypeConverters.STRING;
            }
            SifSimpleType data = converter.Parse(formatter, value);

            targetElement.SetField(fieldDef, data);

            return(true);
        }
Example #26
0
 private object ExtractRawValue( SifSimpleType data )
 {
     if ( data == null )
     {
         return null;
     }
     return data.RawValue;
 }
Example #27
0
 /// <summary>
 /// Sets the value to the underlying dictionary using a SifFormatter
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 protected override Object ToMapValue(SifSimpleType value)
 {
     // Store items in the map using a string value
     return(value.ToString(fDataFormatter));
 }
Example #28
0
 /// <summary>
 /// Sets a value that has been retrieved from a SIF Element in an inbound field
 /// mapping operation.
 /// </summary>
 /// <param name="fieldName">The field name that is mapped to a SIFElement</param>
 /// <param name="value">The value of the SIF element</param>
 /// <param name="mapping">The FieldMappings that will be used to set this value or null</param>
 public void SetSifValue(string fieldName, SifSimpleType value, FieldMapping mapping)
 {
     throw new NotSupportedException("Unable to set values to a DataReader");
 }