private void AddUndefinedEnum(EnumDef def, SifVersion version) { XmlDocument doc = getDocument(def.LocalPackage, version); DefinitionFile.WriteEnumToDom(def, doc); }
protected internal virtual void onEnumeration(XmlElement node) { String name = getAttr(node, "name"); fEnumDef = new EnumDef(name, fSrc.FullName); String value = getAttr(node, "value"); Console.Out.WriteLine(" Enumeration: " + name); fEnumDef.LatestVersion = fVersion; fEnumDef.EarliestVersion = fVersion; fDB.defineEnum(name, fEnumDef); }
public static void WriteEnumToDom(EnumDef def, XmlDocument doc) { string query = "enum[@name=\"" + def.Name + "\"]"; XmlElement node = (XmlElement)doc.DocumentElement.SelectSingleNode(query); if (node == null) { node = doc.CreateElement("enum"); //XmlSignificantWhitespace whitespace = doc.CreateSignificantWhitespace( "\r\n\r\n" ); //doc.DocumentElement.AppendChild( whitespace ); XmlComment comment = doc.CreateComment(def.Name); doc.DocumentElement.AppendChild(comment); //doc.DocumentElement.AppendChild( doc.CreateSignificantWhitespace( "\r\n\r\n" ) ); doc.DocumentElement.AppendChild(node); } else { // TODO: We may want to retain node information in the future and do updates instead. // This has not yet been implemented node.RemoveAll(); } node.SetAttribute("name", def.Name); if (def.Values.Count > 500) { XmlComment comment = node.OwnerDocument.CreateComment ("Too many values to write: Value Count - " + def.Values.Count); node.AppendChild(comment); } else { foreach (ValueDef val in def.Values) { string qry = "value[@value=\"" + val.Value + "\"]"; XmlElement valueElement = (XmlElement)node.SelectSingleNode(qry); if (valueElement == null) { valueElement = node.OwnerDocument.CreateElement("value"); node.AppendChild(valueElement); } valueElement.SetAttribute("name", createEnumName(val)); valueElement.SetAttribute("value", val.Value); if (val.Desc != null && val.Desc.Length > 0) { valueElement.SetAttribute("desc", val.Desc); } } } }
private static void CompareEnumDefs(IDictionary objects, string source, IDictionary targetObjects, string targetName, ICompareOutput output) { foreach (EnumDef def in objects.Values) { EnumDef def2 = targetObjects[def.Name] as EnumDef; if (def2 != null) { CompareEnumDef(def, source, def2, targetName, output); } } }
public void AddUndefinedObjects(ISchemaDefinition src, ISchemaDefinition edustructuresSchema) { IDictionary srcHash = src.GetAllEnums(); foreach (string enumKey in srcHash.Keys) { if (edustructuresSchema.GetEnum(enumKey) == null) { // Exclude YesNo enums EnumDef srcDef = src.GetEnum(enumKey); if (srcDef.Values.Count < 4 && srcDef.ContainsValue("Yes") && srcDef.ContainsValue("No")) { continue; } AddUndefinedEnum(srcHash[enumKey] as EnumDef, edustructuresSchema.Version); } } srcHash = src.GetAllObjects(); foreach (string key in srcHash.Keys) { if (key.StartsWith("State") || key.StartsWith("Country")) { continue; } System.Diagnostics.Debug.Assert(key != "LAInfo"); if (edustructuresSchema.GetObject(key) == null) { AddUndefinedObject(srcHash[key] as ObjectDef, edustructuresSchema.Version); } } saveChanges(); }
private static void CompareEnumDef(EnumDef def1, string source1, EnumDef def2, string source2, ICompareOutput output) { foreach (ValueDef def in def1.Values) { if (!def2.ContainsValue(def.Value)) { output.ComparisonMissing (source1, def1.Name, def.Name, source2, def1.SourceLocation); } } foreach (ValueDef val in def2.Values) { if (!def1.ContainsValue(val.Value)) { output.ComparisonMissing (source2, def2.Name, val.Name, source1, def2.SourceLocation); } } }
private void AddUndefinedEnum( EnumDef def, SifVersion version ) { XmlDocument doc = getDocument( def.LocalPackage, version ); DefinitionFile.WriteEnumToDom( def, doc ); }
protected internal virtual void onObject(XmlElement node, bool infra) { String name = getAttr(node, "name"); if (name == null) { throw new ParseException("<object> or <infra> must specify a name= attribute"); } System.Diagnostics.Debug.Assert(!(name == "LAInfo")); if (infra) { Console.Out.WriteLine(" Infra: " + name); } else { Console.Out.WriteLine(" Object: " + name); } fObjectDef = fDB.defineObject(sID++, name, fLocalPackage, fSrc.FullName); if (infra) { fObjectDef.setInfra(); } // Note: for the purpose of comparision, we want to define this object using the // RenderAs value, if present. This is different behavior than ADKGen Does System.Diagnostics.Debug.Assert(!(name.ToLower() == "ftamount")); // default Validate to True string validate = node.GetAttribute("validate"); fObjectDef.ShouldValidate = !(validate.ToLower() == "false"); fFieldDef = null; fEnumDef = null; String topic = getAttr(node, "topic"); fObjectDef.Topic = topic != null && (topic.ToUpper().Equals("yes".ToUpper()) || topic.ToUpper().Equals("true".ToUpper())); fObjectDef.RenderAs = getAttr(node, "renderAs"); fObjectDef.LatestVersion = fVersion; fObjectDef.EarliestVersion = fVersion; if (getBooleanAttr(node, "empty", false)) { fObjectDef.Flags = fObjectDef.Flags | ObjectDef.FLAG_EMPTYOBJECT; } if (!getBooleanAttr(node, "sifdtd", true)) { fObjectDef.Flags = fObjectDef.Flags | ObjectDef.FLAG_NO_SIFDTD; } if (getBooleanAttr(node, "shared", false)) { fObjectDef.Shared = true; } String override_Renamed = getAttr(node, "sequenceOverride"); if (override_Renamed != null) { try { fObjectDef.SequenceOverride = Int32.Parse(override_Renamed); } catch (FormatException nfe) { throw new ParseException ("Invalid sequenceOverride value: " + override_Renamed, nfe); } } String supercls = getAttr(node, "superclass"); if (supercls == null) { if (infra) { supercls = "SIFMessagePayload"; } else if (fObjectDef.Topic) { supercls = "SIFDataObject"; } else { supercls = "SIFElement"; } } String typ = getAttr(node, "type"); if (typ != null) { supercls = typ; } String draft = getAttr(node, "draft"); if (draft != null && draft.ToUpper().Equals("true".ToUpper())) { fObjectDef.setDraft(); } fObjectDef.Superclass = supercls; String extras = getAttr(node, "extras"); if (extras != null) { fObjectDef.ExtrasFile = fSrcDir + Path.DirectorySeparatorChar + extras; } }
protected internal virtual void onAttribute( XmlElement node ) { fEnumDef = null; String name = getAttr( node, "name" ); String type = getAttr( node, "type" ); String flags = getAttr( node, "flags" ); String enum_Renamed = getAttr( node, "enum" ); System.Diagnostics.Debug.Assert( enum_Renamed != "FTAmountType" ); StringBuilder buffer = new StringBuilder( " - " ); buffer.Append( name ); if ( type != null ) { buffer.Append( "{" ); buffer.Append( type ); buffer.Append( "}" ); } // Note: for the purpose of comparision, we want to define this object using the // RenderAs value, if present. This is different behavior than ADKGen Does string renderAs = getAttr( node, "renderAs" ); if ( renderAs != null ) { if ( renderAs.StartsWith( "xml:" ) ) { renderAs = renderAs.Substring( 4 ); } fFieldDef = fObjectDef.DefineAttr( renderAs, type ); fFieldDef.Name = name; fFieldDef.RenderAs = renderAs; } else { fFieldDef = fObjectDef.DefineAttr( name, type ); } if ( flags != null ) { fFieldDef.SetFlags( flags ); } fFieldDef.SetEnum( enum_Renamed ); if ( (fFieldDef.Flags & FieldDef.FLAG_REQUIRED) != 0 && !getBooleanAttr( node, "key", true ) ) { // By default all attributes with a "R" flag are used to generate // the object's key. However, some attributes have an "R" flag but // are not part of the key. When the key="false" attribute is // specified, set the FLAG_NOT_A_KEY flag. fFieldDef.Flags = fFieldDef.Flags | FieldDef.FLAG_NOT_A_KEY; } fFieldDef.LatestVersion = fVersion; fFieldDef.EarliestVersion = fVersion; Console.Out.WriteLine( buffer ); }
private string GetClassTypeFromDataType(XmlSchemaType dataType, string enclosingName, string parentName, out bool isEnum) { //System.Diagnostics.Debug.Assert( dataType.TypeCode != XmlTypeCode.AnyAtomicType ); //System.Diagnostics.Debug.Assert( dataType.TypeCode != XmlTypeCode.AnyUri ); Debug.Assert(dataType.TypeCode != XmlTypeCode.UntypedAtomic); isEnum = false; XmlSchemaSimpleType simpleType = dataType as XmlSchemaSimpleType; if (simpleType != null) { XmlSchemaSimpleTypeRestriction restriction = simpleType.Content as XmlSchemaSimpleTypeRestriction; if (restriction != null) { IList <DataItem> enumItems = new List <DataItem>(); foreach (XmlSchemaFacet facet in restriction.Facets) { if (facet is XmlSchemaEnumerationFacet) { // LOok for a facet description DataItem item = new DataItem(); item.Name = ((XmlSchemaEnumerationFacet)facet).Value; item.Description = item.Name; if (facet.Annotation != null && facet.Annotation.Items.Count == 1) { XmlSchemaDocumentation doc = facet.Annotation.Items[0] as XmlSchemaDocumentation; if (doc != null) { item.Description = doc.Markup[0].OuterXml; } } enumItems.Add(item); } } if (enumItems.Count > 0) { // TODO: Pull out common enums, such as Yes, No, Unknown types (SIF should do this in the schema) Debug.Assert(!parentName.EndsWith("SchoolYearType")); isEnum = true; if (simpleType.Name != null) { enclosingName = simpleType.Name; } // TODO: Determine what the final algorithm should be for local element names /*else * { * enclosingName = parentName + enclosingName; * } */ if (enclosingName == "Type" || enclosingName == "Code" || enclosingName == "CodeType" || enclosingName == "TypeCode" || fDB.GetEnum(enclosingName) != null) { enclosingName = parentName + enclosingName; } EnumDef enumDef = new EnumDef (enclosingName, restriction.SourceUri + ":" + restriction.LineNumber); enumDef.LocalPackage = getLocalPackage(restriction.SourceUri); foreach (DataItem item in enumItems) { if (item.Name != null) { enumDef.DefineValue(item.Name, item.Name, item.Description); } } fDB.defineEnum(enclosingName, enumDef); return(enclosingName); } } } if (dataType != null) { return(dataType.TypeCode.ToString()); } else { return(null); } }
private string GetClassTypeFromDataType( XmlSchemaType dataType, string enclosingName, string parentName, out bool isEnum ) { //System.Diagnostics.Debug.Assert( dataType.TypeCode != XmlTypeCode.AnyAtomicType ); //System.Diagnostics.Debug.Assert( dataType.TypeCode != XmlTypeCode.AnyUri ); Debug.Assert( dataType.TypeCode != XmlTypeCode.UntypedAtomic ); isEnum = false; XmlSchemaSimpleType simpleType = dataType as XmlSchemaSimpleType; if ( simpleType != null ) { XmlSchemaSimpleTypeRestriction restriction = simpleType.Content as XmlSchemaSimpleTypeRestriction; if ( restriction != null ) { IList<DataItem> enumItems = new List<DataItem>(); foreach ( XmlSchemaFacet facet in restriction.Facets ) { if ( facet is XmlSchemaEnumerationFacet ) { // LOok for a facet description DataItem item = new DataItem(); item.Name = ((XmlSchemaEnumerationFacet) facet).Value; item.Description = item.Name; if ( facet.Annotation != null && facet.Annotation.Items.Count == 1 ) { XmlSchemaDocumentation doc = facet.Annotation.Items[0] as XmlSchemaDocumentation; if ( doc != null ) { item.Description = doc.Markup[0].OuterXml; } } enumItems.Add( item ); } } if ( enumItems.Count > 0 ) { // TODO: Pull out common enums, such as Yes, No, Unknown types (SIF should do this in the schema) Debug.Assert( !parentName.EndsWith( "SchoolYearType" ) ); isEnum = true; if ( simpleType.Name != null ) { enclosingName = simpleType.Name; } // TODO: Determine what the final algorithm should be for local element names /*else { enclosingName = parentName + enclosingName; } */ if ( enclosingName == "Type" || enclosingName == "Code" || enclosingName == "CodeType" || enclosingName == "TypeCode" || fDB.GetEnum( enclosingName ) != null ) { enclosingName = parentName + enclosingName; } EnumDef enumDef = new EnumDef ( enclosingName, restriction.SourceUri + ":" + restriction.LineNumber ); enumDef.LocalPackage = getLocalPackage( restriction.SourceUri ); foreach ( DataItem item in enumItems ) { if ( item.Name != null ) { enumDef.DefineValue( item.Name, item.Name, item.Description ); } } fDB.defineEnum( enclosingName, enumDef ); return enclosingName; } } } if ( dataType != null ) { return dataType.TypeCode.ToString(); } else { return null; } }
/// <summary> Merge the definitions of this DB into another DB /// </summary> public virtual void mergeInto(DB target) { Console.Out.WriteLine ("Merging metadata for \"" + this.fVersion + "\" into \"" + target.Version + "\"..."); Console.Out.WriteLine("- Processing enumerated types..."); for (IEnumerator e = fEnums.Keys.GetEnumerator(); e.MoveNext();) { String key = (String)e.Current; Object val = fEnums[key]; EnumDef targetEnum = (EnumDef)target.fEnums[key]; if (targetEnum == null) { // Add the missing EnumDef to the target Console.Out.WriteLine(" (+) \"" + key + "\" not found in target; adding"); target.fEnums[key] = val; } else { // Visit all values in the target's enumeration and add values // for any that are new in this version of SIF foreach (ValueDef def in ((EnumDef)val).Values) { if (!targetEnum.ContainsValue(def.Value)) { Console.Out.WriteLine (" (~) \"" + key + "::" + def.Value + "\" not found in target; adding"); targetEnum.DefineValue(def.Name, def.Value, def.Desc); } } } } // Update the target's SifVersion range for (IEnumerator e = target.fEnums.Keys.GetEnumerator(); e.MoveNext();) { String key = (String)e.Current; EnumDef enumDef = (EnumDef)target.fEnums[key]; enumDef.LatestVersion = fVersion; Console.Out.WriteLine ("Enum " + enumDef.Name + " now has SifVersion range of " + enumDef.EarliestVersion + ".." + enumDef.LatestVersion); } for (IEnumerator e = target.fObjects.Keys.GetEnumerator(); e.MoveNext();) { String key = (String)e.Current; ObjectDef objDef = (ObjectDef)target.fObjects[key]; objDef.LatestVersion = fVersion; Console.Out.WriteLine ("Object " + objDef.Name + " now has SifVersion range of " + objDef.EarliestVersion + ".." + objDef.LatestVersion); for (IEnumerator e2 = objDef.fFields.Keys.GetEnumerator(); e2.MoveNext();) { key = (String)e2.Current; FieldDef fldDef = objDef.fFields[key]; fldDef.LatestVersion = fVersion; Console.Out.WriteLine (" Field " + fldDef.Name + " now has SifVersion range of " + fldDef.EarliestVersion + ".." + fldDef.LatestVersion); } } Console.Out.WriteLine("- Processing object definitions..."); for (IEnumerator e = fObjects.Keys.GetEnumerator(); e.MoveNext();) { String key = (String)e.Current; ObjectDef val = (ObjectDef)fObjects[key]; ObjectDef targetObj = (ObjectDef)target.fObjects[key]; if (targetObj == null) { // Add the missing ObjectDef to the target Console.Out.WriteLine (" (+) \"" + key + "\" (" + val.Fields.Length + " fields) not found in target; adding"); target.fObjects[key] = val; } else { // Do some sanity checking if (!targetObj.LocalPackage.Equals(val.LocalPackage)) { throw new MergeException ("Target and source have different package values (target=\"" + targetObj.Name + "\", package=\"" + targetObj.LocalPackage + "\", source=\"" + val.Name + "\", package=\"" + val.LocalPackage + "\""); } if (!targetObj.Superclass.Equals(val.Superclass)) { throw new MergeException ("Target and source have different superclass values (target=\"" + targetObj.Name + "\", superclass=\"" + targetObj.Superclass + "\", source=\"" + val.Name + "\", superclass=\"" + val.Superclass + "\""); } // Append this fExtrasFile to the target's if necessary if (val.ExtrasFile != null) { Console.Out.WriteLine(" (+) \"" + key + "\" has an Extras File; adding"); targetObj.ExtrasFile = targetObj.ExtrasFile + ";" + val.ExtrasFile; } // Determine if the object's key fields (required elements and // attributes) differ StringBuilder keyCmp1s = new StringBuilder(); FieldDef[] keyCmp1 = val.Key; for (int n = 0; n < keyCmp1.Length; n++) { keyCmp1s.Append(keyCmp1[n].Name == null ? "null" : keyCmp1[n].Name); if (n != keyCmp1.Length - 1) { keyCmp1s.Append('+'); } } StringBuilder keyCmp2s = new StringBuilder(); FieldDef[] keyCmp2 = targetObj.Key; for (int n = 0; n < keyCmp2.Length; n++) { keyCmp2s.Append(keyCmp2[n].Name == null ? "null" : keyCmp2[n].Name); if (n != keyCmp2.Length - 1) { keyCmp2s.Append('+'); } } if (!keyCmp1s.ToString().Equals(keyCmp2s.ToString())) { throw new MergeException ("\"" + key + "\" target and source have different key signature; merge not yet supported by adkgen." + " Target=\"" + keyCmp2s + "\"; Source=\"" + keyCmp1s + "\""); } targetObj.LatestVersion = Version; // Determine if any of the object's fields differ in their definition for (IEnumerator k = val.fFields.Keys.GetEnumerator(); k.MoveNext();) { String key2 = (String)k.Current; FieldDef srcFld = val.fFields[key2]; FieldDef targetFld; targetFld = targetObj.fFields[key2]; if (targetFld == null) { Console.Out.WriteLine (" (+) Field \"" + key + "::" + key2 + "\" not found in target; adding"); targetObj.fFields[key2] = srcFld; } else { bool methodDiff = false; bool attrDiff = false; // Check the field for differences... if (!Equals(srcFld.FieldType, targetFld.FieldType)) { Console.Out.WriteLine (" (~) Field \"" + key + "::" + key2 + "\" has different ClassType; adding version-specific field"); methodDiff = true; } if (!targetFld.Tag.Equals(srcFld.Tag)) { Console.Out.WriteLine (" (~) Field \"" + key + "::" + key2 + "\" has different tag; adding alias"); Console.Out.WriteLine(" " + fVersion + " -> " + srcFld.Tag); Console.Out.WriteLine (" " + target.Version + " -> " + targetFld.Tag); attrDiff = true; } if (targetFld.Sequence != srcFld.Sequence) { Console.Out.WriteLine (" (~) Field \"" + key + "::" + key2 + "\" has different sequence number; adding alias"); Console.Out.WriteLine (" " + fVersion + " -> " + srcFld.Sequence); Console.Out.WriteLine (" " + target.Version + " -> " + targetFld.Sequence); attrDiff = true; } if (methodDiff) { // If there were any differences that would result in new // methods to the implementation class, create a new FieldDef Console.Out.WriteLine("*** DIFF ***"); throw new MergeException("Method merge not yet supported"); } else if (attrDiff) { // If there were any differences in tag name or sequence // number, add an alias to the FieldDef targetFld.addAlias(fVersion, srcFld.Tag, srcFld.Sequence); } else { targetFld.LatestVersion = fVersion; } } } } } }
public virtual void defineEnum(string name, EnumDef enumdef) { fEnums[name] = enumdef; }
protected internal virtual void onElement( XmlElement node ) { fEnumDef = null; String name = getAttr( node, "name" ); String type = getAttr( node, "type" ); String flags = getAttr( node, "flags" ); String enumVal = getAttr( node, "enum" ); StringBuilder buf = new StringBuilder( " > " ); buf.Append( name ); if ( type != null ) { buf.Append( "{" ); buf.Append( type ); buf.Append( "}" ); } fFieldDef = fObjectDef.DefineElement( name, type ); if ( flags != null ) { fFieldDef.SetFlags( flags ); } if ( enumVal != null ) { fFieldDef.SetEnum( enumVal ); } fFieldDef.RenderAs = getAttr( node, "renderAs" ); String seqOverride = getAttr( node, "sequenceOverride" ); if ( seqOverride != null ) { try { fFieldDef.SequenceOverride = int.Parse( seqOverride ); } catch ( FormatException nfe ) { throw new ParseException( "Invalid sequenceOverride value: " + seqOverride, nfe ); } } if ( !getBooleanAttr( node, "sifdtd", true ) ) { fFieldDef.Flags = fFieldDef.Flags | FieldDef.FLAG_NO_SIFDTD; } if ( !getBooleanAttr( node, "encode", true ) ) { fFieldDef.Flags = fFieldDef.Flags | FieldDef.FLAG_DO_NOT_ENCODE; } if ( getBooleanAttr( node, "collapsed", false ) ) { fFieldDef.Flags = fFieldDef.Flags | FieldDef.FLAG_COLLAPSED; } String draft = getAttr( node, "draft" ); if ( draft != null && bool.Parse( draft ) ) { fFieldDef.setDraft(); } fFieldDef.LatestVersion = fVersion; fFieldDef.EarliestVersion = fVersion; if ( (fFieldDef.Flags & FieldDef.FLAG_MANDATORY) != 0 && !getBooleanAttr( node, "key", true ) ) { // By default all attributes with a "R" flag are used to generate // the object's key. However, some attributes have an "R" flag but // are not part of the key. When the key="false" attribute is // specified, set the FLAG_NOT_A_KEY flag. fFieldDef.Flags = fFieldDef.Flags | FieldDef.FLAG_NOT_A_KEY; } Console.WriteLine( buf ); fFieldDef.Validate(); }
protected internal virtual void onAttribute(XmlElement node) { fEnumDef = null; String name = getAttr(node, "name"); String type = getAttr(node, "type"); String flags = getAttr(node, "flags"); String enum_Renamed = getAttr(node, "enum"); System.Diagnostics.Debug.Assert(enum_Renamed != "FTAmountType"); StringBuilder buffer = new StringBuilder(" - "); buffer.Append(name); if (type != null) { buffer.Append("{"); buffer.Append(type); buffer.Append("}"); } // Note: for the purpose of comparision, we want to define this object using the // RenderAs value, if present. This is different behavior than ADKGen Does string renderAs = getAttr(node, "renderAs"); if (renderAs != null) { if (renderAs.StartsWith("xml:")) { renderAs = renderAs.Substring(4); } fFieldDef = fObjectDef.DefineAttr(renderAs, type); fFieldDef.Name = name; fFieldDef.RenderAs = renderAs; } else { fFieldDef = fObjectDef.DefineAttr(name, type); } if (flags != null) { fFieldDef.SetFlags(flags); } fFieldDef.SetEnum(enum_Renamed); if ((fFieldDef.Flags & FieldDef.FLAG_REQUIRED) != 0 && !getBooleanAttr(node, "key", true)) { // By default all attributes with a "R" flag are used to generate // the object's key. However, some attributes have an "R" flag but // are not part of the key. When the key="false" attribute is // specified, set the FLAG_NOT_A_KEY flag. fFieldDef.Flags = fFieldDef.Flags | FieldDef.FLAG_NOT_A_KEY; } fFieldDef.LatestVersion = fVersion; fFieldDef.EarliestVersion = fVersion; Console.Out.WriteLine(buffer); }
protected internal virtual void onEnumeration( XmlElement node ) { String name = getAttr( node, "name" ); fEnumDef = new EnumDef( name, fSrc.FullName ); String value = getAttr( node, "value" ); Console.Out.WriteLine( " Enumeration: " + name ); fEnumDef.LatestVersion = fVersion; fEnumDef.EarliestVersion = fVersion; fDB.defineEnum( name, fEnumDef ); }
public static void WriteEnumToDom( EnumDef def, XmlDocument doc ) { string query = "enum[@name=\"" + def.Name + "\"]"; XmlElement node = (XmlElement) doc.DocumentElement.SelectSingleNode( query ); if ( node == null ) { node = doc.CreateElement( "enum" ); //XmlSignificantWhitespace whitespace = doc.CreateSignificantWhitespace( "\r\n\r\n" ); //doc.DocumentElement.AppendChild( whitespace ); XmlComment comment = doc.CreateComment( def.Name ); doc.DocumentElement.AppendChild( comment ); //doc.DocumentElement.AppendChild( doc.CreateSignificantWhitespace( "\r\n\r\n" ) ); doc.DocumentElement.AppendChild( node ); } else { // TODO: We may want to retain node information in the future and do updates instead. // This has not yet been implemented node.RemoveAll(); } node.SetAttribute( "name", def.Name ); if ( def.Values.Count > 500 ) { XmlComment comment = node.OwnerDocument.CreateComment ( "Too many values to write: Value Count - " + def.Values.Count ); node.AppendChild( comment ); } else { foreach ( ValueDef val in def.Values) { string qry = "value[@value=\"" + val.Value + "\"]"; XmlElement valueElement = (XmlElement) node.SelectSingleNode( qry ); if ( valueElement == null ) { valueElement = node.OwnerDocument.CreateElement( "value" ); node.AppendChild( valueElement ); } valueElement.SetAttribute( "name", createEnumName( val ) ); valueElement.SetAttribute( "value", val.Value ); if ( val.Desc != null && val.Desc.Length > 0 ) { valueElement.SetAttribute( "desc", val.Desc ); } } } }
protected internal virtual void onObject( XmlElement node, bool infra ) { String name = getAttr( node, "name" ); if ( name == null ) { throw new ParseException( "<object> or <infra> must specify a name= attribute" ); } System.Diagnostics.Debug.Assert( !(name == "LAInfo") ); if ( infra ) { Console.Out.WriteLine( " Infra: " + name ); } else { Console.Out.WriteLine( " Object: " + name ); } fObjectDef = fDB.defineObject( sID++, name, fLocalPackage, fSrc.FullName ); if( infra ) { fObjectDef.setInfra(); } // Note: for the purpose of comparision, we want to define this object using the // RenderAs value, if present. This is different behavior than ADKGen Does System.Diagnostics.Debug.Assert( !(name.ToLower() == "ftamount" ) ); // default Validate to True string validate = node.GetAttribute( "validate" ); fObjectDef.ShouldValidate = !(validate.ToLower() == "false"); fFieldDef = null; fEnumDef = null; String topic = getAttr( node, "topic" ); fObjectDef.Topic = topic != null && (topic.ToUpper().Equals( "yes".ToUpper() ) || topic.ToUpper().Equals( "true".ToUpper() )); fObjectDef.RenderAs = getAttr( node, "renderAs" ); fObjectDef.LatestVersion = fVersion; fObjectDef.EarliestVersion = fVersion; if ( getBooleanAttr( node, "empty", false ) ) { fObjectDef.Flags = fObjectDef.Flags | ObjectDef.FLAG_EMPTYOBJECT; } if ( !getBooleanAttr( node, "sifdtd", true ) ) { fObjectDef.Flags = fObjectDef.Flags | ObjectDef.FLAG_NO_SIFDTD; } if ( getBooleanAttr( node, "shared", false ) ) { fObjectDef.Shared = true; } String override_Renamed = getAttr( node, "sequenceOverride" ); if ( override_Renamed != null ) { try { fObjectDef.SequenceOverride = Int32.Parse( override_Renamed ); } catch ( FormatException nfe ) { throw new ParseException ( "Invalid sequenceOverride value: " + override_Renamed, nfe ); } } String supercls = getAttr( node, "superclass" ); if ( supercls == null ) { if ( infra ) { supercls = "SIFMessagePayload"; } else if ( fObjectDef.Topic ) { supercls = "SIFDataObject"; } else { supercls = "SIFElement"; } } String typ = getAttr( node, "type" ); if ( typ != null ) { supercls = typ; } String draft = getAttr( node, "draft" ); if ( draft != null && draft.ToUpper().Equals( "true".ToUpper() ) ) { fObjectDef.setDraft(); } fObjectDef.Superclass = supercls; String extras = getAttr( node, "extras" ); if ( extras != null ) { fObjectDef.ExtrasFile = fSrcDir + Path.DirectorySeparatorChar + extras; } }
protected internal virtual void onElement(XmlElement node) { fEnumDef = null; String name = getAttr(node, "name"); String type = getAttr(node, "type"); String flags = getAttr(node, "flags"); String enumVal = getAttr(node, "enum"); StringBuilder buf = new StringBuilder(" > "); buf.Append(name); if (type != null) { buf.Append("{"); buf.Append(type); buf.Append("}"); } fFieldDef = fObjectDef.DefineElement(name, type); if (flags != null) { fFieldDef.SetFlags(flags); } if (enumVal != null) { fFieldDef.SetEnum(enumVal); } fFieldDef.RenderAs = getAttr(node, "renderAs"); String seqOverride = getAttr(node, "sequenceOverride"); if (seqOverride != null) { try { fFieldDef.SequenceOverride = int.Parse(seqOverride); } catch (FormatException nfe) { throw new ParseException("Invalid sequenceOverride value: " + seqOverride, nfe); } } if (!getBooleanAttr(node, "sifdtd", true)) { fFieldDef.Flags = fFieldDef.Flags | FieldDef.FLAG_NO_SIFDTD; } if (!getBooleanAttr(node, "encode", true)) { fFieldDef.Flags = fFieldDef.Flags | FieldDef.FLAG_DO_NOT_ENCODE; } if (getBooleanAttr(node, "collapsed", false)) { fFieldDef.Flags = fFieldDef.Flags | FieldDef.FLAG_COLLAPSED; } String draft = getAttr(node, "draft"); if (draft != null && bool.Parse(draft)) { fFieldDef.setDraft(); } fFieldDef.LatestVersion = fVersion; fFieldDef.EarliestVersion = fVersion; if ((fFieldDef.Flags & FieldDef.FLAG_MANDATORY) != 0 && !getBooleanAttr(node, "key", true)) { // By default all attributes with a "R" flag are used to generate // the object's key. However, some attributes have an "R" flag but // are not part of the key. When the key="false" attribute is // specified, set the FLAG_NOT_A_KEY flag. fFieldDef.Flags = fFieldDef.Flags | FieldDef.FLAG_NOT_A_KEY; } Console.WriteLine(buf); fFieldDef.Validate(); }
public virtual void defineEnum( string name, EnumDef enumdef ) { fEnums[name] = enumdef; }