示例#1
0
        public MetaMetadata GetMMByMime(string mimeType)
        {
            MetaMetadata result = null;

            _repositoryByMime.TryGetValue(mimeType, out result);
            return(result);
        }
        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);
        }
示例#3
0
        public MetaMetadata GetMMBySuffix(string suffix)
        {
            MetaMetadata result = null;

            _repositoryBySuffix.TryGetValue(suffix, out result);
            return(result);
        }
        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);
                }
            }
        }
示例#5
0
        public MetaMetadata GetMMByName(String tagName)
        {
            if (tagName == null)
            {
                return(null);
            }
            MetaMetadata result = null;

            _repositoryByName.TryGetValue(tagName, out result);
            return(result);
        }
        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);
        }
示例#7
0
 private void SetDefaultMetaMetadatas()
 {
     if (META_METADATA_REPOSITORY != null)
     {
         DocumentMetaMetadata      = META_METADATA_REPOSITORY.GetMMByName(DocumentParserTagNames.DocumentTag);
         PdfMetaMetadata           = META_METADATA_REPOSITORY.GetMMByName(DocumentParserTagNames.PdfTag);
         SearchMetaMetadata        = META_METADATA_REPOSITORY.GetMMByName(DocumentParserTagNames.SearchTag);
         ImageMetaMetadata         = META_METADATA_REPOSITORY.GetMMByName(DocumentParserTagNames.ImageTag);
         DebugMetaMetadata         = META_METADATA_REPOSITORY.GetMMByName(DocumentParserTagNames.DebugTag);
         ImageClippingMetaMetadata = META_METADATA_REPOSITORY.GetMMByName(DocumentParserTagNames.ImageClippingTag);
     }
 }
 protected void MakeThisFieldUseMmd(String previousName, MetaMetadata mmd)
 {
     // must set this before generatedMmd.inheritMetaMetadata() to meet inheritMetaMetadata() prerequisites
     TypeMmd = mmd;
     // make this field as if is using generatedMmd as type
     Type             = mmd.Name;
     ExtendsAttribute = null;
     if (Tag == null)
     {
         Tag = previousName; // but keep the tag name
     }
 }
示例#9
0
        public Image ConstructImage(ParsedUri location)
        {
            MetaMetadata metaMetadata = GetImageMM(location);
            Image        result       = null;

            if (metaMetadata != null)
            {
                result          = (Image)metaMetadata.ConstructMetadata(this.MetadataTScope);
                result.Location = new MetadataParsedURL(location);
            }
            return(result);
        }
示例#10
0
        public MetaMetadata GetByClass(Type metadataClass)
        {
            if (metadataClass == null)
            {
                return(null);
            }

            MetaMetadata result = null;

            // String tag = metadataTScope.getTag(metadataClass);
            RepositoryByClassName.TryGetValue(metadataClass.Name, out result);
            return(result);
        }
        public bool IsDerivedFrom(MetaMetadata baseMmd)
        {
            MetaMetadata mmd = this;

            while (mmd != null)
            {
                if (mmd == baseMmd)
                {
                    return(true);
                }
                mmd = mmd.SuperMmd;
            }
            return(false);
        }
        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();
            }
        }
示例#13
0
        public Document ConstructDocument(ParsedUri location, bool isImage)
        {
            // if (location.IsImage) return constructImage(location);
            if (isImage)
            {
                return(ConstructImage(location));
            }
            MetaMetadata mmd    = GetDocumentMM(location);
            Document     result = mmd.ConstructMetadata(MetadataTScope) as Document;

            if (result != null)
            {
                result.Location = new MetadataParsedURL(location);
            }
            return(result);
        }
示例#14
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);
                }
            }
        }
        protected override string GetMetadataClassSimpleName()
        {
            if (IsBuiltIn || IsNewMetadataClass())
            {
                // new definition
                return(XmlTools.CamelCaseFromXMLElementName(Name, true));// ClassNameFromElementName(Name);
            }
            else
            {
                // re-using existing type
                // do not use this.type directly because we don't know if that is a definition or just re-using exsiting type
                MetaMetadata inheritedMmd = SuperMmd;
//                if (inheritedMmd == null)
//                    InheritMetaMetadata(null);//edit // currently, this should never happend because we call this method after inheritance process.
                return(inheritedMmd == null ? null : inheritedMmd.GetMetadataClassSimpleName());
            }
        }
        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 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);
            }
        }
示例#18
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);
            }
        }
示例#19
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 MetaMetadata GenerateMetaMetadata(String previousName, MetaMetadata inheritedMmd)
        {
            String generatedName = getGeneratedMmdName2(previousName);

            // generate the mmd and set attributes
            MetaMetadata generatedMmd = new MetaMetadata
            {
                Name             = generatedName,
                PackageName      = PackageName,
                Type             = null,
                TypeMmd          = inheritedMmd,
                ExtendsAttribute = inheritedMmd.Name,
                Repository       = Repository,
                Visibility       = Visibility.PACKAGE,
                Scope            =
                    new MmdScope(this.Scope,
                                 inheritedMmd.Scope)
            };

            if (SchemaOrgItemtype != null)
            {
                generatedMmd.SchemaOrgItemtype = SchemaOrgItemtype;
            }
            generatedMmd.SetNewMetadataClass(true);

            // move nested fields (they will be cloned later)
            if (kids != null && kids.Count > 0)
            {
                foreach (String kidKey in this.kids.Keys)
                {
                    MetaMetadataField kid;
                    kids.TryGetValue(kidKey, out kid);
                    generatedMmd.Kids.Put(kidKey, kid);
                    kid.Parent = generatedMmd;
                }
                kids.Clear();
            }
            MakeThisFieldUseMmd(previousName, generatedMmd);
            return(generatedMmd);
        }
示例#21
0
        /**
         * Initializes HashMaps for MetaMetadata selectors by URL or pattern. Uses the ClippableDocument and Document
         * base classes to ensure that maps are only filled with appropriate matching MetaMetadata.
         */

        public void InitializeLocationBasedMaps()
        {
            foreach (MetaMetadata metaMetadata in _repositoryByName.Values)
            {
                // metaMetadata.inheritMetaMetadata(this);

                Type metadataClass = metaMetadata.GetMetadataClass(MetadataTScope);
                if (metadataClass == null)
                {
                    Debug.WriteLine("No metadata class found for metaMetadata: " + metaMetadata.Name);
                    continue;
                }

                Dictionary <String, MetaMetadata> repositoryByUrlStripped;
                Dictionary <String, List <RepositoryPatternEntry> > repositoryByPattern;

                if (typeof(ClippableDocument).GetTypeInfo().IsAssignableFrom(metadataClass.GetTypeInfo()))
                {
                    repositoryByUrlStripped = _clippableDocumentRepositoryByUrlStripped;
                    repositoryByPattern     = _clippableDocumentRepositoryByPattern;
                }
                else if (typeof(Document).GetTypeInfo().IsAssignableFrom(metadataClass.GetTypeInfo()))
                {
                    repositoryByUrlStripped = _documentRepositoryByUrlStripped;
                    repositoryByPattern     = _documentRepositoryByPattern;
                }
                else
                {
                    continue;
                }

                // We need to check if something is there already
                // if something is there, then we need to check to see if it has its cf pref set
                // if not, then if I am null then I win

                //MetaMetadataSelector selector = metaMetadata.Selectors[0];//Note: Needs to consider all selectors.

                if (metaMetadata.Selectors == null || metaMetadata.Selectors.Count == 0)
                {
                    continue;
                }
                foreach (MetaMetadataSelector selector in metaMetadata.Selectors)
                {
                    ParsedUri strippedPURL = selector.UrlStripped;
                    if (strippedPURL != null)
                    {
                        MetaMetadata inMap = null;
                        repositoryByUrlStripped.TryGetValue(strippedPURL.Stripped, out inMap);
                        if (inMap == null)
                        {
                            repositoryByUrlStripped.Add(strippedPURL.Stripped, metaMetadata);
                        }
                        else
                        {
                            Debug.WriteLine("MetaMetadata already exists in repositoryByUrlStripped for purl\n\t: " +
                                            strippedPURL + " :: " + inMap.Name + " Ignoring MMD: " + metaMetadata.Name);
                        }
                        metaMetadata.MMSelectorType = MMSelectorType.LOCATION;
                    }
                    else
                    {
                        ParsedUri urlPathTree = selector.UrlPathTree;
                        if (urlPathTree != null)
                        {
                            PrefixPhrase <MetaMetadata> pp = urlPrefixCollection.Add(urlPathTree);
                            pp.MappedObject             = metaMetadata;
                            metaMetadata.MMSelectorType = MMSelectorType.LOCATION;
                        }
                        else
                        {
                            // here, url_path_tree is handled through regex.
                            // use .pattern() for comparison
                            String domain = selector.Domain; //??
//                                            (selector.UrlPathTree != null ? selector.UrlPathTree.Domain : null);
                            if (domain != null)
                            {
                                Regex urlPattern = selector.UrlRegex; //??
//                                                   (selector.UrlPathTree == null
//                                                       ? null
//                                                        : new Regex(selector.UrlPathTree.ToString().Replace("*", "[^/]+")));
                                if (urlPattern != null)
                                {
                                    List <RepositoryPatternEntry> bucket;
                                    repositoryByPattern.TryGetValue(domain, out bucket);
                                    if (bucket == null)
                                    {
                                        bucket = new List <RepositoryPatternEntry>(2);
                                        repositoryByPattern.Add(domain, bucket);
                                    }
                                    bucket.Add(new RepositoryPatternEntry(urlPattern, metaMetadata));
                                    metaMetadata.MMSelectorType = MMSelectorType.LOCATION;
                                }
                                else
                                {
                                    // domain only -- no pattern
                                    //TODO: 'PUT' HIDES ERRORS. This is only so that we can identify them
                                    if (_documentRepositoryByDomain.ContainsKey(domain))
                                    {
                                        Debug.WriteLine(
                                            "-----\tError: Adding MMD({0}) for domain({1}), but this domain is already used for MMD({2})",
                                            metaMetadata, domain, _documentRepositoryByDomain[domain]);
                                    }
                                    else
                                    {
                                        _documentRepositoryByDomain.Add(domain, metaMetadata);
                                    }

                                    metaMetadata.MMSelectorType = MMSelectorType.DOMAIN;
                                }
                            }
                        }
                    }
                }
            }
        }
        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 virtual void InheritNonFieldElements(MetaMetadata inheritedMmd, InheritanceHandler inheritanceHandler)
 {
     Scope = new MmdScope(Scope, inheritedMmd.Scope);
 }
        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);
        }
 private static bool IsRootMetaMetadata(MetaMetadata mmd)
 {
     return(mmd.Name.Equals(ROOT_MMD_NAME));
 }
 public InheritanceHandler(MetaMetadata rootMmd)
 {
     this.rootMmd    = rootMmd;
     this.repository = rootMmd.Repository;
 }
 private void InheritFromTopLevelMetaMetadata(MetaMetadata inheritedMmd, MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
 {
     InheritNonFieldElements(inheritedMmd, inheritanceHandler);
     InheritFrom(repository, inheritedMmd, inheritanceHandler);
 }
示例#28
0
 public RepositoryPatternEntry(Regex pattern, MetaMetadata metaMetadata)
 {
     this.pattern      = pattern;
     this.metaMetadata = metaMetadata;
 }
        public static async Task <MetaMetadataRepository> ReadRepository(string filename, SimplTypesScope mmdTScope, SimplTypesScope metadataTScope, MetaMetadataRepository mainRepo)
        {
            MetaMetadataRepository repo = null;

            Debug.WriteLine("MetaMetadataRepository Reading:\t\t" + filename);

            try
            {
                repo = await mmdTScope.DeserializeFile(filename, Format.Xml) as MetaMetadataRepository;

                if (repo != null)
                {
                    repo.MetadataTScope = metadataTScope;
                    repo.File           = filename;
                    repo.InitializeSuffixAndMimeDicts();

                    if (repo.RepositoryByName == null)
                    {
                        return(repo);
                    }

                    foreach (var repoEntry in repo.RepositoryByName)
                    {
                        MetaMetadata mmd     = repoEntry.Value;
                        string       mmdName = repoEntry.Key;

                        //mmd.File = new FileInfo(filename);
                        mmd.File = await FundamentalPlatformSpecifics.Get().CreateFile(filename);

                        mmd.Parent     = mainRepo;
                        mmd.Repository = mainRepo;

                        string packageName = mmd.PackageName ?? repo.PackageName;
                        if (packageName == null)
                        {
                            throw new MetaMetadataException("No Package Name Specified For " + mmd);
                        }
                        mmd.PackageName = packageName;

                        MmdScope packageMmdScopes;
                        mainRepo.PackageMmdScopes.TryGetValue(mmd.PackageName, out packageMmdScopes);
                        if (packageMmdScopes == null)
                        {
                            packageMmdScopes = new MmdScope(repo.PackageName);
                            packageMmdScopes.PutAll(mainRepo.RepositoryByName);
                            mainRepo.PackageMmdScopes.Put(packageName, packageMmdScopes);
                        }

                        MetaMetadata existingMmd;
                        switch (mmd.Visibility)
                        {
                        case Visibility.GLOBAL:

                            mainRepo.RepositoryByName.TryGetValue(mmdName, out existingMmd);

                            if (existingMmd != null && existingMmd != mmd)
                            {
                                throw new MetaMetadataException("MMD already exists: " + mmdName + " in " + filename);
                            }

                            mainRepo.RepositoryByName.Put(mmdName, mmd);
                            break;

                        case Visibility.PACKAGE:
                            Object mmdObj = null;
                            packageMmdScopes.TryGetValue(mmdName, out mmdObj);
                            existingMmd = (MetaMetadata)mmdObj;

                            if (existingMmd != null && existingMmd != mmd)
                            {
                                throw new MetaMetadataException("MMD already exists: " + mmdName + " in " + filename);
                            }

                            packageMmdScopes.Put(mmdName, mmd);
                            break;
                        }
                    }

                    foreach (MetaMetadata metaMetadata in repo.RepositoryByName.Values)
                    {
                        if (metaMetadata.PackageName == null)
                        {
                            Debug.WriteLine("No Package name defined for: " + metaMetadata.Name);
                            continue;
                        }
                        MmdScope packageMmdScope;
                        mainRepo.PackageMmdScopes.TryGetValue(metaMetadata.PackageName, out packageMmdScope);
                        metaMetadata.Scope = packageMmdScope;
                    }

                    mainRepo.IntegrateRepository(repo);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Couldn't translate repository file: " + filename);
                Debug.WriteLine(e);
            }

            return(repo);
        }
示例#30
0
        /// <summary>
        ///  Get MetaMetadata. First, try matching by url_base. If this fails, including if the attribute is
        ///  null, then try by url_prefix. If this fails, including if the attribute is null, then try by
        ///  url_pattern (regular expression).
        ///  <p/>
        /// If that lookup fails, then lookup by tag name, to acquire the default.
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="tagName"></param>
        /// <returns></returns>
        public MetaMetadata GetDocumentMM(ParsedUri uri, String tagName = DocumentParserTagNames.DocumentTag)
        {
            MetaMetadata result = null;

            if (uri != null)
            {
                if (!uri.IsFile)
                {
                    //String noAnchorNoQueryPageString = uri.GetLeftPart(UriPartial.Path);
                    String noAnchorNoQueryPageString = FundamentalPlatformSpecifics.Get().GetUriLeftPart(uri);

                    _documentRepositoryByUrlStripped.TryGetValue(noAnchorNoQueryPageString, out result);

                    if (result == null)
                    {
                        //Check to see if the url prefix is actually a url-path tree.
                        //TODO: For url-path-tree cases, we should just generate a regex to handle those cases.
                        PrefixPhrase <MetaMetadata> matchingPrefix = urlPrefixCollection.getMatchingPrefix(uri);
                        if (matchingPrefix != null)
                        {
                            result = matchingPrefix.MappedObject;
                        }
                    }

                    if (result == null)
                    {
                        String domain = uri.Domain;
                        if (domain != null)
                        {
                            List <RepositoryPatternEntry> entries = null;
                            _documentRepositoryByPattern.TryGetValue(domain, out entries);

                            if (entries != null)
                            {
                                foreach (RepositoryPatternEntry entry in entries)
                                {
                                    Match matcher = entry.Pattern.Match(uri.ToString());
                                    if (matcher.Success)
                                    {
                                        result = entry.MetaMetadata;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                // be careful of the order! suffix before domain

                if (result == null)
                {
                    String suffix = uri.Suffix;

                    if (suffix != null)
                    {
                        result = GetMMBySuffix(suffix);
                    }
                }
                if (result == null)
                {
                    String domain = uri.Domain;
                    _documentRepositoryByDomain.TryGetValue(domain, out result);

                    if (result != null)
                    {
                        Debug.WriteLine("Matched by domain = " + domain + "\t" + result);
                    }
                }
            }
            if (result == null)
            {
                result = GetMMByName(tagName);
            }

            return(result);
        }