Skip to content
Snippets Groups Projects
Commit 2149abc0 authored by Nikolaus Huber's avatar Nikolaus Huber
Browse files

splitting project into several packages

git-svn-id: https://se1.informatik.uni-wuerzburg.de/usvn/svn/code/code/DMM/trunk@13065 9e42b895-fcda-4063-8a3b-11be15eb1bbd
parent fcc6abe0
No related branches found
No related tags found
No related merge requests found
Showing
with 343 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>edu.kit.ipd.descartes.adaptation.model.repository</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
eclipse.preferences.version=1
pluginProject.equinox=false
pluginProject.extensions=false
resolve.requirebundle=false
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ModelRepository
Bundle-SymbolicName: edu.kit.ipd.descartes.adaptation.model.repository
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: edu.kit.ipd.descartes.adaptation.model.repository.Activator
Bundle-Vendor: Descartes Research Group
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: edu.kit.ipd.descartes.core,
edu.kit.ipd.descartes.mm.adaptation,
edu.kit.ipd.descartes.mm.adaptationpoints,
edu.kit.ipd.descartes.mm.containerrepository,
edu.kit.ipd.descartes.mm.resourcelandscape,
org.apache.log4j;version="1.2.15",
org.eclipse.core.resources,
org.eclipse.core.runtime;version="3.4.0",
org.eclipse.emf.common.util,
org.eclipse.emf.ecore,
org.eclipse.emf.ecore.change,
org.eclipse.emf.ecore.change.util,
org.eclipse.emf.ecore.resource,
org.eclipse.emf.ecore.resource.impl,
org.eclipse.emf.ecore.util,
org.eclipse.emf.ecore.xmi,
org.eclipse.emf.ecore.xmi.impl,
org.osgi.framework;version="1.3.0"
Export-Package: edu.kit.ipd.descartes.adaptation.model.repository,
edu.kit.ipd.descartes.adaptation.model.repository.dmm
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
package edu.kit.ipd.descartes.adaptation.model.repository;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.XMIResource;
public abstract class AbstractEcoreModelLoader {
private static Logger logger = Logger.getLogger(AbstractEcoreModelLoader.class);
private ResourceSet resourceSet = null;
private URI currentUri = null;
private EObject loadedModel;
protected ResourceSet getResourceSet() {
if (resourceSet == null)
throw new NullPointerException("INTITIALIZE RESOURCE SET FIRST! ");
return resourceSet;
}
protected void setResourceSet(ResourceSet resourceSet) {
this.resourceSet = resourceSet;
}
/**Implement this method to initialize your {@link ResourceSet}, e.g.,
* if you load your models in a standalone application.
*
* @param resourceSet
*/
public abstract void initializeResourceSet(ResourceSet resourceSet);
/**
* Loads the model specified by <code>uri</code>.
*
* @param uri
* @return
* @throws IOException
*/
public EObject load(URI uri) {
if (null == uri)
throw new IllegalArgumentException("Missing file URI.");
if (uri.equals(currentUri) && loadedModel != null)
return loadedModel;
// Resource resource = resourceSet.createResource(fileURI);
Resource resource = resourceSet.getResource(uri, true);
try {
resource.load(null);
logger.info("Model from URI " + uri.toFileString() + " loaded.");
} catch (IOException e) {
logger.error("Error while loading model " + uri.toFileString(), e);
e.printStackTrace();
}
currentUri = uri;
EcoreUtil.resolveAll(resourceSet);
loadedModel = resource.getContents().get(0);
return resource.getContents().get(0);
}
/**
* Persists the specified <code>obj</code> at the given
* <code>uri</code>.
*
* @param uri
* @param obj
* @throws IOException
*/
public void save(URI uri, EObject obj) throws IOException {
if (null == uri) {
throw new IllegalArgumentException("Missing file URI.");
}
Resource resource = resourceSet.createResource(uri);
resource.getContents().add(obj);
Map<String, Boolean> options = new HashMap<String, Boolean>();
options.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
options.put(XMIResource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER, Boolean.TRUE);
resource.save(options);
}
/** Convenience method to create an URI.
*
* @param projectname
* @param filename
* @param filename_extension
* @return
*/
public static URI createFileURI(String projectname, String filename, String filename_extension) {
if (null == projectname) {
throw new IllegalArgumentException("Missing project name.");
}
if (null == filename) {
throw new IllegalArgumentException("Missing file name.");
}
if (null == filename_extension) {
throw new IllegalArgumentException("Missing file name extension.");
}
/* TODO check for null pointer exceptions */
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(projectname);
String projectPath = project.getLocationURI().getPath();
URI fileURI = URI.createFileURI(projectPath);
return fileURI.appendSegment(filename).appendFileExtension(filename_extension);
}
/**
* Convenience method to determine the current model location.
* @return
*/
public URI getCurrentModelUri() {
return currentUri;
}
}
package edu.kit.ipd.descartes.adaptation.model.repository;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
private static BundleContext context;
static BundleContext getContext() {
return context;
}
/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
}
/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
}
}
package edu.kit.ipd.descartes.adaptation.model.repository.dmm;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.change.ChangeDescription;
import org.eclipse.emf.ecore.change.util.ChangeRecorder;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.DanglingHREFException;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import edu.kit.ipd.descartes.adaptation.model.repository.AbstractEcoreModelLoader;
import edu.kit.ipd.descartes.mm.adaptation.AdaptationPackage;
import edu.kit.ipd.descartes.mm.adaptation.AdaptationProcess;
import edu.kit.ipd.descartes.mm.adaptationpoints.AdaptationpointsPackage;
import edu.kit.ipd.descartes.mm.containerrepository.ContainerrepositoryPackage;
import edu.kit.ipd.descartes.mm.resourcelandscape.DistributedDataCenter;
import edu.kit.ipd.descartes.mm.resourcelandscape.ResourcelandscapePackage;
public class AdaptationProcessModelLoader extends AbstractEcoreModelLoader {
public static final EPackage[] DMM_EPACKAGES = new EPackage[] {
ResourcelandscapePackage.eINSTANCE,
AdaptationpointsPackage.eINSTANCE,
ContainerrepositoryPackage.eINSTANCE,
AdaptationPackage.eINSTANCE };
private static AdaptationProcessModelLoader instance = null;
private static ChangeRecorder recorder = null;
public static AdaptationProcessModelLoader getInstance() {
if (instance == null) {
instance = new AdaptationProcessModelLoader();
}
return instance;
}
private AdaptationProcessModelLoader() {
initializeResourceSet(new ResourceSetImpl());
}
public static void saveAll() throws IOException {
EList<Resource> resources = getInstance().getResourceSet().getResources();
Map<String, String> options = new HashMap<String, String>();
options.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE.toString());
options.put(XMIResource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER, Boolean.TRUE.toString());
options.put(XMIResource.OPTION_PROCESS_DANGLING_HREF, XMIResource.OPTION_PROCESS_DANGLING_HREF_THROW);
for (Resource res : resources) {
try {
res.save(options);
} catch (IOException e) {
if (e.getCause() instanceof DanglingHREFException) {
String newMessage = "Error while persisting " + res.getURI()
+ " because of dangling references. Probably not all changes have been saved.\n";
throw new IOException(newMessage + e.getMessage(), e.getCause());
}
}
}
}
@Override
public void initializeResourceSet(ResourceSet resourceSet) {
setResourceSet(resourceSet);
/* Register the default resource factory -- only needed for stand-alone! */
getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
/* Register also the packages needed for the DMM meta model */
for (EPackage ePackage : DMM_EPACKAGES) {
getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap().put(ePackage.getNsURI(), ePackage);
}
}
public static DistributedDataCenter getDistributedDataCenter() {
for (Iterator<Resource> iter = getInstance().getResourceSet().getResources().iterator(); iter.hasNext();) {
Resource resource = (Resource) iter.next();
if (resource.getContents().get(0).eClass().getClassifierID() == ResourcelandscapePackage.DISTRIBUTED_DATA_CENTER)
return (DistributedDataCenter) resource.getContents().get(0);
}
return null;
}
@Override
public AdaptationProcess load(URI uri) {
return (AdaptationProcess) super.load(uri);
}
public static void startRecording() {
recorder = new ChangeRecorder(getInstance().getResourceSet());
}
public static ChangeDescription endRecording() {
return recorder.endRecording();
}
public static void endRecordingAndRollback() {
recorder.endRecording().apply();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment