Exemplo n.º 1
0
 protected internal virtual void onValue(XmlElement node)
 {
     if (fEnumDef != null)
     {
         String val  = getAttr(node, "value");
         String desc = getAttr(node, "desc");
         String name = getAttr(node, "name");
         if (name == null)
         {
             name = val;
         }
         //fEnumDef.defineValue(name, value_Renamed, desc);
         fEnumDef.DefineValue(name, val, desc);
     }
 }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
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;
                            }
                        }
                    }
                }
            }
        }