Exemple #1
0
        private FieldDef[] GetFields( int flags )
        {
            ArrayList v = new ArrayList();
            foreach ( FieldDef f in fFields.Values ) {
                if ( (f.Flags & flags) != 0 ) {
                    v.Add( f );
                }
            }

            if ( (flags & FLAG_MANDATORY) != 0 ) {
                FieldDef valueDef = GetValueDef();
                if ( valueDef != null ) {
                    v.Add( valueDef );
                }
            }

            FieldDef[] arr = new FieldDef[v.Count];
            v.CopyTo( arr );

            Array.Sort( arr );

            return arr;
        }
Exemple #2
0
 public FieldDef GetValueDef()
 {
     FieldDef returnValue = null;
     FieldType valueType = GetValueType();
     if ( valueType != null ) {
         try {
             returnValue =
                 new FieldDef
                     ( this, "Value", valueType, 999,
                       FieldDef.FLAG_TEXT_VALUE | FLAG_MANDATORY );
         }
         catch ( ParseException parseEx ) {
             Console.WriteLine( parseEx );
             throw parseEx;
         }
         returnValue.Desc = "Gets or sets the content value of the <" + this.fName +
                            "> element";
         returnValue.EarliestVersion = this.EarliestVersion;
         returnValue.LatestVersion = this.LatestVersion;
         // returnValue.ElementDefConst =  this.PackageQualifiedDTDSymbol;
     }
     return returnValue;
 }
Exemple #3
0
        private FieldDef DefineAttrOrElement( string name,
                                              string classType,
                                              int type )
        {
            FieldDef def = null;

            if ( fFields.ContainsKey( name ) ) {
                def = fFields[name];
            }
            else {
                def = new FieldDef( this, name, classType, fFieldSeq++, type );
                fFields[name] = def;
            }

            return def;
        }
        private static void WriteFieldToDom( XmlElement fieldElement,
                                             FieldDef field )
        {
            fieldElement.SetAttribute( "name", field.Name );
            FieldType type = field.FieldType;
            if ( type.IsEnum ) {
                fieldElement.SetAttribute( "enum", type.Enum );
            }
            else {
                fieldElement.SetAttribute( "type", type.MetadataType );
            }

            if ( field.RenderAs != null ) {
                fieldElement.SetAttribute( "renderAs", field.RenderAs );
            }

            fieldElement.SetAttribute( "flags", field.GetFlags() );

            if ( field.Draft ) {
                fieldElement.SetAttribute( "draft", "true" );
            }

            if ( field.Attribute && (field.fFlags & FieldDef.FLAG_NOT_A_KEY) > 0 ) {
                fieldElement.SetAttribute( "key", "false" );
            }

                WriteDesc( fieldElement, field.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();
        }
        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 );
        }
        public bool FlagIntrinsicallyMatches( FieldDef counterpart )
        {
            if (fFlags == counterpart.fFlags)
            {
                return true;
            }
            else if ((fFlags & FLAG_REPEATABLE) == 0 &&
                ((fFlags & FLAG_REQUIRED) > 0 || (fFlags & FLAG_MANDATORY) > 0) )
            {
                return ((counterpart.fFlags & FLAG_REQUIRED) > 0 ||
                        (counterpart.fFlags & FLAG_MANDATORY) > 0 );

            }
            return GetFlags() == counterpart.GetFlags();
        }