private Mappings buildMappings1() { // root Mappings root = new Mappings(); // root.Default Mappings defaults = new Mappings( root, "Default", null, null, null ); root.AddChild( defaults ); // root.Default.StudentPersonal ObjectMapping studentMappings = new ObjectMapping( "StudentPersonal" ); defaults.AddRules( studentMappings ); studentMappings.AddRule( new FieldMapping( "REFID", "@RefId" ) ); // root.Default.MA Mappings massachusetts = new Mappings( defaults, "MA", null, null, null ); defaults.AddChild( massachusetts ); // root.Default.MA.StudentPersonal studentMappings = new ObjectMapping( "StudentPersonal" ); massachusetts.AddRules( studentMappings ); studentMappings.AddRule( new FieldMapping( "LOCALID", "LocalId" ) ); studentMappings.AddRule( new FieldMapping( "FIRSTNAME", "Name[@Type='01']/FirstName" ) ); studentMappings.AddRule( new FieldMapping( "LASTNAME", "Name[@Type='01']/LastName" ) ); // root.Default.MA.Boston Mappings boston = new Mappings( massachusetts, "Boston", null, "Boston", null ); massachusetts.AddChild( boston ); // root.Default.MA.Boston.StudentPersonal studentMappings = new ObjectMapping( "StudentPersonal" ); boston.AddRules( studentMappings ); studentMappings.AddRule( new FieldMapping( "BIRTHDAY", "Demographics/BirthDate" ) ); return root; }
protected internal void Populate(XmlElement node, Mappings parent) { // TODO: We should probably be using a GetElementsby name query here // I think the java implementation might have been doing a recursive search here foreach (XmlElement n in new XmlUtils.XmlElementEnumerator(node)) { if (n.Name.ToUpper() == XML_MAPPINGS.ToUpper()) { // Get the ID string id = n.GetAttribute("id"); // Create a new child Mappings object Mappings mappings = new Mappings(parent, id); mappings.XmlElement = n; if (parent.fChildren == null) { parent.fChildren = new Dictionary<String, Mappings>(); } parent.fChildren[mappings.Id] = mappings; // Set a SifVersion filter if present string ver = n.GetAttribute("sifVersion"); if (ver.Trim().Length > 0) { mappings.SetSIFVersionFilter(ver); } // Set a ZoneId filter if present string zoneIds = n.GetAttribute("zoneId"); if (zoneIds.Trim().Length > 0) { mappings.SetZoneIdFilter(zoneIds); } // Set a SourceId filter if present string sourceIds = n.GetAttribute("sourceId"); if (sourceIds.Trim().Length > 0) { mappings.SetSourceIdFilter(sourceIds); } // Populate the Mappings object with rules Populate(n, mappings); } else { if (n.Name.ToUpper() == XML_OBJECT.ToUpper()) { if (n.ParentNode.Name == XML_MAPPINGS) { string obj = n.GetAttribute(XML_OBJECT); if (obj == null) { throw new AdkConfigException ("<object> element must have an object attribute"); } ObjectMapping om = new ObjectMapping(obj); om.XmlElement = n; parent.AddRules(om, false); PopulateObject(n, om); } } else { if (n.Name.ToUpper() == "PROPERTY") { if (n.ParentNode.Name == XML_MAPPINGS) { parent.SetProperty (n.GetAttribute(AdkXmlConstants.Property.NAME), n.GetAttribute(AdkXmlConstants.Property.VALUE)); } } else { if (n.Name.ToUpper() == "VALUESET") { if (n.ParentNode.Name == XML_MAPPINGS) { ValueSet set_Renamed = new ValueSet (n.GetAttribute("id"), n.GetAttribute("title"), n); parent.AddValueSet(set_Renamed); PopulateValueSet(n, set_Renamed); } } else { Populate(n, parent); } } } } } }
/// <summary> Creates a copy of this Mappings object and adds the copy as a child of /// the specified parent. Note the root Mappings container cannot be copied. /// If this method is called on the root an exception is raised. /// /// This method performs a "deep copy", such that a copy is made of each /// child Mappings, ObjectMapping, FieldMapping, ValueSet, and Property /// instance. /// /// </summary> /// <param name="newParent">The parent Mappings instance /// </param> /// <returns> A "deep copy" of this root Mappings object /// /// </returns> /// <exception cref="OpenADK.Library.Tools.Mapping.AdkMappingException"> AdkMappingException thrown if this method is not called on the /// root Mappings container /// </exception> public Mappings Copy(Mappings newParent) { if (IsRoot()) { throw new AdkMappingException ("Mappings.copy cannot be called on the root Mappings container", null); } // Create a new Mappings instance Mappings m = new Mappings(newParent, fId); // Copy the DOM XmlElement if there is one if (fNode != null && newParent.fNode != null) { m.fNode = (XmlElement) newParent.fNode.OwnerDocument.ImportNode( fNode, false ); } newParent.AddChild( m ); // Copy the filters m.SetSourceIdFilter(SourceIdFilterString); m.SetZoneIdFilter(ZoneIdFilterString); m.SetSIFVersionFilter(SIFVersionFilterString); // Copy all Mappings children if (fChildren != null) { foreach (string key in fChildren.Keys) { Mappings ch = fChildren[key]; m.AddChild(ch.Copy(m)); } } // Copy all ObjectMapping children if (fObjRules != null) { foreach (string key in fObjRules.Keys) { ObjectMapping ch = fObjRules[key]; ObjectMapping copy = ch.Copy(m); m.AddRules(copy, false); // if( m.fNode != null ) // m.fNode.AppendChild( copy.fNode ); } } // Copy fValueSets if (fValueSets != null) { foreach (string key in fValueSets.Keys) { ValueSet vs = fValueSets[key]; m.AddValueSet(vs.Copy(m)); } } // Copy properties if (fProps != null) { foreach (string key in fProps.Keys) { string val = fProps[key]; m.SetProperty(key, val); } } return m; }
public void testCreateMappings() { // Create the root instance Mappings root = new Mappings(); // Create the default set of universal mappings Mappings defaults = new Mappings( root, "Default" ); root.AddChild( defaults ); // Create an ObjectMapping for StudentPersonal ObjectMapping studentMappings = new ObjectMapping( "StudentPersonal" ); defaults.AddRules( studentMappings ); // Add field rules studentMappings.AddRule( new FieldMapping( "FIRSTNAME", "Name[@Type='04']/FirstName" ) ); studentMappings.AddRule( new FieldMapping( "LASTNAME", "Name[@Type='04']/LastName" ) ); // Create a set of mappings for the state of Wisconsin Mappings wisconsin = new Mappings( defaults, "Wisconsin" ); defaults.AddChild( wisconsin ); // Create a set of mappings for the Neillsville School District Mappings neillsville = new Mappings( wisconsin, "Neillsville" ); wisconsin.AddChild( neillsville ); XmlDocument doc = new XmlDocument( ); doc.LoadXml( "<agent/>"); XmlElement n = root.ToDom( doc ); debug( doc ); }