Package org.intermine.modelproduction
Class ModelMerger
- java.lang.Object
-
- org.intermine.modelproduction.ModelMerger
-
public final class ModelMerger extends java.lang.Object
Merge model additions into a source model to produce a new larger model.- Author:
- Thomas Riley
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static java.util.Set<AttributeDescriptor>
cloneAttributeDescriptors(java.util.Set<AttributeDescriptor> refs)
Clone a set of AttributeDescriptors.protected static ClassDescriptor
cloneClassDescriptor(ClassDescriptor cld)
Construct a ClassDescriptor that takes on all the properties ofcld
without attaching to a particular Model.protected static java.util.Set<CollectionDescriptor>
cloneCollectionDescriptors(java.util.Set<CollectionDescriptor> refs)
Clone a set of CollectionDescriptors.protected static java.util.Set<ReferenceDescriptor>
cloneReferenceDescriptors(java.util.Set<ReferenceDescriptor> refs)
Clone a set of ReferenceDescriptors.static java.util.Set<AttributeDescriptor>
mergeAttributes(ClassDescriptor original, ClassDescriptor merge)
Merge the attributes of a target model class descriptororiginal
with the attributes present in class descriptormerge
.static ClassDescriptor
mergeClass(ClassDescriptor original, ClassDescriptor merge, Model originalModel, java.util.Set<ClassDescriptor> mergeClasses)
Merge the attributes, collections and references from ClassDescriptormerge
into the ClassDescriptororiginal
.static java.util.Set<CollectionDescriptor>
mergeCollections(ClassDescriptor original, ClassDescriptor merge)
Merge the collections of a target model class descriptororiginal
with the collections present in class descriptormerge
.static Model
mergeModel(Model original, java.util.Set<ClassDescriptor> classes)
'Merges' the information from the set of ClassDescriptorsclasses
into the modeltarget
.static java.util.Set<ReferenceDescriptor>
mergeReferences(ClassDescriptor original, ClassDescriptor merge)
Merge the references of a target model class descriptororiginal
with the references present in class descriptormerge
.protected static void
removeFieldDescriptor(java.util.Set<? extends FieldDescriptor> fields, java.lang.String name)
Remove a FieldDescriptor from a Set of FieldDescriptors by name.protected static java.util.Map<java.lang.String,ClassDescriptor>
removeRedundancy(java.util.Map<java.lang.String,ClassDescriptor> classes)
When changes are made to the inheritance hierarchy (especially the addition of superinterfaces), fields may be defined on superinterfaces making previous definitions further down the inheritance hierarchy redundant.
-
-
-
Method Detail
-
mergeModel
public static Model mergeModel(Model original, java.util.Set<ClassDescriptor> classes) throws ModelMergerException
'Merges' the information from the set of ClassDescriptorsclasses
into the modeltarget
. This method does not actually modifytarget
but creates and returns a new model containing updated class descriptors. Merging may involve the following actions:- Adding fields.
- Adding references.
- Adding collections.
- Adding a new class.
- Modifying inheritance hierarchy.
- Parameters:
original
- the existing model (not modified)classes
- set of ClassDescriptors containing new information to add to the model- Returns:
- the resulting merged model
- Throws:
ModelMergerException
- if an error occurs during model mergining
-
removeRedundancy
protected static java.util.Map<java.lang.String,ClassDescriptor> removeRedundancy(java.util.Map<java.lang.String,ClassDescriptor> classes) throws ModelMergerException
When changes are made to the inheritance hierarchy (especially the addition of superinterfaces), fields may be defined on superinterfaces making previous definitions further down the inheritance hierarchy redundant. This method removes those redundant fields.- Parameters:
classes
- starting collection of ClassDescriptors- Returns:
- a new mapping from class name to ClassDescriptors
- Throws:
ModelMergerException
- if an error occurs during model merging
-
mergeClass
public static ClassDescriptor mergeClass(ClassDescriptor original, ClassDescriptor merge, Model originalModel, java.util.Set<ClassDescriptor> mergeClasses) throws ModelMergerException
Merge the attributes, collections and references from ClassDescriptormerge
into the ClassDescriptororiginal
. The two are different in that inheritance settings on the merge class can override the inheritance present in the original class. This method will throw a ModelMergerException if the two class descriptors return different values fromisInterface
.If the original class extends a superclass, and the
merge
also specifies a superclass then the merge superclass will override the old superclass.This method requires
originalModel
andmergeClasses
so it can determine whether the superclass names inmerge
represente classes or interfaces.- Parameters:
original
- the original ClassDescriptormerge
- the ClassDescriptor to merge into the originaloriginalModel
- the original Model we're merging intomergeClasses
- the set of ClassDescriptors being merged- Returns:
- ClassDescriptor merge "merged" into ClassDescriptor original
- Throws:
ModelMergerException
- if an error occurs during model merging
-
mergeAttributes
public static java.util.Set<AttributeDescriptor> mergeAttributes(ClassDescriptor original, ClassDescriptor merge) throws ModelMergerException
Merge the attributes of a target model class descriptororiginal
with the attributes present in class descriptormerge
. Returns a new set of AttributeDescriptors.- Parameters:
original
- the target model class descriptormerge
- the additions- Returns:
- new set of AttributeDescriptors
- Throws:
ModelMergerException
- if an error occurs during model mergining
-
mergeCollections
public static java.util.Set<CollectionDescriptor> mergeCollections(ClassDescriptor original, ClassDescriptor merge) throws ModelMergerException
Merge the collections of a target model class descriptororiginal
with the collections present in class descriptormerge
. Returns a new set of CollectionDescriptors.- Parameters:
original
- the target model class descriptormerge
- the additions- Returns:
- new set of CollectionDescriptors
- Throws:
ModelMergerException
- if an error occurs during model mergining
-
mergeReferences
public static java.util.Set<ReferenceDescriptor> mergeReferences(ClassDescriptor original, ClassDescriptor merge) throws ModelMergerException
Merge the references of a target model class descriptororiginal
with the references present in class descriptormerge
. Returns a new set of ReferenceDescriptors.- Parameters:
original
- the target model class descriptormerge
- the additions- Returns:
- new set of CollectionDescriptors
- Throws:
ModelMergerException
- if an error occurs during model mergining
-
cloneReferenceDescriptors
protected static java.util.Set<ReferenceDescriptor> cloneReferenceDescriptors(java.util.Set<ReferenceDescriptor> refs)
Clone a set of ReferenceDescriptors.- Parameters:
refs
- a set of ReferenceDescriptors- Returns:
- cloned set of ReferenceDescriptors
-
cloneCollectionDescriptors
protected static java.util.Set<CollectionDescriptor> cloneCollectionDescriptors(java.util.Set<CollectionDescriptor> refs)
Clone a set of CollectionDescriptors.- Parameters:
refs
- a set of CollectionDescriptors- Returns:
- cloned set of CollectionDescriptors
-
removeFieldDescriptor
protected static void removeFieldDescriptor(java.util.Set<? extends FieldDescriptor> fields, java.lang.String name)
Remove a FieldDescriptor from a Set of FieldDescriptors by name.- Parameters:
fields
- set of FieldDescriptorsname
- the field name
-
cloneAttributeDescriptors
protected static java.util.Set<AttributeDescriptor> cloneAttributeDescriptors(java.util.Set<AttributeDescriptor> refs)
Clone a set of AttributeDescriptors.- Parameters:
refs
- a set of AttributeDescriptors- Returns:
- cloned set of AttributeDescriptors
-
cloneClassDescriptor
protected static ClassDescriptor cloneClassDescriptor(ClassDescriptor cld)
Construct a ClassDescriptor that takes on all the properties ofcld
without attaching to a particular Model.- Parameters:
cld
- the ClassDescriptor to clone- Returns:
- cloned ClassDescriptor
-
-