private bool InheritFromSuperField(MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
        {
            bool inhertedIsInheriting = false;
            MetaMetadataCompositeField inheritedField = (MetaMetadataCompositeField)SuperField;

            if (inheritedField != null)
            {
                inheritedField.Repository = repository;
                if (inheritedField.InheritInProcess)
                {
                    inhertedIsInheriting = true;

                    // if inheriting from the root mmd, we need to clone and keep the environment right now.
                    InheritanceHandler inheritanceHandlerToUse = inheritanceHandler.clone();
                    inheritanceHandler.Pop(this);

                    //inheritedField.InheritFinished += (sender, e) => InheritFrom(repository, inheritedField);
                    this.AddInheritanceFinishHandler(inheritedField, InheritFieldFinished, inheritanceHandlerToUse);
                }
                else
                {
                    inheritedField.InheritMetaMetadata(inheritanceHandler);
                    InheritFromCompositeField(inheritedField, repository, inheritanceHandler);
                }
            }
            return(inhertedIsInheriting);
        }
        public InheritanceHandler clone()
        {
            InheritanceHandler cloned = new InheritanceHandler(rootMmd);

            cloned.repository = this.repository;
            cloned.mmStack    = new Stack <MetaMetadataField>(this.mmStack);
            //cloned.mmStack.addAll (this.mmStack);
            cloned.scopeStack = new Stack <MultiAncestorScope <Object> >(this.scopeStack);
            //cloned.scopeStack.addAll(this.scopeStack);
            return(cloned);
        }
Exemplo n.º 3
0
        protected override void InheritNonFieldElements(MetaMetadata inheritedMmd, InheritanceHandler inheritanceHandler)
        {
            base.InheritNonFieldElements(inheritedMmd, inheritanceHandler);
            InheritAttributes(inheritedMmd);

            if (this.genericTypeVars != null)
            {
                this.genericTypeVars.InheritFrom(inheritedMmd.genericTypeVars, inheritanceHandler);
            }

            //InheritSemanticActions(inheritedMmd);
        }
Exemplo n.º 4
0
        protected override bool InheritMetaMetadataHelper(InheritanceHandler inheritanceHandler)
        {
            inheritanceHandler = new InheritanceHandler(this);

            // init each field's declaringMmd to this (some of them may change during inheritance)
            foreach (MetaMetadataField field in Kids.Values)
            {
                field.DeclaringMmd = this;
            }

            return(base.InheritMetaMetadataHelper(inheritanceHandler));
        }
Exemplo n.º 5
0
        protected override bool InheritMetaMetadataHelper(InheritanceHandler inheritanceHandler)
        {
            /*
             * the childComposite should hide all complexity between collection fields and composite fields,
             * through hooks when necessary.
             */
            int typeCode = this.GetFieldType();

            switch (typeCode)
            {
            case FieldTypes.CollectionElement:
            {
                // prepare childComposite: possibly new name, type, extends, tag and inheritedField
                MetaMetadataCompositeField childComposite = this.GetChildComposite();
                if (childComposite.Name == UNRESOLVED_NAME)
                {
                    childComposite.Name = (childType ?? Name);
                }
                childComposite.Type             = childType; // here not using setter to reduce unnecessary re-assignment of this.childType
                childComposite.ExtendsAttribute = ChildExtends;
                childComposite.Tag         = childTag;
                childComposite.Repository  = Repository;
                childComposite.PackageName = PackageName;

                if (SuperField != null)
                {
                    childComposite.SuperField = (SuperField as MetaMetadataCollectionField).GetChildComposite();
                }
                childComposite.DeclaringMmd = DeclaringMmd;
                childComposite.Scope        = Scope;

                childComposite.InheritMetaMetadata(inheritanceHandler); // inheritedMmd might be inferred from type/extends

                TypeMmd = childComposite.TypeMmd;
                Scope   = childComposite.Scope;
                break;
            }

            case FieldTypes.CollectionScalar:
            {
                MetaMetadataField inheritedField = SuperField;
                if (inheritedField != null)
                {
                    InheritAttributes(inheritedField);
                }
                break;
            }
            }

            return(true);
        }
        private void InheritMetaMetadataFinished(MetaMetadataNestedField sender, EventArgs e)
        {
            MetaMetadata       inheritedMmd       = (MetaMetadata)_waitingToInheritFrom.Pop();
            InheritanceHandler inheritanceHandler = _waitingToInheritFromInheritanceHandler.Pop();

            InheritFromTopLevelMetaMetadata(inheritedMmd, Repository, inheritanceHandler);

            InheritFromSuperField(Repository, inheritanceHandler);

            if (_waitingToInheritFrom.Count == 0)
            {
                FinishInheritance();
            }
        }
        public void InheritMetaMetadata(InheritanceHandler inheritanceHandler)
        {
            if (inheritDone || _inheritInProcess)
            {
                return;
            }

            //Debug.WriteLine("inheriting " + this);
            _inheritInProcess = true;
            if (InheritMetaMetadataHelper(inheritanceHandler))
            {
                FinishInheritance();
            }
        }
        protected override bool InheritMetaMetadataHelper(InheritanceHandler inheritanceHandler)
        {
            inheritanceHandler.Push(this);

            bool inhertedIsInheriting = false;
            // init
            MetaMetadataRepository repository = Repository;

            // determine the structure we should inherit from
            MetaMetadata inheritedMmd = FindOrGenerateInheritedMetaMetadata(repository, inheritanceHandler);

            if (inheritedMmd != null)
            {
                if (inheritedMmd.InheritInProcess)
                {
                    inhertedIsInheriting = true;

                    // if inheriting from the root mmd, we need to clone and keep the environment right now.
                    InheritanceHandler inheritanceHandlerToUse = inheritanceHandler.clone();
                    inheritanceHandler.Pop(this);

                    //inheritedMmd.InheritFinished += (sender, e) => InheritFromTopLevelMetaMetadata(inheritedMmd, repository);
                    this.AddInheritanceFinishHandler(inheritedMmd, InheritMetaMetadataFinished, inheritanceHandlerToUse);
                }
                else
                {
                    inheritedMmd.InheritMetaMetadata(null); //edit
                    InheritFromTopLevelMetaMetadata(inheritedMmd, repository, inheritanceHandler);
                }
            }
            if (!inhertedIsInheriting)
            {
                inhertedIsInheriting = InheritFromSuperField(repository, inheritanceHandler);
            }

            // for the root meta-metadata, this may happend
            if (inheritedMmd == null && SuperField == null)
            {
                InheritFrom(repository, null, inheritanceHandler);
            }

            return(!inhertedIsInheriting);
        }
Exemplo n.º 9
0
        public void InheritFrom(MmdGenericTypeVarScope superScope, InheritanceHandler inheritanceHandler)
        {
            if (superScope == null)
            {
                return;
            }

            foreach (MmdGenericTypeVar superGenericTypeVar in superScope.Values)
            {
                String            name = superGenericTypeVar.Name;
                MmdGenericTypeVar localGenericTypeVar = this.Get(name);

                if (localGenericTypeVar == null)
                {
                    this.Add(name, superGenericTypeVar);
                }
                else
                {
                    localGenericTypeVar.ResolveArgAndBounds(this);

                    if (superGenericTypeVar.IsAssignment() && localGenericTypeVar.IsAssignment() &&
                        !superGenericTypeVar.Arg.Equals(localGenericTypeVar.Arg))
                    {
                        throw new MetaMetadataException("incompatiable assignments to a generic type var: "
                                                        + name);
                    }
                    else if (superGenericTypeVar.IsAssignment() && localGenericTypeVar.IsBound())
                    {
                        throw new MetaMetadataException("generic type already assigned: " + name);
                    }
                    else if (superGenericTypeVar.IsBound() && localGenericTypeVar.IsAssignment())
                    {
                        CheckAssignmentWithBounds(name, localGenericTypeVar, superGenericTypeVar,
                                                  inheritanceHandler);
                    }
                    else
                    {
                        CheckBoundsWithBounds(name, localGenericTypeVar, superGenericTypeVar, inheritanceHandler);
                    }
                }
            }
        }
Exemplo n.º 10
0
        private void CheckAssignmentWithBounds(String name, MmdGenericTypeVar argGtv,
                                               MmdGenericTypeVar boundGtv, InheritanceHandler inheritanceHandler)
        {
            MetaMetadata argMmd = inheritanceHandler.ResolveMmdName(argGtv.Arg);

            argMmd.InheritMetaMetadata(null);

            MetaMetadata lowerBoundMmd = inheritanceHandler.ResolveMmdName(boundGtv.ExtendsAttribute);

            lowerBoundMmd.InheritMetaMetadata(null);
            bool satisfyLowerBound = lowerBoundMmd == null || argMmd.IsDerivedFrom(lowerBoundMmd);

            // MetaMetadata upperBoundMmd = inheritanceHandler.resolveMmdName(localGtv.getSuperAttribute());
            // boolean satisfyUpperBound = upperBoundMmd == null || upperBoundMmd.isDerivedFrom(argMmd);

            if (!satisfyLowerBound /* || !satisfyUpperBound */)
            {
                throw new MetaMetadataException("generic type bound(s) not satisfied: " + name);
            }
        }
Exemplo n.º 11
0
        private void CheckBoundsWithBounds(String name, MmdGenericTypeVar local, MmdGenericTypeVar other,
                                           InheritanceHandler inheritanceHandler)
        {
            MetaMetadata lowerBoundMmdLocal = inheritanceHandler.ResolveMmdName(local.ExtendsAttribute);

            lowerBoundMmdLocal.InheritMetaMetadata(null);

            MetaMetadata lowerBoundMmdOther = inheritanceHandler.ResolveMmdName(other.ExtendsAttribute);

            lowerBoundMmdOther.InheritMetaMetadata(null);

            bool lowerBoundsCompatible = lowerBoundMmdOther == null ||
                                         lowerBoundMmdLocal.IsDerivedFrom(lowerBoundMmdOther);

            // TODO upperBoundsCompatible

            if (!lowerBoundsCompatible /* || !upperBoundsCompatible */)
            {
                throw new MetaMetadataException("generic type bound(s) not compatible: " + name);
            }
        }
        protected virtual MetaMetadata FindOrGenerateInheritedMetaMetadata(MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
        {
            MetaMetadata inheritedMmd = this.TypeMmd;
            if (inheritedMmd == null)
            {
                MmdScope mmdScope = this.Scope;
                String inheritedMmdName = Type ?? Name;

                if (ExtendsAttribute != null)
                {
                    // determine new type name
                    if (inheritedMmdName == null)
                        throw new MetaMetadataException("attribute 'name' must be specified: " + this);
                    if (inheritanceHandler.ResolveMmdName(inheritedMmdName) != null)
                        // currently we don't encourage re-using existing name. however, in the future, when package names are available, we can change this.
                        throw new MetaMetadataException("meta-metadata '" + inheritedMmdName + "' already exists! please use another name to prevent name collision. hint: use 'tag' to change the tag if needed.");

                    // determine from which meta-metadata to inherit
                    inheritedMmd = inheritanceHandler.ResolveMmdName(ExtendsAttribute);
                    if (ExtendsAttribute == null || inheritedMmd == null)
                        throw new MetaMetadataException("super type not specified or recognized: " + this + ", super type name: " + ExtendsAttribute);

                    // generate inline mmds and put it into current scope
                    MetaMetadata generatedMmd = this.GenerateMetaMetadata(inheritedMmdName, inheritedMmd);
                    mmdScope.Put(inheritedMmdName, generatedMmd);
                    mmdScope.Put(generatedMmd.Name, generatedMmd);

                    // recursively do inheritance on generated mmd
                    generatedMmd.InheritMetaMetadata(null); // this will set generateClassDescriptor to true if necessary

                    MakeThisFieldUseMmd(inheritedMmdName, generatedMmd);
                    return generatedMmd;
                }
                else
                {
                    // use type / extends
                    if (inheritedMmdName == null)
                        throw new MetaMetadataException("no type / extends defined for " + this
                            + " (note that due to a limitation explicit child_scalar_type is needed for scalar collection fields, even if it has been declared in super field).");

                    NameType[] nameType = new NameType[1];
                    inheritedMmd = inheritanceHandler.ResolveMmdName(inheritedMmdName, nameType);

                    if (inheritedMmd == null)
                        throw new MetaMetadataException("meta-metadata not found: " + inheritedMmdName + " (if you want to define new types inline, you need to specify extends/child_extends).");

                    if (!inheritedMmdName.Equals(inheritedMmd.Name) && nameType[0] == NameType.MMD)
                    {
                        // could be inline mmd
                        this.MakeThisFieldUseMmd(inheritedMmdName, inheritedMmd);
                    }

                    // process normal mmd / field
                    Debug.WriteLine("setting " + this + ".inheritedMmd to " + inheritedMmd);
                    TypeMmd = inheritedMmd;
                }
            }
            return inheritedMmd;
        }
Exemplo n.º 13
0
        protected override void InheritFrom(MetaMetadataRepository repository, MetaMetadataCompositeField inheritedStructure, InheritanceHandler inheritanceHandler)
        {
            base.InheritFrom(repository, inheritedStructure, inheritanceHandler);

            // for fields referring to this meta-metadata type
            // need to do inheritMetaMetadata() again after copying fields from this.getInheritedMmd()

/*		    foreach (MetaMetadataField f in this.Kids.Values)
 *                  {
 *                          if (f.GetType() ==  typeof(MetaMetadataNestedField))
 *                          {
 *                                  MetaMetadataNestedField nested = (MetaMetadataNestedField) f;
 *                                  if (nested.InheritedMmd == this)
 *                                  {
 *                                          nested.ClearInheritFinishedOrInProgressFlag();
 *                      nested.InheritMetaMetadata();
 *                                  }
 *                          }
 *                  }
 */
        }
        protected override bool InheritMetaMetadataHelper(InheritanceHandler inheritanceHandler)
        {
            /*
               * the childComposite should hide all complexity between collection fields and composite fields,
               * through hooks when necessary.
               */
              int typeCode = this.GetFieldType();
              switch (typeCode)
              {
            case FieldTypes.CollectionElement:
              {
            // prepare childComposite: possibly new name, type, extends, tag and inheritedField
            MetaMetadataCompositeField childComposite = this.GetChildComposite();
            if (childComposite.Name == UNRESOLVED_NAME)
              childComposite.Name = (childType ?? Name);
            childComposite.Type = childType; // here not using setter to reduce unnecessary re-assignment of this.childType
            childComposite.ExtendsAttribute = ChildExtends;
            childComposite.Tag = childTag;
            childComposite.Repository = Repository;
            childComposite.PackageName = PackageName;

            if (SuperField != null)
              childComposite.SuperField = (SuperField as MetaMetadataCollectionField).GetChildComposite();
            childComposite.DeclaringMmd = DeclaringMmd;
            childComposite.Scope = Scope;

            childComposite.InheritMetaMetadata(inheritanceHandler); // inheritedMmd might be inferred from type/extends

            TypeMmd = childComposite.TypeMmd;
            Scope = childComposite.Scope;
            break;
              }
            case FieldTypes.CollectionScalar:
              {
            MetaMetadataField inheritedField = SuperField;
            if (inheritedField != null)
              InheritAttributes(inheritedField);
            break;
              }
            }

            return true;
        }
        private bool InheritFromSuperField(MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
        {
            bool inhertedIsInheriting = false;
            MetaMetadataCompositeField inheritedField = (MetaMetadataCompositeField)SuperField;
            if (inheritedField != null)
            {
                inheritedField.Repository = repository;
                if (inheritedField.InheritInProcess)
                {
                    inhertedIsInheriting = true;

                    // if inheriting from the root mmd, we need to clone and keep the environment right now.
                    InheritanceHandler inheritanceHandlerToUse = inheritanceHandler.clone();
                    inheritanceHandler.Pop(this);

                    //inheritedField.InheritFinished += (sender, e) => InheritFrom(repository, inheritedField);
                    this.AddInheritanceFinishHandler(inheritedField, InheritFieldFinished, inheritanceHandlerToUse);
                }
                else
                {
                    inheritedField.InheritMetaMetadata(inheritanceHandler);
                    InheritFromCompositeField(inheritedField, repository, inheritanceHandler);
                }
            }
            return inhertedIsInheriting;
        }
 protected virtual void InheritNonFieldElements(MetaMetadata inheritedMmd, InheritanceHandler inheritanceHandler)
 {
     Scope = new MmdScope(Scope, inheritedMmd.Scope);
 }
        public void AddInheritanceFinishHandler(MetaMetadataNestedField inheritingField, InheritFinishedEventHandler eventHandler, InheritanceHandler inheritanceHandler)
        {
            if (_waitingToInheritFrom == null)
            {
                _waitingToInheritFrom = new Stack <MetaMetadataNestedField>();
            }

            _waitingToInheritFrom.Push(inheritingField);

            //adding the InheritanceHandler for this inheritingField
            if (_waitingToInheritFromInheritanceHandler == null)
            {
                _waitingToInheritFromInheritanceHandler = new Stack <InheritanceHandler>();
            }

            _waitingToInheritFromInheritanceHandler.Push(inheritanceHandler);

            inheritingField.InheritFinished += eventHandler;
        }
        protected virtual MetaMetadata FindOrGenerateInheritedMetaMetadata(MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
        {
            MetaMetadata inheritedMmd = this.TypeMmd;

            if (inheritedMmd == null)
            {
                MmdScope mmdScope         = this.Scope;
                String   inheritedMmdName = Type ?? Name;

                if (ExtendsAttribute != null)
                {
                    // determine new type name
                    if (inheritedMmdName == null)
                    {
                        throw new MetaMetadataException("attribute 'name' must be specified: " + this);
                    }
                    if (inheritanceHandler.ResolveMmdName(inheritedMmdName) != null)
                    {
                        // currently we don't encourage re-using existing name. however, in the future, when package names are available, we can change this.
                        throw new MetaMetadataException("meta-metadata '" + inheritedMmdName + "' already exists! please use another name to prevent name collision. hint: use 'tag' to change the tag if needed.");
                    }

                    // determine from which meta-metadata to inherit
                    inheritedMmd = inheritanceHandler.ResolveMmdName(ExtendsAttribute);
                    if (ExtendsAttribute == null || inheritedMmd == null)
                    {
                        throw new MetaMetadataException("super type not specified or recognized: " + this + ", super type name: " + ExtendsAttribute);
                    }

                    // generate inline mmds and put it into current scope
                    MetaMetadata generatedMmd = this.GenerateMetaMetadata(inheritedMmdName, inheritedMmd);
                    mmdScope.Put(inheritedMmdName, generatedMmd);
                    mmdScope.Put(generatedMmd.Name, generatedMmd);

                    // recursively do inheritance on generated mmd
                    generatedMmd.InheritMetaMetadata(null); // this will set generateClassDescriptor to true if necessary

                    MakeThisFieldUseMmd(inheritedMmdName, generatedMmd);
                    return(generatedMmd);
                }
                else
                {
                    // use type / extends
                    if (inheritedMmdName == null)
                    {
                        throw new MetaMetadataException("no type / extends defined for " + this
                                                        + " (note that due to a limitation explicit child_scalar_type is needed for scalar collection fields, even if it has been declared in super field).");
                    }

                    NameType[] nameType = new NameType[1];
                    inheritedMmd = inheritanceHandler.ResolveMmdName(inheritedMmdName, nameType);

                    if (inheritedMmd == null)
                    {
                        throw new MetaMetadataException("meta-metadata not found: " + inheritedMmdName + " (if you want to define new types inline, you need to specify extends/child_extends).");
                    }

                    if (!inheritedMmdName.Equals(inheritedMmd.Name) && nameType[0] == NameType.MMD)
                    {
                        // could be inline mmd
                        this.MakeThisFieldUseMmd(inheritedMmdName, inheritedMmd);
                    }

                    // process normal mmd / field
                    Debug.WriteLine("setting " + this + ".inheritedMmd to " + inheritedMmd);
                    TypeMmd = inheritedMmd;
                }
            }
            return(inheritedMmd);
        }
 protected virtual void InheritNonFieldElements(MetaMetadata inheritedMmd, InheritanceHandler inheritanceHandler)
 {
     Scope = new MmdScope(Scope, inheritedMmd.Scope);
 }
        protected virtual void InheritFrom(MetaMetadataRepository repository,
                                           MetaMetadataCompositeField inheritedStructure,
                                           InheritanceHandler inheritanceHandler)
        {
            // init nested fields inside this
            var subfields = Kids.Values;

            foreach (MetaMetadataField f in subfields)
            {
                if (f is MetaMetadataNestedField)
                {
                    f.Repository = (repository);
                    MetaMetadataNestedField nested = (MetaMetadataNestedField)f;
                    if (nested.PackageName == null)
                    {
                        nested.PackageName = PackageName;
                    }
                    nested.Scope = Scope;
                }
            }

            // inherit fields with attributes from inheritedStructure
            // if inheritedStructure == null, this must be the root meta-metadata
            if (inheritedStructure != null)
            {
                var inheritedStructSubfields = inheritedStructure.Kids.Values;
                foreach (MetaMetadataField field in inheritedStructSubfields)
                {
                    if (field is MetaMetadataNestedField)
                    {
                        ((MetaMetadataNestedField)field).InheritMetaMetadata(inheritanceHandler);
                    }
                    string            fieldName = field.Name;
                    MetaMetadataField fieldLocal;
                    kids.TryGetValue(fieldName, out fieldLocal);

                    if (fieldLocal == null && inheritanceHandler.IsUsingGenerics(field))
                    {
                        // if the super field is using generics, we will need to re-evaluate generic type vars
                        fieldLocal = (MetaMetadataField)Activator.CreateInstance(field.GetType());

                        //Prepare Child Field For Inheritance
                        fieldLocal.Repository = (repository);
                        if (fieldLocal is MetaMetadataNestedField)
                        {
                            MetaMetadataNestedField nested = (MetaMetadataNestedField)fieldLocal;
                            if (nested.PackageName == null)
                            {
                                nested.PackageName = PackageName;
                            }
                            nested.Scope = Scope;
                        }
                    }
                    if (fieldLocal != null)
                    {
                        Debug.WriteLine("inheriting field: " + fieldLocal + " <= " + field);
                        if (field.GetType() != fieldLocal.GetType())
                        {
                            Debug.WriteLine("local field " + fieldLocal + " hides field " + fieldLocal +
                                            " with the same name in super mmd type!");
                        }
                        // debug("inheriting field " + fieldLocal + " from " + field);
                        if (field != fieldLocal)
                        {
                            fieldLocal.SuperField = field;
                        }
                        fieldLocal.DeclaringMmd = field.DeclaringMmd;
                        fieldLocal.InheritAttributes(field);
                        if (fieldLocal is MetaMetadataNestedField)
                        {
                            ((MetaMetadataNestedField)fieldLocal).PackageName =
                                ((MetaMetadataNestedField)field).PackageName;
                        }
                    }
                }
            }

            // recursively call inheritMetaMetadata() on nested fields
            foreach (MetaMetadataField f in subfields)
            {
                // a new field is defined inside this mmd
                if (f.DeclaringMmd == this && f.SuperField == null)
                {
                    SetNewMetadataClass(true);
                }

                // recursively call this method on nested fields
                f.Repository = repository;
                if (f is MetaMetadataNestedField)
                {
                    MetaMetadataNestedField f1 = (MetaMetadataNestedField)f;
                    f1.InheritMetaMetadata(inheritanceHandler);
                    if (f1.IsNewMetadataClass())
                    {
                        SetNewMetadataClass(true);
                    }

                    MetaMetadataNestedField f0 = (MetaMetadataNestedField)f.SuperField;
                    if (f0 != null && f0.GetTypeName() != f1.GetTypeName())
                    {
                        // inherited field w changing base type (polymorphic case)
                        f1.InheritMetaMetadata(inheritanceHandler);
                        MetaMetadata mmd0 = f0.TypeMmd;
                        MetaMetadata mmd1 = f1.TypeMmd;
                        if (mmd1.IsDerivedFrom(mmd0))
                        {
                            SetNewMetadataClass(true);
                        }
                        else
                        {
                            throw new MetaMetadataException("incompatible types: " + mmd0 + " => " + mmd1);
                        }
                    }
                }
            }

            // clone fields only declared in inheritedStructure.
            // must clone them after recursively calling inheritMetaMetadata(), so that their nested
            // structures (which may be inherited too) can be cloned.
            if (inheritedStructure != null)
            {
                var inheritedStructSubfields = inheritedStructure.Kids.Values;
                foreach (MetaMetadataField field in inheritedStructSubfields)
                {
                    string            fieldName = field.Name;
                    MetaMetadataField fieldLocal;
                    kids.TryGetValue(fieldName, out fieldLocal);

                    if (fieldLocal == null)
                    {
                        //					MetaMetadataField clonedField = (MetaMetadataField) field.clone();
                        //					clonedField.setParent(this);
                        //					this.getChildMetaMetadata().put(fieldName, clonedField);
                        kids.Put(fieldName, field);
                    }
                }
            }
        }
 private void InheritFromTopLevelMetaMetadata(MetaMetadata inheritedMmd, MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
 {
     InheritNonFieldElements(inheritedMmd, inheritanceHandler);
     InheritFrom(repository, inheritedMmd, inheritanceHandler);
 }
 private void InheritFromCompositeField(MetaMetadataCompositeField inheritedField, MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
 {
     InheritFrom(repository, inheritedField, inheritanceHandler);
 }
 protected abstract bool InheritMetaMetadataHelper(InheritanceHandler inheritanceHandler);
        protected virtual void InheritFrom(MetaMetadataRepository repository,
            MetaMetadataCompositeField inheritedStructure,
            InheritanceHandler inheritanceHandler)
        {
            // init nested fields inside this
            var subfields = Kids.Values;
            foreach (MetaMetadataField f in subfields)
                if (f is MetaMetadataNestedField)
                {
                    f.Repository = (repository);
                    MetaMetadataNestedField nested = (MetaMetadataNestedField) f;
                    if (nested.PackageName == null)
                        nested.PackageName = PackageName;
                    nested.Scope = Scope;
                }

            // inherit fields with attributes from inheritedStructure
            // if inheritedStructure == null, this must be the root meta-metadata
            if (inheritedStructure != null)
            {
                var inheritedStructSubfields = inheritedStructure.Kids.Values;
                foreach (MetaMetadataField field in inheritedStructSubfields)
                {
                    if (field is MetaMetadataNestedField)
                    {
                        ((MetaMetadataNestedField)field).InheritMetaMetadata(inheritanceHandler);
                    }
                    string fieldName = field.Name;
                    MetaMetadataField fieldLocal;
                    kids.TryGetValue(fieldName, out fieldLocal);

                    if (fieldLocal == null && inheritanceHandler.IsUsingGenerics(field))
                    {
                        // if the super field is using generics, we will need to re-evaluate generic type vars
                        fieldLocal = (MetaMetadataField) Activator.CreateInstance(field.GetType());

                        //Prepare Child Field For Inheritance
                        fieldLocal.Repository = (repository);
                        if (fieldLocal is MetaMetadataNestedField)
                        {
                            MetaMetadataNestedField nested = (MetaMetadataNestedField)fieldLocal;
                            if (nested.PackageName == null)
                                nested.PackageName = PackageName;
                            nested.Scope = Scope;
                        }
                    }
                    if (fieldLocal != null)
                    {
                        Debug.WriteLine("inheriting field: " + fieldLocal + " <= " + field);
                        if (field.GetType() != fieldLocal.GetType())
                            Debug.WriteLine("local field " + fieldLocal + " hides field " + fieldLocal +
                                            " with the same name in super mmd type!");
                        // debug("inheriting field " + fieldLocal + " from " + field);
                        if (field != fieldLocal)
                            fieldLocal.SuperField = field;
                        fieldLocal.DeclaringMmd = field.DeclaringMmd;
                        fieldLocal.InheritAttributes(field);
                        if (fieldLocal is MetaMetadataNestedField)
                            ((MetaMetadataNestedField)fieldLocal).PackageName =
                                ((MetaMetadataNestedField)field).PackageName;
                    }
                }
            }

            // recursively call inheritMetaMetadata() on nested fields
            foreach (MetaMetadataField f in subfields)
            {
                // a new field is defined inside this mmd
                if (f.DeclaringMmd == this && f.SuperField == null)
                    SetNewMetadataClass(true);

                // recursively call this method on nested fields
                f.Repository = repository;
                if (f is MetaMetadataNestedField)
                {
                    MetaMetadataNestedField f1 = (MetaMetadataNestedField) f;
                    f1.InheritMetaMetadata(inheritanceHandler);
                    if (f1.IsNewMetadataClass())
                        SetNewMetadataClass(true);

                    MetaMetadataNestedField f0 = (MetaMetadataNestedField) f.SuperField;
                    if (f0 != null && f0.GetTypeName() != f1.GetTypeName())
                    {
                        // inherited field w changing base type (polymorphic case)
                        f1.InheritMetaMetadata(inheritanceHandler);
                        MetaMetadata mmd0 = f0.TypeMmd;
                        MetaMetadata mmd1 = f1.TypeMmd;
                        if (mmd1.IsDerivedFrom(mmd0))
                            SetNewMetadataClass(true);
                        else
                            throw new MetaMetadataException("incompatible types: " + mmd0 + " => " + mmd1);
                    }
                }
            }

            // clone fields only declared in inheritedStructure.
            // must clone them after recursively calling inheritMetaMetadata(), so that their nested
            // structures (which may be inherited too) can be cloned.
            if (inheritedStructure != null)
            {
                var inheritedStructSubfields = inheritedStructure.Kids.Values;
                foreach (MetaMetadataField field in inheritedStructSubfields)
                {
                    string fieldName = field.Name;
                    MetaMetadataField fieldLocal;
                    kids.TryGetValue(fieldName, out fieldLocal);

                    if (fieldLocal == null)
                    {
                        //					MetaMetadataField clonedField = (MetaMetadataField) field.clone();
                        //					clonedField.setParent(this);
                        //					this.getChildMetaMetadata().put(fieldName, clonedField);
                        kids.Put(fieldName, field);
                    }
                }
            }
        }
        protected override bool InheritMetaMetadataHelper(InheritanceHandler inheritanceHandler)
        {
            inheritanceHandler.Push(this);

            bool inhertedIsInheriting = false;
            // init
            MetaMetadataRepository repository = Repository;

            // determine the structure we should inherit from
            MetaMetadata inheritedMmd = FindOrGenerateInheritedMetaMetadata(repository, inheritanceHandler);
            if (inheritedMmd != null)
            {
                if (inheritedMmd.InheritInProcess)
                {
                    inhertedIsInheriting = true;

                    // if inheriting from the root mmd, we need to clone and keep the environment right now.
                    InheritanceHandler inheritanceHandlerToUse = inheritanceHandler.clone();
                    inheritanceHandler.Pop(this);

                    //inheritedMmd.InheritFinished += (sender, e) => InheritFromTopLevelMetaMetadata(inheritedMmd, repository);
                    this.AddInheritanceFinishHandler(inheritedMmd, InheritMetaMetadataFinished, inheritanceHandlerToUse);
                }
                else
                {
                    inheritedMmd.InheritMetaMetadata(null); //edit
                    InheritFromTopLevelMetaMetadata(inheritedMmd, repository, inheritanceHandler);
                }
            }
            if (!inhertedIsInheriting)
            {
                inhertedIsInheriting = InheritFromSuperField(repository, inheritanceHandler);
            }

            // for the root meta-metadata, this may happend
            if (inheritedMmd == null && SuperField == null)
                InheritFrom(repository, null, inheritanceHandler);

            return !inhertedIsInheriting;
        }
        public void AddInheritanceFinishHandler(MetaMetadataNestedField inheritingField, InheritFinishedEventHandler eventHandler, InheritanceHandler inheritanceHandler)
        {
            if (_waitingToInheritFrom == null)
                _waitingToInheritFrom = new Stack<MetaMetadataNestedField>();

            _waitingToInheritFrom.Push(inheritingField);

            //adding the InheritanceHandler for this inheritingField
            if (_waitingToInheritFromInheritanceHandler == null)
                _waitingToInheritFromInheritanceHandler = new Stack<InheritanceHandler>();

            _waitingToInheritFromInheritanceHandler.Push(inheritanceHandler);

            inheritingField.InheritFinished += eventHandler;
        }
 private void InheritFromCompositeField(MetaMetadataCompositeField inheritedField, MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
 {
     InheritFrom(repository, inheritedField, inheritanceHandler);
 }
        public void InheritMetaMetadata(InheritanceHandler inheritanceHandler)
        {
            if (inheritDone || _inheritInProcess) return;

            //Debug.WriteLine("inheriting " + this);
            _inheritInProcess = true;
            if (InheritMetaMetadataHelper(inheritanceHandler))
                FinishInheritance();
        }
 private void InheritFromTopLevelMetaMetadata(MetaMetadata inheritedMmd, MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
 {
     InheritNonFieldElements(inheritedMmd, inheritanceHandler);
     InheritFrom(repository, inheritedMmd, inheritanceHandler);
 }
 protected abstract bool InheritMetaMetadataHelper(InheritanceHandler inheritanceHandler);
 public InheritanceHandler clone()
 {
     InheritanceHandler cloned = new InheritanceHandler(rootMmd);
     cloned.repository = this.repository;
     cloned.mmStack = new Stack<MetaMetadataField>(this.mmStack);
     //cloned.mmStack.addAll (this.mmStack);
     cloned.scopeStack = new Stack<MultiAncestorScope<Object>>(this.scopeStack);
     //cloned.scopeStack.addAll(this.scopeStack);
     return cloned;
 }
Exemplo n.º 32
0
        protected override MetaMetadata FindOrGenerateInheritedMetaMetadata(MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
        {
            if (MetaMetadata.IsRootMetaMetadata(this))
            {
                return(null);
            }

            MetaMetadata inheritedMmd = this.TypeMmd;

            if (inheritedMmd == null)
            {
                String inheritedMmdName = this.Type;
                if (inheritedMmdName == null)
                {
                    inheritedMmdName = this.ExtendsAttribute;
                    SetNewMetadataClass(true);
                }
                if (inheritedMmdName == null)
                {
                    throw new MetaMetadataException("no type/extends specified: " + this);
                }
                inheritedMmd = (MetaMetadata)this.Scope[inheritedMmdName];
                if (inheritedMmd == null)
                {
                    throw new MetaMetadataException("meta-metadata '" + inheritedMmdName + "' not found.");
                }
                TypeMmd = inheritedMmd;
            }
            return(inheritedMmd);
        }