diff options
author | sboyko | 2014-11-26 16:08:50 +0000 |
---|---|---|
committer | sboyko | 2014-11-26 16:08:50 +0000 |
commit | 6b1a095f721a47b2cd3591058c79ec9e31ee4ba5 (patch) | |
tree | 11c452b03c88434413e9d4466c8b75385094f2ab /plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal | |
parent | 20c787c0bf30dd6f3cd1f58a443824de748a5b9e (diff) | |
download | org.eclipse.qvto-6b1a095f721a47b2cd3591058c79ec9e31ee4ba5.tar.gz org.eclipse.qvto-6b1a095f721a47b2cd3591058c79ec9e31ee4ba5.tar.xz org.eclipse.qvto-6b1a095f721a47b2cd3591058c79ec9e31ee4ba5.zip |
[449483] - Code duplication for EPackage.Registry construction from
metamodel mappings
cherry-picked from cgerking/449483:
I426d29e42a31bb2655a73aa330939568bab68411
Diffstat (limited to 'plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal')
3 files changed, 0 insertions, 189 deletions
diff --git a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/io/CResourceRepositoryContext.java b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/io/CResourceRepositoryContext.java deleted file mode 100644 index cf2bf862d..000000000 --- a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/io/CResourceRepositoryContext.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Borland Software Corporation and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Borland Software Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.m2m.internal.qvt.oml.common.io; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.m2m.internal.qvt.oml.emf.util.mmregistry.IMetamodelRegistryProvider.IRepositoryContext; - -public class CResourceRepositoryContext implements IRepositoryContext { - private URI fUri; - - public CResourceRepositoryContext(URI uri) { - if(uri == null) { - throw new IllegalArgumentException(); - } - - this.fUri = uri; - } - - public URI getURI() { - return fUri; - } -} diff --git a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/io/eclipse/MetamodelRegistryProvider.java b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/io/eclipse/MetamodelRegistryProvider.java deleted file mode 100644 index 3d05bc160..000000000 --- a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/io/eclipse/MetamodelRegistryProvider.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Borland Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Borland Software Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.m2m.internal.qvt.oml.common.io.eclipse; - -import org.eclipse.m2m.internal.qvt.oml.emf.util.mmregistry.IMetamodelRegistryProvider; -import org.eclipse.m2m.internal.qvt.oml.emf.util.mmregistry.MetamodelRegistry; - -/** - * @author aigdalov - * Created on Oct 10, 2007 - */ -public class MetamodelRegistryProvider implements IMetamodelRegistryProvider { - public MetamodelRegistry getRegistry(IRepositoryContext context) { - return MetamodelRegistry.getInstance(); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/io/eclipse/WorkspaceMetamodelRegistryProvider.java b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/io/eclipse/WorkspaceMetamodelRegistryProvider.java deleted file mode 100644 index 1d03aa6f4..000000000 --- a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/io/eclipse/WorkspaceMetamodelRegistryProvider.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2014 Borland Software Corporation and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Borland Software Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.m2m.internal.qvt.oml.common.io.eclipse; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.eclipse.m2m.internal.qvt.oml.common.CommonPlugin; -import org.eclipse.m2m.internal.qvt.oml.emf.util.mmregistry.IMetamodelProvider; -import org.eclipse.m2m.internal.qvt.oml.emf.util.mmregistry.IMetamodelRegistryProvider; -import org.eclipse.m2m.internal.qvt.oml.emf.util.mmregistry.MetamodelRegistry; -import org.eclipse.m2m.internal.qvt.oml.emf.util.mmregistry.WorkspaceMetamodelProvider; -import org.eclipse.m2m.internal.qvt.oml.emf.util.urimap.MappingContainer; -import org.eclipse.m2m.internal.qvt.oml.emf.util.urimap.MetamodelURIMappingHelper; -import org.eclipse.m2m.internal.qvt.oml.emf.util.urimap.URIMapping; -import org.eclipse.osgi.util.NLS; - -public class WorkspaceMetamodelRegistryProvider implements IMetamodelRegistryProvider { - - private ResourceSet resolutionRSet; - private Map<String, MetamodelRegistry> perProjectRegs; - - public WorkspaceMetamodelRegistryProvider() { - this(new ResourceSetImpl()); - } - - public WorkspaceMetamodelRegistryProvider(ResourceSet resourceSet) { - if(resourceSet == null) { - throw new IllegalArgumentException(); - } - - this.resolutionRSet = resourceSet; - } - - public ResourceSet getResolutionResourceSet() { - return resolutionRSet; - } - - public MetamodelRegistry getRegistry(IRepositoryContext context) { - if(context == null) { - throw new IllegalArgumentException("Null context"); //$NON-NLS-1$ - } - - URI uri = context.getURI(); - if(!uri.isPlatformResource()) { - return getDelegateRegistry(); - } - - IPath wsLocation = new Path(uri.toPlatformString(true)); - IResource wsResource = ResourcesPlugin.getWorkspace().getRoot().findMember(wsLocation); - if(wsResource == null) { - // not a file, could be a folder - wsResource = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(wsLocation); - } - - if(wsResource != null) { - IProject project = wsResource.getProject(); - if(MetamodelURIMappingHelper.hasMappingResource(project)) { - if(perProjectRegs == null) { - perProjectRegs = new HashMap<String, MetamodelRegistry>(); - } - - String projectKey = project.getFullPath().toString(); - MetamodelRegistry reg = perProjectRegs.get(projectKey); - if(reg == null) { - try { - reg = createRegistry(MetamodelURIMappingHelper.loadMappings(project)); - perProjectRegs.put(projectKey, reg); - return reg; - } catch (IOException e) { - CommonPlugin.log(e); - } - } else { - return reg; - } - } - } - - return getDelegateRegistry(); - } - - private MetamodelRegistry getDelegateRegistry() { - return new MetamodelRegistry(createDelegateMetamodelProvider()); - } - - protected IMetamodelProvider createDelegateMetamodelProvider() { - return MetamodelRegistry.getDefaultMetamodelProvider(); - } - - private MetamodelRegistry createRegistry(MappingContainer mappings) { - WorkspaceMetamodelProvider metamodelProvider = new WorkspaceMetamodelProvider(createDelegateMetamodelProvider(), resolutionRSet); - - for (URIMapping nextMapping : mappings.getMapping()) { - URI uri = null; - IllegalArgumentException error = null; - try { - uri = URI.createURI(nextMapping.getTargetURI()); - } catch (IllegalArgumentException e) { - error = e; - } - - if(uri != null && nextMapping.getSourceURI() != null) { - metamodelProvider.addMetamodel(nextMapping.getSourceURI(), uri); - } else { - String message = NLS.bind("Invalid metamodel uri mapping. nsUri:''{0}'' modelUri:''{1}''", //$NON-NLS-1$ - nextMapping.getSourceURI(), nextMapping.getTargetURI()); - - CommonPlugin.log(new Status(IStatus.ERROR, CommonPlugin.ID, message, error)); - } - } - - return new MetamodelRegistry(metamodelProvider); - } -} |