Class AttachingModelObjectCopier


  • public class AttachingModelObjectCopier
    extends ModelObjectCopier
    Model object copier that also attaches copied objects to the provided BM session. All created copy objects will be attached to that session. External properties will be copied as file system resources. Copier allows to copy metadata objects to different target classes, e.g. clients may copy Document to Catalog, or even to CatalogAttribute and only matching attributes will be copied.

    AttachingModelObjectCopier instances are stateful, they hold information about BM session to attach objects to. AttachingModelObjectCopier may be used multiple times to copy and attach multiple objects to the same BM session.

    Clients may extend copier and customize copy and attach process.

    See Also:
    ModelObjectCopier
    • Constructor Detail

      • AttachingModelObjectCopier

        public AttachingModelObjectCopier​(IV8ProjectManager v8projectManager,
                                          IModelObjectFactory modelFactory,
                                          IRuntimeVersionSupport runtimeVersionSupport,
                                          IEditingLanguageManager editingLanguageManager,
                                          ITopObjectFqnGenerator topObjectFqnGenerator,
                                          org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider,
                                          IResourceLookup resourceLookup,
                                          IProjectFileSystemSupportProvider projectFileSystemSupportProvider,
                                          IBmModelManager bmModelManager,
                                          IBmEmfIndexManager bmEmfIndexManager,
                                          ISymbolicNameService symbolicNameService,
                                          IBmTransaction transaction,
                                          IBmModel bmModel)
        Parameters:
        v8projectManager - the V8 project manager, cannot be null
        modelFactory - the model object factory, cannot be null
        runtimeVersionSupport - the 1C:Enterprise runtime version support, cannot be null
        editingLanguageManager - the editing language manager, cannot be null
        topObjectFqnGenerator - the top object FQN generator, cannot be null
        qualifiedNameProvider - the qualified name provider, cannot be null
        resourceLookup - the resource lookup, cannot be null
        projectFileSystemSupportProvider - the project filesystem support provider, cannot be null
        bmModelManager - the BM model manager, cannot be null
        bmEmfIndexManager - the BM model EMF index manager, cannot be null
        transaction - the transaction to perform copying within, cannot be null
        bmModel - the target BM model, cannot be null
        symbolicNameService - symbolic name service for getting URI, can't be null
    • Method Detail

      • attach

        protected org.eclipse.emf.ecore.EObject attach​(org.eclipse.emf.ecore.EObject copy,
                                                       org.eclipse.emf.ecore.EObject parent,
                                                       org.eclipse.emf.ecore.EReference reference)
        Attach the result model object copy using the provided parent object reference. Returns attached object. Method is called after source object copy and before its references copy.

        Attaching copier implementation also attaches result object copy to the BM session.

        Overrides:
        attach in class ModelObjectCopier
        Parameters:
        copy - the model object copy to attach, cannot be null
        parent - the target parent, cannot be null
        reference - the parent reference, cannot be null
        Returns:
        the attached object, never null
      • copyReferences

        protected void copyReferences​(ModelObjectCopier.CopyContext context,
                                      org.eclipse.emf.ecore.EObject parent,
                                      boolean resolveProxies,
                                      boolean useOriginalReferences)
        Copy all references in the provided CopyContext copies.

        Attaching copier implementation copies references as superclass implementation and also copies referenced external property filesystem resources.

        Overrides:
        copyReferences in class ModelObjectCopier
        Parameters:
        context - the copy context, cannot be null
        parent - the parent, can be null
        resolveProxies - whether proxies should be resolved while copying
        useOriginalReferences - whether non-copied references should be used while copying
      • copyReference

        protected void copyReference​(org.eclipse.emf.ecore.EObject fromObject,
                                     org.eclipse.emf.ecore.EReference fromReference,
                                     org.eclipse.emf.ecore.EObject toObject,
                                     org.eclipse.emf.ecore.EReference toReference,
                                     ModelObjectCopier.CopyContext context,
                                     boolean resolveProxies,
                                     boolean useOriginalReferences)
        Description copied from class: ModelObjectCopier
        Copy the model object non-containment reference feature.
        Overrides:
        copyReference in class ModelObjectCopier
        Parameters:
        fromObject - the object to copy reference feature from, cannot be null
        fromReference - the reference feature to copy, cannot be null
        toObject - the object to copy reference feature to, cannot be null
        toReference - the reference feature to copy, cannot be null
        context - the copy context, cannot be null
        resolveProxies - whether proxies should be resolved while copying
        useOriginalReferences - whether non-copied references should be used while copying
      • copyExternalPropertyReference

        protected void copyExternalPropertyReference​(org.eclipse.emf.ecore.EObject fromObject,
                                                     org.eclipse.emf.ecore.EReference fromReference,
                                                     org.eclipse.emf.ecore.EObject toObject,
                                                     org.eclipse.emf.ecore.EReference toReference,
                                                     ModelObjectCopier.CopyContext context,
                                                     boolean resolveProxies,
                                                     boolean useOriginalReferences)
        Description copied from class: ModelObjectCopier
        Copy the model object external property reference feature.
        Overrides:
        copyExternalPropertyReference in class ModelObjectCopier
        Parameters:
        fromObject - the object to copy external property from, cannot be null
        fromReference - the external property to copy, cannot be null
        toObject - the object to copy external property to, cannot be null
        toReference - the external property to copy to, cannot be null
        context - the copy context, cannot be null
        resolveProxies - whether proxies should be resolved while copying
        useOriginalReferences - whether non-copied references should be used while copying
      • generateMdCopyName

        protected String generateMdCopyName​(MdObject sourceObject,
                                            MdObject targetObject,
                                            org.eclipse.emf.ecore.EObject targetParent,
                                            org.eclipse.emf.ecore.EReference reference,
                                            ModelObjectCopier.CopyContext copyContext)
        Description copied from class: ModelObjectCopier
        Generate copied model metadata object name.
        Overrides:
        generateMdCopyName in class ModelObjectCopier
        Parameters:
        sourceObject - the source object to copy, cannot be null
        targetObject - the target object to copy, cannot be null
        targetParent - the target parent to copy to or null if none
        reference - the parent reference to copy to or null if none
        Returns:
        the copied model metadata object name, never null
      • copyReferenceTypeDescription

        protected void copyReferenceTypeDescription​(TypeDescription typeDescription,
                                                    org.eclipse.emf.ecore.EReference fromReference,
                                                    org.eclipse.emf.ecore.EObject copyEObject,
                                                    org.eclipse.emf.ecore.EReference toReference,
                                                    ModelObjectCopier.CopyContext context,
                                                    boolean resolveProxies,
                                                    boolean useOriginalReferences)
        Description copied from class: ModelObjectCopier
        Copy the model object non-containment reference feature from the type description object.
        Overrides:
        copyReferenceTypeDescription in class ModelObjectCopier
        Parameters:
        typeDescription - the object to copy reference feature from, cannot be null
        fromReference - the reference feature to copy, cannot be null
        toReference - the reference feature to copy, cannot be null
        context - the copy context, cannot be null
        resolveProxies - whether proxies should be resolved while copying
        useOriginalReferences - whether non-copied references should be used while copying
      • copyReferenceFields

        protected void copyReferenceFields​(org.eclipse.emf.ecore.EObject fromObject,
                                           org.eclipse.emf.ecore.EReference fromReference,
                                           org.eclipse.emf.ecore.EObject toObject,
                                           org.eclipse.emf.ecore.EReference toReference,
                                           ModelObjectCopier.CopyContext context,
                                           boolean resolveProxies,
                                           boolean useOriginalReferences)
        Description copied from class: ModelObjectCopier
        Copy the model object non-containment reference feature of the Field type.
        Overrides:
        copyReferenceFields in class ModelObjectCopier
        Parameters:
        fromObject - the object to copy reference feature from, cannot be null
        fromReference - the reference feature to copy, cannot be null
        toObject - the object to copy reference feature to, cannot be null
        toReference - the reference feature to copy, cannot be null
        context - the copy context, cannot be null
        resolveProxies - whether proxies should be resolved while copying
        useOriginalReferences - whether non-copied references should be used while copying
      • copyReferenceField

        protected void copyReferenceField​(org.eclipse.emf.ecore.EObject fromObject,
                                          org.eclipse.emf.ecore.EReference fromReference,
                                          org.eclipse.emf.ecore.EObject toObject,
                                          org.eclipse.emf.ecore.EReference toReference,
                                          ModelObjectCopier.CopyContext context,
                                          boolean resolveProxies,
                                          boolean useOriginalReferences)
        Description copied from class: ModelObjectCopier
        Copy the model object non-containment reference feature of the Field type.
        Overrides:
        copyReferenceField in class ModelObjectCopier
        Parameters:
        fromObject - the object to copy reference feature from, cannot be null
        fromReference - the reference feature to copy, cannot be null
        toObject - the object to copy reference feature to, cannot be null
        toReference - the reference feature to copy, cannot be null
        context - the copy context, cannot be null
        resolveProxies - whether proxies should be resolved while copying
        useOriginalReferences - whether non-copied references should be used while copying
      • copySourceAsReferenceType

        protected void copySourceAsReferenceType​(org.eclipse.emf.ecore.EObject eObject,
                                                 org.eclipse.emf.ecore.EObject copyObject,
                                                 org.eclipse.emf.ecore.EReference toReference,
                                                 ModelObjectCopier.CopyContext context)
        Description copied from class: ModelObjectCopier
        Copy the source object as reference to source type in the terms of V8 metadata model. If cannot copy then do nothing.
        Overrides:
        copySourceAsReferenceType in class ModelObjectCopier
        Parameters:
        eObject - the original object, cannot be null
        copyObject - the copied object, cannot be null
        toReference - the type description reference to copy source as type to, cannot be null
        context - the copy context, cannot be null
      • createContext

        protected ModelObjectCopier.CopyContext createContext​(org.eclipse.emf.ecore.EClass toClass)
        Description copied from class: ModelObjectCopier
        Creates copy context. Subclasses may override and provide more specific copy context.
        Overrides:
        createContext in class ModelObjectCopier
        Parameters:
        toClass - the result model class, cannot be null
        Returns:
        the created copy context, never null
      • createContext

        protected ModelObjectCopier.CopyContext createContext​(org.eclipse.emf.ecore.EObject parent,
                                                              org.eclipse.emf.ecore.EReference reference)
        Description copied from class: ModelObjectCopier
        Creates copy context. Subclasses may override and provide more specific copy context.
        Overrides:
        createContext in class ModelObjectCopier
        Parameters:
        parent - the target parent, cannot be null
        reference - the reference parent, cannot be null
        Returns:
        the created copy context, never null
      • attachExternalProperty

        protected <T extends IBmObject> T attachExternalProperty​(T externalProperty,
                                                                 org.eclipse.emf.ecore.EObject owner,
                                                                 org.eclipse.emf.ecore.EReference reference)
        Attach the given external property to the associated BM session.
        Parameters:
        externalProperty - the external property value, cannot be null
        owner - the external property owner, cannot be null
        reference - the external property reference, cannot be null
        Returns:
        the attached external property, never null
      • attachModelObject

        protected <T extends IBmObject> T attachModelObject​(T original)
        Attach the given model object to the associated BM session.
        Parameters:
        original - the original model object, cannot be null
        Returns:
        the attached model object, never null
      • attachModelObject

        protected <T extends IBmObject> T attachModelObject​(T original,
                                                            boolean isTop)
        Attach the given model object to the associated BM session.
        Parameters:
        original - the original model object, cannot be null
        isTop - whether the object is top object
        Returns:
        the attached model object, never null
      • createProxy

        protected org.eclipse.emf.ecore.EObject createProxy​(org.eclipse.core.resources.IProject sourceProject,
                                                            org.eclipse.emf.ecore.EObject sourceParent,
                                                            org.eclipse.emf.ecore.EObject source,
                                                            org.eclipse.core.resources.IProject targetProject,
                                                            org.eclipse.emf.ecore.EObject targetParent,
                                                            org.eclipse.emf.ecore.EReference targetReference,
                                                            ModelObjectCopier.CopyContext context)
        Create proxy of the source object in the target project. The proxy will have the same URI but with the provided project instead of original and the provided targetParent URI part instead of sourceParent part.
        Parameters:
        sourceProject - the source object project, cannot be null
        sourceParent - the source object parent, cannot be null
        source - the source object, cannot be null
        targetProject - the target project to create proxy in, cannot be null
        targetParent - the target proxy object parent, cannot be null
        targetReference - the target proxy reference, cannot be null
        context - the copy context, cannot be null
        Returns:
        the created proxy, never null
      • copyExternalPropertyResource

        protected void copyExternalPropertyResource​(ModelObjectCopier.CopyContext context,
                                                    org.eclipse.core.resources.IProject projectFrom,
                                                    org.eclipse.core.resources.IProject projectTo,
                                                    IProjectFileSystemSupport projectFileSystemSupportTo,
                                                    IProjectFileSystemSupport projectFileSystemSupportFrom,
                                                    org.eclipse.emf.ecore.EObject owner,
                                                    org.eclipse.emf.ecore.EReference reference,
                                                    org.eclipse.emf.ecore.EObject externalProperty)
        Copies the provided external property resource file to the target file location and attaches it to the associated BM session.
        Parameters:
        context - the copy context, cannot be null
        projectFrom - the project to copy resource from, cannot be null
        projectTo - the project to copy resource to, cannot be null
        projectFileSystemSupportTo - the project filesystem support to copy resource from, cannot be null
        projectFileSystemSupportFrom - the project filesystem support to copy resource to, cannot be null
        owner - the external property owner, cannot be null
        reference - the external property reference feature, cannot be null
        externalProperty - the external property, cannot be null
      • copyReferenceAsProxy

        protected Object copyReferenceAsProxy​(org.eclipse.core.resources.IProject fromProject,
                                              org.eclipse.emf.ecore.EObject fromObject,
                                              org.eclipse.emf.ecore.EReference fromReference,
                                              org.eclipse.core.resources.IProject toProject,
                                              org.eclipse.emf.ecore.EObject toObject,
                                              org.eclipse.emf.ecore.EReference toReference,
                                              ModelObjectCopier.CopyContext context)
        Copy the model object non-containment reference feature as proxy in the associated BM session project.
        Parameters:
        fromProject - the original object project, cannot be null
        fromObject - the object to copy reference feature from, cannot be null
        fromReference - the reference feature to copy, cannot be null
        toProject - the project to create proxy in, cannot be null
        toObject - the object to copy reference feature to, cannot be null
        toReference - the reference feature to copy, cannot be null
        context - the copy context, cannot be null
        resolveProxies - whether proxies should be resolved while copying
        useOriginalReferences - whether non-copied references should be used while copying
        Returns:
        the result of the copied reference: EObject element or a collection of EObject elements, never null
      • copyResource

        protected void copyResource​(org.eclipse.core.resources.IFile fromFile,
                                    org.eclipse.core.resources.IFile toFile)
        Copies the provided resource file to the target file location. If target file is already exist it will be replaced with the provided file copy.
        Parameters:
        fromFile - the source file to copy, cannot be null
        toFile - the target file location, cannot be null
      • generateExternalPropertyFqn

        protected String generateExternalPropertyFqn​(IBmObject externalProperty,
                                                     org.eclipse.emf.ecore.EObject owner,
                                                     org.eclipse.emf.ecore.EReference reference)
        Generate and external property FQN.
        Parameters:
        externalProperty - the external property object, cannot be null
        owner - the external property owner, cannot be null
        reference - the reference to external property, cannot be null
        Returns:
        the generated external property FQN, never null