Exemple #1
0
        public FieldDef(ObjectDef parent,
                        String name,
                        FieldType fieldType,
                        int sequence,
                        int nodeTypeFlag)
            : base(name)
        {
            fParent    = parent;
            fSequence  = sequence;
            fFieldType = fieldType;
            fFlags     = nodeTypeFlag;

            if (fFieldType.IsComplex)
            {
                if (fFlags == FLAG_ATTRIBUTE)
                {
                    throw new ParseException
                          (
                              "Cannot create an attribute as a ComplexType: " +
                              parent.Name + "." + name + " {" + fieldType.ClassType + "}");
                }
                fFlags |= FLAG_COMPLEX;
                if (fieldType.ClassType.Equals(name))
                {
                    fSuperclass = fieldType.ClassType;
                }
            }
            fDtdSymbol       = fParent.DTDSymbol + "_" + fName.ToUpper();
            fElementDefConst = fParent.PackageQualifiedDTDSymbol + "_" + (fName.ToUpper());
        }
Exemple #2
0
        private void AddUndefinedObject(ObjectDef def,
                                        SifVersion version)
        {
            XmlDocument doc = getDocument(def.LocalPackage, version);

            DefinitionFile.WriteObjectToDom(def, doc);
        }
Exemple #3
0
        protected void BuildAttribute( XmlSchemaAttribute attribute,
                                       ObjectDef objectDef )
        {
            FieldDef def = null;
            bool isEnum;
            string dataType =
                GetClassTypeFromDataType
                    ( attribute.AttributeSchemaType, attribute.QualifiedName.Name, objectDef.Name,
                      out isEnum );
            if ( isEnum ) {
                def = objectDef.DefineAttr( attribute.QualifiedName.Name, null );
                def.SetEnum( dataType );
            }
            else {
                def = objectDef.DefineAttr( attribute.QualifiedName.Name, dataType );
            }

            if ( attribute.Use == XmlSchemaUse.Required ) {
                def.SetFlags( "R" );
            }
            else {
                def.SetFlags( "O" );
            }
            setAnnotation( def, attribute.Annotation );
            // TODO: See if the data type is an enumeration
            //System.Diagnostics.Debug.Assert( ! ( attribute.AttributeType is xmlschemdata
        }
Exemple #4
0
        private void BuildDb()
        {
            foreach (XmlSchemaElement element in Schema.Elements.Values)
            {
                BuildObjectFromElement(element, null, true);
            }

            // Set the Infra flag on these items
            foreach (XmlSchemaParticle p in GetInfraMessageElements().Items)
            {
                ObjectDef def =
                    (ObjectDef)fDB.GetObject(((XmlSchemaElement)p).QualifiedName.Name);
                def.setInfra();
            }

            // Special Case for SIF_Header
            ObjectDef def2;

            def2 = this.fDB.GetObject("SIF_Header");
            def2.setInfra();

            // Build up the topic items
            foreach (XmlSchemaEnumerationFacet p in GetTopicMessageElements())
            {
                ObjectDef def = (ObjectDef)fDB.GetObject(p.Value);
                if (def.Name != "SIF_EventObject")
                {
                    def.Topic = true;
                }
            }
        }
Exemple #5
0
        protected void BuildAttribute(XmlSchemaAttribute attribute,
                                      ObjectDef objectDef)
        {
            FieldDef def = null;
            bool     isEnum;
            string   dataType =
                GetClassTypeFromDataType
                    (attribute.AttributeSchemaType, attribute.QualifiedName.Name, objectDef.Name,
                    out isEnum);

            if (isEnum)
            {
                def = objectDef.DefineAttr(attribute.QualifiedName.Name, null);
                def.SetEnum(dataType);
            }
            else
            {
                def = objectDef.DefineAttr(attribute.QualifiedName.Name, dataType);
            }

            if (attribute.Use == XmlSchemaUse.Required)
            {
                def.SetFlags("R");
            }
            else
            {
                def.SetFlags("O");
            }
            setAnnotation(def, attribute.Annotation);
            // TODO: See if the data type is an enumeration
            //System.Diagnostics.Debug.Assert( ! ( attribute.AttributeType is xmlschemdata
        }
Exemple #6
0
 private void BuildParticle(XmlSchemaParticle particle,
                            ObjectDef parent,
                            bool attachToParent)
 {
     //System.Diagnostics.Debug.Assert(!particle.SourceUri.EndsWith("TransacationList"));
     if (particle is XmlSchemaElement)
     {
         BuildObjectFromElement((XmlSchemaElement)particle, parent, attachToParent);
     }
     else if (particle is XmlSchemaSequence)
     {
         foreach (XmlSchemaParticle particle1 in ((XmlSchemaSequence)particle).Items)
         {
             BuildParticle(particle1, parent, true);
         }
     }
     else if (particle is XmlSchemaChoice)
     {
         foreach (XmlSchemaParticle particle1 in ((XmlSchemaChoice)particle).Items)
         {
             // TODO: This element is a choice element, we won't define it on the parent, but we may need to add an element with some type of name ( research );
             BuildParticle(particle1, parent, false);
         }
     }
     else if (particle is XmlSchemaAny)
     {
         // New in SIF 2.0. XML Schema Any just means that the data type of the parent object
         // is Set to represent XML Any
         parent.SetDataType("any");
     }
     else
     {
         throw new SchemaNotImplementedException(particle);
     }
 }
Exemple #7
0
        public FieldDef( ObjectDef parent,
                         String name,
                         FieldType fieldType,
                         int sequence,
                         int nodeTypeFlag )
            : base(name)
        {
            fParent = parent;
            fSequence = sequence;
            fFieldType = fieldType;
            fFlags = nodeTypeFlag;

            if ( fFieldType.IsComplex ) {
                if ( fFlags == FLAG_ATTRIBUTE ) {
                    throw new ParseException
                        (
                        "Cannot create an attribute as a ComplexType: " +
                        parent.Name + "." + name + " {" + fieldType.ClassType + "}" );
                }
                fFlags |= FLAG_COMPLEX;
                if ( fieldType.ClassType.Equals( name ) ) {
                    fSuperclass = fieldType.ClassType;
                }
            }
            fDtdSymbol = fParent.DTDSymbol + "_" + fName.ToUpper();
            fElementDefConst = fParent.PackageQualifiedDTDSymbol + "_" + (fName.ToUpper());
        }
Exemple #8
0
 public FieldDef(ObjectDef parent,
                 String name,
                 String classType,
                 int sequence,
                 int nodeTypeFlag)
     : this(parent, name, FieldType.GetFieldType(classType), sequence, nodeTypeFlag)
 {
 }
Exemple #9
0
 public FieldDef( ObjectDef parent,
                  String name,
                  String classType,
                  int sequence,
                  int nodeTypeFlag )
     : this(parent, name, FieldType.GetFieldType( classType ), sequence, nodeTypeFlag)
 {
 }
        private static void CompareField(string source1,
                                         ObjectDef def1,
                                         FieldDef field1,
                                         string source2,
                                         FieldDef field2,
                                         ICompareOutput output,
                                         bool detailedCheck)
        {
            if (field1.Attribute != field2.Attribute)
            {
                output.ComparisonFailed
                    (source1, def1.Name + "." + field1.Name, "Attribute",
                    field1.Attribute.ToString(), source2, field2.Attribute.ToString(),
                    def1.SourceLocation);
            }

            if (field1.Sequence != field2.Sequence)
            {
                output.ComparisonWarning
                    (source1, source2, "Differing sequence: " + def1.Name + "." + field1.Name + " src(" + field1.Sequence + ") target:(" + field2.Sequence + ")");
            }

            if (detailedCheck)
            {
                //				if( field1.Complex != field2.Complex )
                //				{
                //					output.ComparisonFailed( source1, def1.Name + "." + field1.Name, "Complex", field1.Complex.ToString(), source2, field2.Complex.ToString(), def1.SourceLocation );
                //				}

                //System.Diagnostics.Debug.Assert( !(def1.Name == "FundingSource") );

                if (!field1.FlagIntrinsicallyMatches(field2))
                {
                    output.ComparisonWarning
                        (source1, source2, "Differing flags: " + def1.Name + "." + field1.Name + " src(" + field1.GetFlags() +
                        ") target:(" + field2.GetFlags() + ")");
                }



                if (!field1.FieldType.Equals(field2.FieldType))
                {
                    if (field1.FieldType.IsEnum && field2.FieldType.IsEnum)
                    {
                        output.ComparisonDebug
                            (source2, source1,
                            "differing class type: " + def1.Name + "." + field1.Name + " src(" +
                            field1.FieldType + ") target:(" + field2.FieldType + ")");
                    }

                    output.ComparisonWarning
                        (source2, source1,
                        "differing class type: " + def1.Name + "." + field1.Name + " src(" +
                        field1.FieldType + ") target:(" + field2.FieldType + ")");
                }
            }
        }
Exemple #11
0
        public virtual ObjectDef defineObject(int id,
                                              String name,
                                              String pkg,
                                              string sourceLocation)
        {
            //System.Diagnostics.Debug.Assert( !(name == "FundingSource" ));
            ObjectDef d = (ObjectDef)fObjects[name];

            if (d == null)
            {
                d = new ObjectDef(id, name, sourceLocation, pkg, fVersion);
                fObjects[name] = d;
            }
            return(d);
        }
 private static void CompareObjectDefs(IDictionary objects,
                                       string source,
                                       IDictionary targetObjects,
                                       string targetName,
                                       ICompareOutput output,
                                       bool detailed)
 {
     foreach (ObjectDef def in objects.Values)
     {
         ObjectDef def2 = targetObjects[def.Name] as ObjectDef;
         if (def2 != null)
         {
             CompareObjectDef(def, source, def2, targetName, output, detailed);
         }
     }
 }
Exemple #13
0
 private void BuildAttributes(XmlSchemaObjectCollection attributes,
                              ObjectDef objectDef)
 {
     foreach (XmlSchemaObject o in attributes)
     {
         if (o is XmlSchemaAttribute)
         {
             BuildAttribute((XmlSchemaAttribute)o, objectDef);
         }
         else
         {
             XmlSchemaAttributeGroup group =
                 (XmlSchemaAttributeGroup)
                 Schema.Groups[((XmlSchemaAttributeGroupRef)o).RefName];
             BuildAttributes(group.Attributes, objectDef);
         }
     }
 }
        private static void WriteFieldsToDom(XmlElement objectElement,
                                             ObjectDef def)
        {
            FieldDef[] fields = def.Attributes;
            Array.Sort(fields, new FieldDefComparer());
            foreach (FieldDef attr in fields)
            {
                XmlElement fieldAttribute = objectElement.OwnerDocument.CreateElement("attribute");
                objectElement.AppendChild(fieldAttribute);
                WriteFieldToDom(fieldAttribute, attr);
            }


            fields = def.Elements;
            Array.Sort(fields, new FieldDefComparer());
            foreach (FieldDef ele in def.Elements)
            {
                XmlElement fieldElement = objectElement.OwnerDocument.CreateElement("element");
                objectElement.AppendChild(fieldElement);
                WriteFieldToDom(fieldElement, ele);
            }
        }
        private static void CompareObjectDef(ObjectDef def1,
                                             string source1,
                                             ObjectDef def2,
                                             string source2,
                                             ICompareOutput output,
                                             bool detailed)
        {
            if (def1.Infra != def2.Infra)
            {
                output.ComparisonFailed
                    (source1, def1.Name, "Infra", def1.Infra.ToString(), source2,
                    def2.Infra.ToString(), def1.SourceLocation);
            }
            if (def1.Topic != def2.Topic)
            {
                output.ComparisonFailed
                    (source1, def1.Name, "Topic", def1.Topic.ToString(), source2,
                    def2.Topic.ToString(), def1.SourceLocation);
            }

            CompareFields(source1, def1, source2, def2, output, detailed);
            CompareFields(source2, def2, source1, def1, output, detailed);
        }
 private static void CompareFields(string source,
                                   ObjectDef sourceDef,
                                   string target,
                                   ObjectDef targetDef,
                                   ICompareOutput output,
                                   bool detailed)
 {
     foreach (FieldDef field1 in sourceDef.Fields)
     {
         if (field1.Name == "SIF_ExtendedElements" || field1.Name == "SIF_Metadata")
         {
             // ignore. adkgen automatically adds to "topic" objects
         }
         else
         {
             FieldDef field2;
             if (field1.RenderAs != null)
             {
                 field2 = targetDef.GetField(field1.RenderAs);
             }
             else
             {
                 field2 = targetDef.GetField(field1.Name);
             }
             if (field2 == null)
             {
                 output.ComparisonMissing
                     (source, sourceDef.Name, field1.Name, target, sourceDef.SourceLocation);
             }
             else if (detailed)
             {
                 CompareField
                     (source, sourceDef, field1, target, field2, output, true);
             }
         }
     }
 }
        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;
            }
        }
Exemple #18
0
 private void BuildContentModel(XmlSchemaComplexType type,
                                ObjectDef def)
 {
     if (type.ContentModel != null)
     {
         if (type.ContentModel is XmlSchemaSimpleContent)
         {
             XmlSchemaSimpleContent            content     = type.ContentModel as XmlSchemaSimpleContent;
             XmlSchemaSimpleContentRestriction restriction =
                 content.Content as XmlSchemaSimpleContentRestriction;
             if (restriction != null)
             {
                 FieldDef field;
                 bool     isEnum;
                 string   dataType =
                     GetClassTypeFromDataType
                         (restriction.BaseType, type.QualifiedName.Name, def.Name,
                         out isEnum);
                 if (isEnum)
                 {
                     field = def.DefineElement(type.QualifiedName.Name, null);
                     field.SetEnum(dataType);
                 }
                 else
                 {
                     field = def.DefineElement(type.QualifiedName.Name, dataType);
                 }
                 if ((type.Particle != null && type.Particle.MinOccurs > 0) ||
                     (type.ContentTypeParticle != null && type.ContentTypeParticle.MinOccurs > 0))
                 {
                     field.SetFlags("M");
                 }
             }
             else
             {
                 XmlSchemaSimpleContentExtension extension =
                     content.Content as XmlSchemaSimpleContentExtension;
                 BuildAttributes(extension.Attributes, def);
                 //FieldDef field = def.defineElement( type.QualifiedName.Name, extension.BaseTypeName.Name );
             }
         }
         else if (type.Particle == null && type.ContentModel is XmlSchemaComplexContent)
         {
             XmlSchemaComplexContent complexContent =
                 type.ContentModel as XmlSchemaComplexContent;
             XmlSchemaComplexContentExtension ext =
                 type.ContentModel.Content as XmlSchemaComplexContentExtension;
             if (type.BaseXmlSchemaType != null)
             {
                 XmlSchemaComplexType baseType =
                     type.BaseXmlSchemaType as XmlSchemaComplexType;
                 if (baseType != null)
                 {
                     BuildContentModel(baseType, def);
                 }
             }
             if (ext != null && ext.Particle != null)
             {
                 if (ext.BaseTypeName != null)
                 {
                     object ao = Schema.Elements[ext.BaseTypeName];
                     //string data = ao.ToString();
                 }
                 BuildParticle(ext.Particle, def, true);
             }
         }
     }
     else if (type.Particle != null)
     {
         try {
             BuildParticle(type.Particle, def, true);
         }
         catch (SchemaNotImplementedException xse) {
             Console.WriteLine
                 ("Type Not Implemented: " + type.QualifiedName + " : " +
                 xse.Particle.ToString() + xse.Particle.SourceUri + ":" +
                 xse.Particle.LineNumber);
         }
     }
 }
 private void AddUndefinedObject( ObjectDef def,
                                  SifVersion version )
 {
     XmlDocument doc = getDocument( def.LocalPackage, version );
     DefinitionFile.WriteObjectToDom( def, doc );
 }
Exemple #20
0
 public virtual ObjectDef defineObject( int id,
                                        String name,
                                        String pkg,
                                        string sourceLocation )
 {
     //System.Diagnostics.Debug.Assert( !(name == "FundingSource" ));
     ObjectDef d = (ObjectDef) fObjects[name];
     if ( d == null ) {
         d = new ObjectDef( id, name, sourceLocation, pkg, fVersion );
         fObjects[name] = d;
     }
     return d;
 }
Exemple #21
0
        private AbstractDef BuildObjectFromElement(XmlSchemaElement element,
                                                   ObjectDef parent,
                                                   bool attachToParent)
        {
            //System.Diagnostics.Debug.Assert( !( element.QualifiedName.Name == "FineInfo" ) );
            AbstractDef returnVal = null;

            if (element.ElementSchemaType is XmlSchemaComplexType)
            {
                ObjectDef def = fDB.GetObject(element.QualifiedName.Name);
                if (def != null)
                {
                    if (parent != null && attachToParent)
                    {
                        returnVal = parent.DefineElement(def.Name, def.Name);
                        if (parent.Infra)
                        {
                            def.setInfra();
                        }
                        returnVal.SetFlags(getFlags(element));
                        setAnnotation(returnVal, element.Annotation);
                    }
                    if (parent == null)
                    {
                        // Reset the source location
                        def.SourceLocation = element.SourceUri + ";line:" + element.LineNumber;
                        def.LocalPackage   = getLocalPackage(element.SourceUri);
                        setAnnotation(def, element.Annotation);
                    }
                    // Console.WriteLine( element.QualifiedName.Name + " is already defined, ignoring." );
                    return(def);
                }
                //System.Diagnostics.Debug.Assert( !( element.QualifiedName.Name == "StaffPersonal" ) );
                def =
                    fDB.defineObject
                        (0, element.QualifiedName.Name, getLocalPackage(element.SourceUri),
                        element.SourceUri + ";line:" + element.LineNumber);
                returnVal = def;
                XmlSchemaComplexType type = (XmlSchemaComplexType)element.ElementSchemaType;
                BuildAttributes(type.Attributes, def);
                BuildContentModel(type, def);
                if (parent != null && attachToParent)
                {
                    returnVal = parent.DefineElement(def.Name, def.Name);
                    if (parent.Infra)
                    {
                        def.setInfra();
                    }
                }
            }
            else
            {
                if (parent == null)
                {
                    Console.WriteLine
                        ("Unexpected Root Simple element found: " + element.QualifiedName.Name);
                }
                else
                {
                    bool   isEnum;
                    string dataType =
                        GetClassTypeFromDataType
                            (element.ElementSchemaType, element.QualifiedName.Name, parent.Name,
                            out isEnum);
                    if (isEnum)
                    {
                        Debug.Assert(element.QualifiedName.Name != "SchoolYear");

                        returnVal = parent.DefineElement(element.QualifiedName.Name, null);
                        ((FieldDef)returnVal).SetEnum(dataType);
                    }
                    else
                    {
                        returnVal = parent.DefineElement(element.QualifiedName.Name, dataType);
                    }
                }
            }
            if (returnVal != null)
            {
                returnVal.SetFlags(getFlags(element));
                setAnnotation(returnVal, element.Annotation);
            }
            return(returnVal);
        }
Exemple #22
0
 private void BuildAttributes( XmlSchemaObjectCollection attributes,
                               ObjectDef objectDef )
 {
     foreach ( XmlSchemaObject o in attributes ) {
         if ( o is XmlSchemaAttribute ) {
             BuildAttribute( (XmlSchemaAttribute) o, objectDef );
         }
         else {
             XmlSchemaAttributeGroup group =
                 (XmlSchemaAttributeGroup)
                 Schema.Groups[((XmlSchemaAttributeGroupRef) o).RefName];
             BuildAttributes( group.Attributes, objectDef );
         }
     }
 }
Exemple #23
0
        /// <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;
                            }
                        }
                    }
                }
            }
        }
Exemple #24
0
 private void BuildParticle( XmlSchemaParticle particle,
                             ObjectDef parent,
                             bool attachToParent )
 {
     //System.Diagnostics.Debug.Assert(!particle.SourceUri.EndsWith("TransacationList"));
     if ( particle is XmlSchemaElement ) {
         BuildObjectFromElement( (XmlSchemaElement) particle, parent, attachToParent );
     }
     else if ( particle is XmlSchemaSequence ) {
         foreach ( XmlSchemaParticle particle1 in ((XmlSchemaSequence) particle).Items ) {
             BuildParticle( particle1, parent, true );
         }
     }
     else if ( particle is XmlSchemaChoice ) {
         foreach ( XmlSchemaParticle particle1 in ((XmlSchemaChoice) particle).Items ) {
             // TODO: This element is a choice element, we won't define it on the parent, but we may need to add an element with some type of name ( research );
             BuildParticle( particle1, parent, false );
         }
     }
     else if ( particle is XmlSchemaAny ) {
         // New in SIF 2.0. XML Schema Any just means that the data type of the parent object
         // is Set to represent XML Any
         parent.SetDataType( "any" );
     }
     else {
         throw new SchemaNotImplementedException( particle );
     }
 }
        /// <summary>
        /// Writes the specified object to the XmlDocument passed in. Writes only the object fields, not recursive
        /// </summary>
        /// <param name="def">The object to write</param>
        /// <param name="doc">The document to write the object to</param>
        public static void WriteObjectToDom( ObjectDef def,
                                             XmlDocument doc )
        {
            // TODO: Search for the element first and don't write it if it already exists

            string query = "object[@name=\"" + def.Name + "\"]";
            XmlElement node = (XmlElement) doc.DocumentElement.SelectSingleNode( query );
            if ( node == null ) {
                node = doc.CreateElement( "object" );
                //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.RenderAs != null ) {
                node.SetAttribute( "renderAs", def.RenderAs );
            }
            else {
                if ( node.HasAttribute( "renderAs" ) ) {
                    node.RemoveAttribute( "renderAs" );
                }
            }

            if ( !def.ShouldValidate ) {
                node.SetAttribute( "validate", "false" );
            }
            else {
                if ( node.HasAttribute( "validate" ) ) {
                    node.RemoveAttribute( "validate" );
                }
            }

            if ( def.Topic ) {
                node.SetAttribute( "topic", "true" );
            }
            else {
                if ( node.HasAttribute( "topic" ) ) {
                    node.RemoveAttribute( "topic" );
                }
            }

            if ( (def.Flags & ObjectDef.FLAG_EMPTYOBJECT) > 0 ) {
                node.SetAttribute( "empty", "true" );
            }
            else {
                if ( node.HasAttribute( "empty" ) ) {
                    node.RemoveAttribute( "empty" );
                }
            }

            if ( def.Superclass != null ) {
                if (
                    ! (def.Superclass == "SIFMessagePayload" || def.Superclass == "SIFDataObject" ||
                       def.Superclass == "SIFElement") ) {
                    node.SetAttribute( "type", def.Superclass );
                }
                else {
                    if ( node.HasAttribute( "type" ) ) {
                        node.RemoveAttribute( "type" );
                    }
                }
            }

            if ( def.Draft ) {
                node.SetAttribute( "draft", "true" );
            }
            else {
                if ( node.HasAttribute( "draft" ) ) {
                    node.RemoveAttribute( "draft" );
                }
            }

            if ( def.ExtrasFile != null ) {
                FileInfo info = new FileInfo( def.ExtrasFile );
                node.SetAttribute( "extras", info.Name );
            }
            else {
                if ( node.HasAttribute( "draft" ) ) {
                    node.RemoveAttribute( "draft" );
                }
            }

            WriteDesc( node, def.Desc );
            WriteFieldsToDom( node, def );
        }
        private static void WriteFieldsToDom( XmlElement objectElement,
                                              ObjectDef def )
        {
            FieldDef[] fields = def.Attributes;
            Array.Sort( fields, new FieldDefComparer() );
            foreach ( FieldDef attr in fields ) {
                XmlElement fieldAttribute = objectElement.OwnerDocument.CreateElement( "attribute" );
                objectElement.AppendChild( fieldAttribute );
                WriteFieldToDom( fieldAttribute, attr );
            }

            fields = def.Elements;
            Array.Sort( fields, new FieldDefComparer() );
            foreach ( FieldDef ele in def.Elements ) {
                XmlElement fieldElement = objectElement.OwnerDocument.CreateElement( "element" );
                objectElement.AppendChild( fieldElement );
                WriteFieldToDom( fieldElement, ele );
            }
        }
        /// <summary>
        /// Writes the specified object to the XmlDocument passed in. Writes only the object fields, not recursive
        /// </summary>
        /// <param name="def">The object to write</param>
        /// <param name="doc">The document to write the object to</param>
        public static void WriteObjectToDom(ObjectDef def,
                                            XmlDocument doc)
        {
            // TODO: Search for the element first and don't write it if it already exists

            string     query = "object[@name=\"" + def.Name + "\"]";
            XmlElement node  = (XmlElement)doc.DocumentElement.SelectSingleNode(query);

            if (node == null)
            {
                node = doc.CreateElement("object");
                //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.RenderAs != null)
            {
                node.SetAttribute("renderAs", def.RenderAs);
            }
            else
            {
                if (node.HasAttribute("renderAs"))
                {
                    node.RemoveAttribute("renderAs");
                }
            }

            if (!def.ShouldValidate)
            {
                node.SetAttribute("validate", "false");
            }
            else
            {
                if (node.HasAttribute("validate"))
                {
                    node.RemoveAttribute("validate");
                }
            }

            if (def.Topic)
            {
                node.SetAttribute("topic", "true");
            }
            else
            {
                if (node.HasAttribute("topic"))
                {
                    node.RemoveAttribute("topic");
                }
            }

            if ((def.Flags & ObjectDef.FLAG_EMPTYOBJECT) > 0)
            {
                node.SetAttribute("empty", "true");
            }
            else
            {
                if (node.HasAttribute("empty"))
                {
                    node.RemoveAttribute("empty");
                }
            }


            if (def.Superclass != null)
            {
                if (
                    !(def.Superclass == "SIFMessagePayload" || def.Superclass == "SIFDataObject" ||
                      def.Superclass == "SIFElement"))
                {
                    node.SetAttribute("type", def.Superclass);
                }
                else
                {
                    if (node.HasAttribute("type"))
                    {
                        node.RemoveAttribute("type");
                    }
                }
            }

            if (def.Draft)
            {
                node.SetAttribute("draft", "true");
            }
            else
            {
                if (node.HasAttribute("draft"))
                {
                    node.RemoveAttribute("draft");
                }
            }

            if (def.ExtrasFile != null)
            {
                FileInfo info = new FileInfo(def.ExtrasFile);
                node.SetAttribute("extras", info.Name);
            }
            else
            {
                if (node.HasAttribute("draft"))
                {
                    node.RemoveAttribute("draft");
                }
            }

            WriteDesc(node, def.Desc);
            WriteFieldsToDom(node, def);
        }
Exemple #28
0
 private void BuildContentModel( XmlSchemaComplexType type,
                                 ObjectDef def )
 {
     if ( type.ContentModel != null ) {
         if ( type.ContentModel is XmlSchemaSimpleContent ) {
             XmlSchemaSimpleContent content = type.ContentModel as XmlSchemaSimpleContent;
             XmlSchemaSimpleContentRestriction restriction =
                 content.Content as XmlSchemaSimpleContentRestriction;
             if ( restriction != null ) {
                 FieldDef field;
                 bool isEnum;
                 string dataType =
                     GetClassTypeFromDataType
                         ( restriction.BaseType, type.QualifiedName.Name, def.Name,
                           out isEnum );
                 if ( isEnum ) {
                     field = def.DefineElement( type.QualifiedName.Name, null );
                     field.SetEnum( dataType );
                 }
                 else {
                     field = def.DefineElement( type.QualifiedName.Name, dataType );
                 }
                 if( ( type.Particle != null &&  type.Particle.MinOccurs > 0 ) ||
                     ( type.ContentTypeParticle != null && type.ContentTypeParticle.MinOccurs > 0 ) ) {
                     field.SetFlags( "M" );
                 }
             }
             else {
                 XmlSchemaSimpleContentExtension extension =
                     content.Content as XmlSchemaSimpleContentExtension;
                 BuildAttributes( extension.Attributes, def );
                 //FieldDef field = def.defineElement( type.QualifiedName.Name, extension.BaseTypeName.Name );
             }
         }
         else if ( type.Particle == null && type.ContentModel is XmlSchemaComplexContent ) {
             XmlSchemaComplexContent complexContent =
                 type.ContentModel as XmlSchemaComplexContent;
             XmlSchemaComplexContentExtension ext =
                 type.ContentModel.Content as XmlSchemaComplexContentExtension;
             if ( type.BaseXmlSchemaType != null ) {
                 XmlSchemaComplexType baseType =
                     type.BaseXmlSchemaType as XmlSchemaComplexType;
                 if ( baseType != null ) {
                     BuildContentModel( baseType, def );
                 }
             }
             if ( ext != null && ext.Particle != null ) {
                 if ( ext.BaseTypeName != null ) {
                     object ao = Schema.Elements[ext.BaseTypeName];
                     //string data = ao.ToString();
                 }
                 BuildParticle( ext.Particle, def, true );
             }
         }
     }
     else if ( type.Particle != null ) {
         try {
             BuildParticle( type.Particle, def, true );
         }
         catch ( SchemaNotImplementedException xse ) {
             Console.WriteLine
                 ( "Type Not Implemented: " + type.QualifiedName + " : " +
                   xse.Particle.ToString() + xse.Particle.SourceUri + ":" +
                   xse.Particle.LineNumber );
         }
     }
 }
        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;
            }
        }
Exemple #30
0
        private AbstractDef BuildObjectFromElement( XmlSchemaElement element,
                                                    ObjectDef parent,
                                                    bool attachToParent )
        {
            //System.Diagnostics.Debug.Assert( !( element.QualifiedName.Name == "FineInfo" ) );
            AbstractDef returnVal = null;
            if ( element.ElementSchemaType is XmlSchemaComplexType ) {
                ObjectDef def = fDB.GetObject( element.QualifiedName.Name );
                if ( def != null ) {
                    if ( parent != null && attachToParent ) {
                        returnVal = parent.DefineElement( def.Name, def.Name );
                        if ( parent.Infra ) {
                            def.setInfra();
                        }
                        returnVal.SetFlags( getFlags( element ) );
                        setAnnotation( returnVal, element.Annotation );
                    }
                    if ( parent == null ) {
                        // Reset the source location
                        def.SourceLocation = element.SourceUri + ";line:" + element.LineNumber;
                        def.LocalPackage = getLocalPackage( element.SourceUri );
                        setAnnotation( def, element.Annotation );
                    }
                    // Console.WriteLine( element.QualifiedName.Name + " is already defined, ignoring." );
                    return def;
                }
                //System.Diagnostics.Debug.Assert( !( element.QualifiedName.Name == "StaffPersonal" ) );
                def =
                    fDB.defineObject
                        ( 0, element.QualifiedName.Name, getLocalPackage( element.SourceUri ),
                          element.SourceUri + ";line:" + element.LineNumber );
                returnVal = def;
                XmlSchemaComplexType type = (XmlSchemaComplexType) element.ElementSchemaType;
                BuildAttributes( type.Attributes, def );
                BuildContentModel( type, def );
                if ( parent != null && attachToParent ) {
                    returnVal = parent.DefineElement( def.Name, def.Name );
                    if ( parent.Infra ) {
                        def.setInfra();
                    }
                }
            }
            else {
                if ( parent == null ) {
                    Console.WriteLine
                        ( "Unexpected Root Simple element found: " + element.QualifiedName.Name );
                }
                else {
                    bool isEnum;
                    string dataType =
                        GetClassTypeFromDataType
                            ( element.ElementSchemaType, element.QualifiedName.Name, parent.Name,
                              out isEnum );
                    if ( isEnum ) {
                        Debug.Assert( element.QualifiedName.Name != "SchoolYear" );

                        returnVal = parent.DefineElement( element.QualifiedName.Name, null );
                        ((FieldDef) returnVal).SetEnum( dataType );
                    }
                    else {
                        returnVal = parent.DefineElement( element.QualifiedName.Name, dataType );
                    }
                }
            }
            if ( returnVal != null ) {
                returnVal.SetFlags( getFlags( element ) );
                setAnnotation( returnVal, element.Annotation );
            }
            return returnVal;
        }