Exemple #1
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);
                }
            }
        }
Exemple #2
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);
            }
        }
Exemple #3
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);
        }
Exemple #4
0
 public void deserializationPostHook(MetadataNS.Metadata deserializedMetadata, MetadataFieldDescriptor mfd)
 {
     currentMMstack.Pop();
 }
        /**
         * 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);
                    }
                }
            }
        }