protected override void CustomizeFieldDescriptor(SimplTypesScope metadataTScope, MetadataFieldDescriptorProxy fdProxy)
        {
            base.CustomizeFieldDescriptor(metadataTScope, fdProxy);

            MetaMetadata thisMmd = TypeMmd;

            if (thisMmd == null)
            {
                return;
            }

            MetaMetadataNestedField inheritedField = (MetaMetadataNestedField)SuperField;

            if (inheritedField != null)
            {
                MetaMetadata superMmd = inheritedField.TypeMmd;
                if (thisMmd == superMmd || thisMmd.IsDerivedFrom(superMmd))
                {
                    MetadataClassDescriptor elementMetadataCD = thisMmd.GetMetadataClassDescriptor(metadataTScope);
                    if (elementMetadataCD != null)
                    {
                        fdProxy.SetElementClassDescriptor(elementMetadataCD);
                    }
                    else
                    {
                        Debug.WriteLineIf(BigSemanticsSettings.DebugLevel > 5, "can't bind FieldDescriptor because metadata class does not exist for: " + thisMmd.ToString());
                    }
                }
                else
                {
                    throw new MetaMetadataException("incompatible types: " + inheritedField + " => " + this);
                }
            }
        }
Example #2
0
        private void CustomizeFieldDescriptorInClass(SimplTypesScope metadataTScope, MetadataClassDescriptor metadataCd)
        {
            MetadataFieldDescriptor oldFD =
                (MetadataFieldDescriptor)metadataCd.GetFieldDescriptorByFieldName(GetFieldName(false));
            String newTagName = MetadataFieldDescriptor.TagName;

            metadataCd.Replace(oldFD, MetadataFieldDescriptor);

            MetadataFieldDescriptor wrapperFD = (MetadataFieldDescriptor)MetadataFieldDescriptor.Wrapper;

            if (wrapperFD != null)
            {
                MetadataFieldDescriptor clonedWrapperFD = wrapperFD.Clone();
                clonedWrapperFD.TagName   = newTagName;
                clonedWrapperFD.WrappedFd = metadataFieldDescriptor;
                metadataCd.Replace(wrapperFD, clonedWrapperFD);
            }

            int fieldType = MetadataFieldDescriptor.FdType;

            if (fieldType == FieldTypes.CollectionElement || fieldType == FieldTypes.MapElement)
            {
                if (!MetadataFieldDescriptor.IsWrapped)
                {
                    string childTagName = MetadataFieldDescriptor.CollectionOrMapTagName;
                    oldFD = (MetadataFieldDescriptor)metadataCd.GetFieldDescriptorByTag(childTagName);
                    metadataCd.Replace(oldFD, MetadataFieldDescriptor);
                }
            }
        }
Example #3
0
 public void SetElementClassDescriptor(MetadataClassDescriptor metadataClassDescriptor)
 {
     if (metadataClassDescriptor != outer.MetadataFieldDescriptor.ElementClassDescriptor)
     {
         CloneFieldDescriptorOnWrite();
         outer.MetadataFieldDescriptor.SetElementClassDescriptor(metadataClassDescriptor);
     }
 }
Example #4
0
        internal Type GetMetadataClass(SimplTypesScope metadataTScope)
        {
            Type result = metadataClass;

            if (result == null)
            {
                MetadataClassDescriptor descriptor = this.MetadataClassDescriptor;
                result        = (descriptor == null ? null : descriptor.DescribedClass);
                metadataClass = result;
            }
            return(result);
        }
        protected internal virtual MetadataClassDescriptor BindMetadataClassDescriptor(SimplTypesScope metadataTScope)
        {
            MetadataClassDescriptor metadataCd = this.MetadataClassDescriptor;

            if (metadataCd == null)
            {
                metadataCd = GetMetadataClassDescriptor(metadataTScope);
                if (metadataCd != null)
                {
                    this.MetadataClassDescriptor = metadataCd; // early assignment to prevent infinite loop
                    this.BindMetadataFieldDescriptors(metadataTScope, metadataCd);
                }
            }
            return(metadataCd);
        }
Example #6
0
        /**
         * For the root, compare the meta-metadata from the binding with the one we started with. Down the
         * hierarchy, try to perform similar bindings.
         */
        public void DeserializationPreHook(MetadataNS.Metadata deserializedMetadata, MetadataFieldDescriptor mfd)
        {
            if (deserializingRoot)
            {
                deserializingRoot = false;
                Document document = GetDocument();
                MetaMetadataCompositeField preMM = document.MetaMetadata;
                MetadataClassDescriptor    mcd   = (MetadataClassDescriptor)ClassDescriptor.GetClassDescriptor(deserializedMetadata);;
                MetaMetadataCompositeField metaMetadata;
                String tagName = mcd.TagName;
                if (preMM.GetTagForTranslationScope().Equals(tagName))
                {
                    metaMetadata = preMM;
                }
                else
                {               // just match in translation scope
                    //TODO use local TranslationScope if there is one
                    metaMetadata = SemanticsSessionScope.MetaMetadataRepository.GetMMByName(tagName);
                }
                deserializedMetadata.MetaMetadata = metaMetadata;

                currentMMstack.Push(metaMetadata);
            }
            else
            {
                String mmName = mfd.MmName;
                MetaMetadataNestedField currentMM     = currentMMstack.Peek();
                MetaMetadataNestedField childMMNested = (MetaMetadataNestedField)currentMM.LookupChild(mmName);              // this fails for collections :-(
                if (childMMNested == null)
                {
                    throw new Exception("Can't find composite child meta-metadata for " + mmName + " amidst " + mfd +
                                        "\n\tThis probably means there is a conflict between the meta-metadata repository and the runtime." +
                                        "\n\tProgrammer: Have you Changed the fields in built-in Metadata subclasses without updating primitives.xml???!");
                }
                MetaMetadataCompositeField childMMComposite = null;
                if (childMMNested.IsPolymorphicInherently)
                {
                    String tagName = ClassDescriptor.GetClassDescriptor(deserializedMetadata).TagName;
                    childMMComposite = SemanticsSessionScope.MetaMetadataRepository.GetMMByName(tagName);
                }
                else
                {
                    childMMComposite = childMMNested.GetMetaMetadataCompositeField();
                }
                deserializedMetadata.MetaMetadata = childMMComposite;
                currentMMstack.Push(childMMComposite);
            }
        }
Example #7
0
        private void AddToRepositoryByClassName(MetaMetadata mmd)
        {
            if (mmd.ExtendsAttribute != null || mmd.IsNewMetadataClass())
            {
                MetadataClassDescriptor mcd = mmd.MetadataClassDescriptor;
                if (mcd != null)
                {
                    RepositoryByClassName.Put(mcd.DescribedClass.Name, mmd);
                }

                foreach (MetaMetadata localMmd in mmd.Scope.valuesOfType <MetaMetadata>())
                {
                    AddToRepositoryByClassName(localMmd);
                }
            }
        }
        MetadataClassDescriptor GetMetadataClassDescriptor(SimplTypesScope metadataTScope)
        {
            MetadataClassDescriptor metadataCd = this.metadataClassDescriptor;

            if (metadataCd == null)
            {
                //this.InheritMetaMetadata(null); //edit

                String metadataClassSimpleName = this.GetMetadataClassSimpleName();
                // first look up by simple name, since package names for some built-ins are wrong

                metadataCd =
                    (MetadataClassDescriptor)metadataTScope.GetClassDescriptorBySimpleName(metadataClassSimpleName);
                if (metadataCd == null)
                {
                    String metadataClassName = this.GetMetadataClassName();

                    metadataCd = (MetadataClassDescriptor)metadataTScope.GetClassDescriptorByClassName(metadataClassName);
                    if (metadataCd == null)
                    {
                        try
                        {
                            Type metadataType = Type.GetType(metadataClassName) ??
                                                Type.GetType(metadataClassName +
                                                             AsemblyQualifiedNameForGeneratedSemantics);
                            this.metadataClass = metadataType;
                            if (MetadataClass != null)
                            {
                                metadataCd = (MetadataClassDescriptor)ClassDescriptor.GetClassDescriptor(MetadataClass);
                                metadataTScope.AddTranslation(MetadataClass);
                            }
                            else
                            {
                                Debug.WriteLineIf(BigSemanticsSettings.DebugLevel > 5, "Cannot find metadata class " + metadataClassName + " for " + this);
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine("Exception: " + e.Message);
                            Debug.WriteLine("Stacktrace:\n" + e.StackTrace);
                            Debug.WriteLine("Cannot find metadata class " + metadataClassName + " for " + this);
                        }
                    }
                }
            }
            return(metadataCd);
        }
        public static String GetMdClassNameFromMmdOrNoChange(String mmdName,
                                                             MetaMetadataRepository repository, MmdCompilerService compilerService)
        {
            MetaMetadata mmd = repository.GetMMByName(mmdName);

            if (mmd == null)
            {
                return(mmdName);
            }
            else
            {
                MetadataClassDescriptor metadataClassDescriptor = mmd.MetadataClassDescriptor;
                if (compilerService != null)
                {
                    compilerService.AddCurrentClassDependency(metadataClassDescriptor);
                }
                return(metadataClassDescriptor.DescribedClassSimpleName);
            }
        }
        public new MetadataClassDescriptor BindMetadataClassDescriptor(SimplTypesScope metadataTScope)
        {
            if (metadataClassDescriptor != null)
            {
                return(metadataClassDescriptor);
            }

            // create a temporary local metadata translation scope
            SimplTypesScope localMetadataTScope = SimplTypesScope.Get("mmd_local_tscope:" + Name, metadataTScope);

            // record the initial number of classes in the local translation scope

            int initialLocalTScopeSize = localMetadataTScope.EntriesByClassName.Count;

            // do actual stuff ...
            base.BindMetadataClassDescriptor(localMetadataTScope);

            // if tag overlaps, or there are fields using classes not in metadataTScope, use localTScope
            MetadataClassDescriptor thisCd = this.MetadataClassDescriptor;

            if (thisCd != null)
            {
                MetadataClassDescriptor thatCd = (MetadataClassDescriptor)metadataTScope.GetClassDescriptorByTag(thisCd.TagName);
                if (thisCd != thatCd)
                {
                    localMetadataTScope.AddTranslation(thisCd);
                    this.localMetadataTranslationScope = localMetadataTScope;
                }
                else if (localMetadataTScope.EntriesByClassName.Count > initialLocalTScopeSize)
                {
                    this.localMetadataTranslationScope = localMetadataTScope;
                }
                else
                {
                    this.localMetadataTranslationScope = metadataTScope;
                }
            }

            // return the bound metadata class descriptor
            return(thisCd);
        }
Example #11
0
        /// <summary>
        ///
        /// Recursively bind MetadataFieldDescriptors to all MetaMetadataFields. Perform other
        /// initialization.
        /// </summary>
        /// <param name="metadataTScope"></param>
        public void BindMetadataClassDescriptorsToMetaMetadata(SimplTypesScope metadataTScope)
        {
            this.MetadataTScope = metadataTScope;

            //TraverseAndInheritMetaMetadata();

            // global metadata classes
            // use another copy because we may modify the scope during the process
            List <MetaMetadata> mmds = new List <MetaMetadata>(_repositoryByName.Values);

            foreach (MetaMetadata mmd in mmds)
            {
                MetadataClassDescriptor mcd = mmd.BindMetadataClassDescriptor(metadataTScope);
                if (mcd == null)
                {
                    Debug.WriteLineIf(BigSemanticsSettings.DebugLevel > 5, "Cannot bind metadata class descriptor for " + mmd);
                    this.RepositoryByName.Remove(mmd.Name);
                }
            }

            // other initialization stuffs
            foreach (MetaMetadata mmd in RepositoryByName.Values)
            {
                AddToRepositoryByClassName(mmd);
                //mmd.setUpLinkWith(this); //Note Implement linking.
            }
            if (PackageMmdScopes != null)
            {
                foreach (MmdScope scope in this.PackageMmdScopes.Values)
                {
                    foreach (MetaMetadata mmd in scope.Values)
                    {
                        AddToRepositoryByClassName(mmd);
                        //mmd.setUpLinkWith(this); //Note Implement linking.
                    }
                }
            }

            InitializeLocationBasedMaps();
        }
Example #12
0
        public MetadataFieldDescriptor BindMetadataFieldDescriptor(SimplTypesScope metadataTScope, MetadataClassDescriptor metadataCd)
        {
            MetadataFieldDescriptor metadataFd = MetadataFieldDescriptor;

            if (metadataFd == null)
            {
                metadataFd = MetadataFieldDescriptor;
                String fieldName = this.GetFieldName(false);
                if (metadataFd == null)
                {
                    FieldDescriptor fd = metadataCd.GetFieldDescriptorByFieldName(fieldName);
                    metadataFd = (MetadataFieldDescriptor)fd;
                    if (metadataFd != null)
                    {
                        // FIXME is the following "if" statement still useful? I never see the condition is
                        // true. can we remove it? -- yin 7/26/2011
                        // if we don't have a field, then this is a wrapped collection, so we need to get the
                        // wrapped field descriptor
                        if (metadataFd.Field == null)
                        {
                            FieldDescriptor wfd = metadataFd.WrappedFd;
                            metadataFd = (MetadataFieldDescriptor)wfd;
                        }

                        MetadataFieldDescriptor = metadataFd;

                        if (MetadataFieldDescriptor != null)
                        {
                            // it is possible that the fieldescriptor in the fieldDescriptor proxy has been removed during clone.
                            // if so, make a new fieldDescriptorProxy.
                            if (!_fieldDescriptorProxy.FieldDescriptorExists())
                            {
                                _fieldDescriptorProxy = new MetadataFieldDescriptorProxy(this);
                            }
                            CustomizeFieldDescriptor(metadataTScope, _fieldDescriptorProxy);
                        }
                        if (MetadataFieldDescriptor != metadataFd)
                        {
                            // the field descriptor has been modified in customizeFieldDescriptor()!
                            // we need to update it in the class descriptor so that deserialization of metadata
                            // objects can work correctly, e.g. using the right classDescriptor for a composite
                            // field or a right elementClassDescriptor for a collection field.

                            CustomizeFieldDescriptorInClass(metadataTScope, metadataCd);
                            //String tagName = this.metadataFieldDescriptor.TagName;
                            //int fieldType = this.metadataFieldDescriptor.FdType;
                            //if (fieldType == FieldTypes.CollectionElement || fieldType == FieldTypes.MapElement)
                            //    tagName = this.metadataFieldDescriptor.CollectionOrMapTagName;
                            //metadataClassDescriptor.AllFieldDescriptorsByTagNames.Put(tagName,
                            //                                                          this.metadataFieldDescriptor);
                        }
                    }
                }
                else
                {
                    Debug.WriteLine("Ignoring <" + fieldName +
                                    "> because no corresponding MetadataFieldDescriptor can be found.");
                }
            }
            return(metadataFieldDescriptor);
        }
        /**
         * bind metadata field descriptors to sub-fields of this nested field, with field names as keys,
         * but without mixins field.
         * <p>
         * sub-fields that lack corresponding field descriptors will be removed from this nested field.
         * <p>
         * note that this field no longer uses a boolean flag to prevent multiple invocation. this should
         * have been done by the bindClassDescriptor() method.
         *
         * @param metadataTScope
         *          the translation scope of (generated) metadata classes.
         * @param metadataClassDescriptor
         *          the metadata class descriptor where field descriptors can be found.
         */

        protected void BindMetadataFieldDescriptors(SimplTypesScope metadataTScope,
                                                    MetadataClassDescriptor metadataClassDescriptorToBind)
        {
            bool needCloneKids = false;

            // check if the class's base class is genereic typed, and make sure itself is not generic.
            MetadataClassDescriptor metadataCd = MetadataClassDescriptor;
            MetaMetadata            baseMmd    = TypeMmd;

            while (baseMmd != null && metadataCd != null)
            {
                if (metadataCd.GetGenericTypeVars().Count == 0 && baseMmd.GenericTypeVars != null)
                {
                    needCloneKids = true;
                    break;
                }
                metadataCd = baseMmd.MetadataClassDescriptor;
                baseMmd    = baseMmd.TypeMmd;
            }

            if (needCloneKids)
            {
                DictionaryList <string, MetaMetadataField> clonedKids = new DictionaryList <string, MetaMetadataField>();
                foreach (KeyValuePair <string, MetaMetadataField> entry in Kids)
                {
                    string            key   = entry.Key;
                    MetaMetadataField field = entry.Value;

                    // look up to see if the field is declared in a generic typed class. If not, it does not need to clone it.
                    MetaMetadata declaringMmd = field.DeclaringMmd;
                    if (declaringMmd != null && declaringMmd.GenericTypeVars != null && declaringMmd.IsGenericMetadata)
                    {
                        // clone the field
                        field = field.Clone();
                        // remove the inherited field descriptor
                        field.MetadataFieldDescriptor = null;
                    }
                    clonedKids.Put(key, field);
                }
                Kids = clonedKids;
            }


            // copy the kids collection first to prevent modification to the collection during iteration (which may invalidate the iterator).
            List <MetaMetadataField> fields = new List <MetaMetadataField>(Kids.Values);

            foreach (MetaMetadataField thatChild in fields)
            {
                // look up by field name and bind
                MetadataFieldDescriptor metadataFd = thatChild.BindMetadataFieldDescriptor(metadataTScope, metadataClassDescriptorToBind);
                if (metadataFd == null)
                {
                    Debug.WriteLineIf(BigSemanticsSettings.DebugLevel > 5, "Cannot bind metadata field descriptor for " + thatChild);
                    Kids.Remove(thatChild.Name);
                    continue;
                }

                // set defininig mmdfield

                // process hide and shadows
                var isImage = thatChild is MetaMetadataCompositeField && "image".Equals(((MetaMetadataCompositeField)thatChild).Type);
                HashSet <String> nonDisplayedFieldNames = NonDisplayedFieldNames;
                if (thatChild.Hide && !isImage)
                {
                    nonDisplayedFieldNames.Add(thatChild.Name);
                }
                if (thatChild.Shadows != null)
                {
                    nonDisplayedFieldNames.Add(thatChild.Shadows);
                }

                // recursively process sub-fields
                Int32 fieldType = metadataFd.FdType;
                if (fieldType == FieldTypes.CompositeElement || fieldType == FieldTypes.CollectionElement)
                {
                    // bind class descriptor for nested sub-fields
                    MetaMetadataNestedField nested = (MetaMetadataNestedField)thatChild;
                    MetadataFieldDescriptor fd     = nested.MetadataFieldDescriptor;
                    if (fd.IsPolymorphic)
                    {
                        Debug.WriteLineIf(BigSemanticsSettings.DebugLevel > 5, "Polymorphic field: " + nested + ", not binding an element class descriptor.");
                    }
                    else
                    {
                        MetadataClassDescriptor elementClassDescriptor =
                            ((MetaMetadataNestedField)thatChild).BindMetadataClassDescriptor(metadataTScope);
                        if (elementClassDescriptor != null)
                        {
                            MetaMetadata mmdForThatChild = nested.TypeMmd;
                            if (mmdForThatChild != null && mmdForThatChild.MetadataClassDescriptor == null)
                            {
                                //							mmdForThatChild.setMetadataClassDescriptor(elementClassDescriptor);
                                mmdForThatChild.BindMetadataClassDescriptor(metadataTScope);
                            }
                        }
                        else
                        {
                            Debug.WriteLineIf(BigSemanticsSettings.DebugLevel > 5, "Cannot determine elementClassDescriptor for " + thatChild);
                            Kids.Remove(thatChild.Name);
                        }
                    }
                }

                if (this is MetaMetadata)
                {
                    MetaMetadata mmd       = (MetaMetadata)this;
                    String       naturalId = thatChild.AsNaturalId;
                    if (naturalId != null)
                    {
                        mmd.NaturalIds.Put(naturalId, thatChild);
                    }
                }
            }
        }