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 ); }
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; }
/// <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; }