blob: 8b12e1230f75ef2ff81b99bd49ef05df23f2db3a [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Peter Pasztor, Akos Horvath, Gergely Varro, Istvan Rath and Daniel Varro
* 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:
* Peter Pasztor, Akos Horvath, Gergely Varro, Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.gtasm.interpreter.internal;
import org.eclipse.core.runtime.Plugin;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.viatra2.gtasm.interpreter.extension.INativeASMRule;
import org.osgi.framework.BundleContext;
public class ViatraGTASMInterpreterPlugin extends Plugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.viatra2.gtasm.interpreter";
// Extension points
public static final String NATIVE_ASM_RULE_EXT_ID = "org.eclipse.viatra2.gtasm.interpreter.nativeasmrule";
// The shared instance
private static ViatraGTASMInterpreterPlugin plugin;
/* Native ASM rules*/
private Map<String,INativeASMRule> nativeASMRules;
/**
* The constructor
*/
public ViatraGTASMInterpreterPlugin () {
plugin = this;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static ViatraGTASMInterpreterPlugin getDefault() {
return plugin;
}
/** Returns a Map that contains all Native AMS rule implementation attached to the org.eclipse.viatra2.gtasm.interpreter.impl.interpreter
* @return
*/
public Map<String, INativeASMRule> getNativeAMSRules() {
if (nativeASMRules == null) {
nativeASMRules = initNativeASMRules();
}
return nativeASMRules;
}
/**
* Returns the native ASM rules registered to the interpreter
* @param id
* The id of the registered native AMS rule
* @return its implementing object
*/
public INativeASMRule getNativeAMSRules(String id) {
if (nativeASMRules == null || nativeASMRules.size() == 0) {
nativeASMRules= initNativeASMRules();
}
return nativeASMRules.containsKey(id)?nativeASMRules.get(id):null;
}
private Map<String, INativeASMRule> initNativeASMRules() {
IExtensionRegistry reg = Platform.getExtensionRegistry();
IExtensionPoint poi = reg.getExtensionPoint(NATIVE_ASM_RULE_EXT_ID);
HashMap<String, INativeASMRule> r = new HashMap<String, INativeASMRule>();
if (poi == null)
return r;
IExtension[] exts = poi.getExtensions();
for (int i = 0; i < exts.length; i++) {
IConfigurationElement[] el = exts[i].getConfigurationElements();
for (int j = 0; j < el.length; j++) {
try {
Object o = el[j].createExecutableExtension("class");
if (o instanceof INativeASMRule) {
String id = ((INativeASMRule)o).getID();
r.put(id, (INativeASMRule) o);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return r;
}
}