/******************************************************************************* | |
* Copyright (c) 2004-2008 Akos Horvath, Gergely Varro 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: | |
* Akos Horvath, Gergely Varro - initial API and implementation | |
*******************************************************************************/ | |
package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.extension; | |
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.core.runtime.Plugin; | |
import org.osgi.framework.BundleContext; | |
/** | |
* The activator class for the GtMatcher. Holds the references for the alternative pattern matcher | |
* @author Akos Horvath | |
* | |
*/ | |
public class VIATRAGTMatcherPlugin extends Plugin { | |
// The plug-in ID | |
public static final String PLUGIN_ID = "org.eclipse.viatra2.gtasm.patternmatcher.impl"; | |
//Extension points | |
public static final String PATTERN_MATCHER_EXT_ID = "org.eclipse.viatra2.gtasm.patternmatcher.impl.alternativepatternmatcher"; | |
public static final String INCREMENTAL_PM_FACTORY_ID="org.eclipse.viatra2.gtasm.patternmatcher.incremental.alternativeGTmatcher"; | |
// public static final String INCREMENTAL_PARALlEL_PM_FACTORY_ID="org.eclipse.viatra2.gtasm.patternmatcher.incremental.parallel.alternativeGTmatcher"; | |
// public static final String LOCAL_PM_FACTORY_ID = "org.eclipse.viatra2.local_search"; | |
public static final String DEFAULT_ALTERNATIVE_PM_FACTORY_ID = INCREMENTAL_PM_FACTORY_ID; | |
// The shared instance | |
private static VIATRAGTMatcherPlugin plugin; | |
/** | |
* The constructor | |
*/ | |
public VIATRAGTMatcherPlugin() { | |
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 VIATRAGTMatcherPlugin getDefault() { | |
return plugin; | |
} | |
/** PATTERN MATCHER FACTORIES*/ | |
private Map<String,IAlternativePatternMatcherFactory> patternMatcherFactories; | |
public Map<String,IAlternativePatternMatcherFactory> getPatternMatcherFactories() | |
{ | |
if (patternMatcherFactories==null) | |
{ | |
patternMatcherFactories = initPatternMatcherFactories(); | |
} | |
return patternMatcherFactories; | |
} | |
/** Returns the pattern matcher registered with the input id | |
* @param id The id of the registered patternMatcher plugin id | |
* @return the IAlternativePatternMatcherFactory for the patternMatcher | |
*/ | |
public IAlternativePatternMatcherFactory getPatternMatcherFactory(String id){ | |
if (patternMatcherFactories==null) | |
{ | |
patternMatcherFactories = initPatternMatcherFactories(); | |
} | |
return patternMatcherFactories.containsKey(id)? patternMatcherFactories.get(id): null; | |
} | |
private Map<String,IAlternativePatternMatcherFactory> initPatternMatcherFactories() | |
{ | |
IExtensionRegistry reg = Platform.getExtensionRegistry(); | |
IExtensionPoint poi = reg.getExtensionPoint(PATTERN_MATCHER_EXT_ID); | |
HashMap<String,IAlternativePatternMatcherFactory> r = new HashMap<String,IAlternativePatternMatcherFactory>(); | |
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 IAlternativePatternMatcherFactory) | |
{String id = (String)el[j].getAttribute("id"); | |
r.put(id,(IAlternativePatternMatcherFactory)o); | |
} | |
} | |
catch (Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
} | |
return r; | |
} | |
/** Checks if there is a registered pattern matcher on the plugin | |
* @return | |
*/ | |
public Boolean hasAlternativePatternMatcher(){ | |
if (patternMatcherFactories==null) | |
{ | |
patternMatcherFactories = initPatternMatcherFactories(); | |
} | |
return patternMatcherFactories.size() > 0; | |
} | |
} |