| /** |
| * Copyright (c) 2007, 2008 INRIA. |
| * 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: |
| * INRIA - initial API and implementation |
| * |
| * $Id: Metamodel.java,v 1.5 2008/06/25 13:01:57 fjouault Exp $ |
| */ |
| package org.eclipse.gmt.tcs.builder.ct; |
| |
| import java.io.IOException; |
| import java.util.Collections; |
| |
| import org.eclipse.gmt.tcs.builder.ct.definition.ATLTransformation; |
| import org.eclipse.m2m.atl.core.ATLCoreException; |
| import org.eclipse.m2m.atl.core.IInjector; |
| import org.eclipse.m2m.atl.core.IReferenceModel; |
| import org.eclipse.m2m.atl.core.ModelFactory; |
| import org.eclipse.m2m.atl.core.emf.EMFModelFactory; |
| import org.eclipse.m2m.atl.core.service.CoreService; |
| import org.eclipse.m2m.atl.dsls.Resource; |
| import org.eclipse.m2m.atl.dsls.textsource.TextSource; |
| |
| /** |
| * |
| * @author Fr�d�ric Jouault |
| * |
| */ |
| public class Metamodel { |
| |
| public String name; |
| public IReferenceModel metamodel; |
| public ATLTransformation checker = null; |
| public TextSource source = null; |
| |
| public Metamodel(String name, String nsURI) throws IOException, ATLCoreException { |
| this.name = name; |
| |
| ModelFactory mf = CoreService.getModelFactory(EMFModelFactory.MODEL_FACTORY_NAME); |
| IInjector injector = CoreService.getInjector(mf.getDefaultInjectorName()); |
| |
| metamodel = mf.newReferenceModel(); |
| injector.inject(metamodel, "uri:" + nsURI); |
| } |
| |
| public Metamodel(String name, IReferenceModel metamodel) throws IOException { |
| this.name = name; |
| this.metamodel = metamodel; |
| } |
| |
| public Metamodel(String name, TextSource metamodelTS) throws IOException, ATLCoreException { |
| this.name = name; |
| |
| ModelFactory mf = CoreService.getModelFactory(EMFModelFactory.MODEL_FACTORY_NAME); |
| IInjector injector = CoreService.getInjector(mf.getDefaultInjectorName()); |
| |
| metamodel = mf.newReferenceModel(); |
| injector.inject(metamodel, metamodelTS.openStream(), Collections.emptyMap()); |
| source = metamodelTS; |
| } |
| |
| public Metamodel(String name, Resource metamodelResource) throws IOException, ATLCoreException { |
| this.name = name; |
| |
| ModelFactory mf = CoreService.getModelFactory(EMFModelFactory.MODEL_FACTORY_NAME); |
| IInjector injector = CoreService.getInjector(mf.getDefaultInjectorName()); |
| |
| metamodel = mf.newReferenceModel(); |
| injector.inject(metamodel, "uri:" + metamodelResource.asEMFURI().toString()); |
| source = metamodelResource.asTextSource(); |
| } |
| |
| public String getName() { |
| return name; |
| } |
| |
| public IReferenceModel getMetamodel() { |
| return metamodel; |
| } |
| } |