public void removeImmediateAncestor(MmdScope ancestor) { if (ancestors != null) { ancestors.Remove(ancestor); } }
public void addAncestor(MmdScope ancestor) { if (ancestor != null && ancestor != this && !isAncestor(ancestor)) { this.Ancestors().Add(ancestor); } }
private void allAncestorsHelper(List <MmdScope> result, MmdScope scope) { if (scope.ancestors != null) { foreach (MmdScope ancestor in scope.ancestors) { if (!result.Contains(ancestor)) { result.Add(ancestor); allAncestorsHelper(result, ancestor); } } } }
public bool isAncestor(MmdScope scope) { return(ancestors == null ? false : allAncestors().Contains(scope)); }
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); }
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); }