Skip to main content



      Home
Home » Modeling » EMF » EPackage to containing PluginID
EPackage to containing PluginID [message #406288] Wed, 10 January 2007 09:22 Go to next message
Eclipse UserFriend
I need to get hold of the plugin ID of EPackages ( from generated EMF
plugins with appropraite generated_package extensions ) that I am being
passed in an Editor so that I can add them in turn to the dependencies of
a Plugin I am generating.

What is the best way of doing this given an EPackage object reference
gained from the EPackage registry...

EPackage.Registry registry = EPackage.Registry.INSTANCE;
EPackage aPackage = registry.getEPackage(nsURI);

Should I be getting hold of the GenModels ( and calling getModelPluginID()
) associated with these EPackages ( using
EcorePlugin.getEPackageNsURIToGenModelLocationMap(); ) and going from
there ?

If I use EcorePlugin.getEPackageNsURIToGenModelLocationMap() what is the
best way to turn the URIs from it into Resources or GenModels?


Thanks
Re: EPackage to containing PluginID [message #406289 is a reply to message #406288] Wed, 10 January 2007 11:28 Go to previous messageGo to next message
Eclipse UserFriend
I have tried the following but I get an IOEXception
"java.io.FileNotFoundException: /model/Model%20TestOne.genmodel" when the
ResourceSet
( which is constructed simply as follows
ResourceSet genModelResSet = new ResourceSetImpl(); )
tries to load the resource pointed to by the URL... The file is essentialy
the resource path within the Plugin. This is strange because I used this
code elsewhere to load the same genmodel without a problem within my
plugin.

public String getModelPluginIDfromEPackageNSUri(String nsURI)
{
Map map = EcorePlugin.getEPackageNsURIToGenModelLocationMap();
if(map == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Cannot load
EcorePlugin NsURI to GenModel location map");
return null;
}
URI genModelLocation = (URI)map.get(nsURI);
if(genModelLocation == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Cannot find
GenModel for EPackage with NS URI " + nsURI);
return null;
}
Resource res = null;
try
{
res = genModelResSet.getResource(genModelLocation, true);
}
catch(RuntimeException ex)
{
System.out.println("Problem ...." + ex);
}
if(res != null)
{
GenModel coreGenModel = (GenModel)res.getContents().get(0);
if(coreGenModel != null)
{
return coreGenModel.getModelPluginID();
}
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Resource at " +
genModelLocation + " which is meant to contain GenModel for EPackage with
NS URI " + nsURI + " contains no GenModel at its root!");
}
else
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Cannot load
GenModel at " + genModelLocation + " for EPackage with NS URI " + nsURI);
}
return null;
}
Re: EPackage to containing PluginID [message #406291 is a reply to message #406289] Wed, 10 January 2007 12:24 Go to previous messageGo to next message
Eclipse UserFriend
This code works fine, except that the plugin.xml contained an invalid name
for the genmodel file.

The question is... is there a better way..
Re: EPackage to containing PluginID [message #406299 is a reply to message #406291] Wed, 10 January 2007 15:33 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I really liked your code and I am actually thinking on converting it to
a JUnit test. But I can only do it if you post the snippet on a
bugzilla that would be used to track it as a contribution. Of course
you are free to say "no, not interested" ;-)

Anyways, I run your code without any problems and was able to print out
"org.eclipse.emf.ecore" as the getModelPluginID() of the loaded
genmodel. There are 3 "gotchas" on the logic though:

- This code has to be executed under a plugin in Eclipse since the
EPackageNsURIToGenModelLocation map is computed from the plugin registry

- The plugin.xml has to properly register the genmodel

- The GenModel file has to be available during runtime.

If one of the first 2 issues is a problem, you could try to load all
".gemodel" files in the same directory of the ".ecore" file to identify
which one refers to the package you are interested on. I can't see a
workaround for the third problem ;-)

Btw, I didn't get your "the plugin.xml contained an invalid name"
comment. I will need more information to be able to help if this is a
problem you need to solve.

Cheers,
Marcelo.

JF wrote:
> This code works fine, except that the plugin.xml contained an invalid
> name for the genmodel file.
>
> The question is... is there a better way..
>
Re: EPackage to containing PluginID [message #406313 is a reply to message #406299] Thu, 11 January 2007 06:04 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
Sorry, I solved my problem which was basically, as per your email

- The plugin.xml has to properly register the genmodel

It didn't because the file name contained spaces and the plugin.xml
contained %20 instead of a space for the location of the genmodel and the
genmodel file name on disk contained a space not %20. I'm not sure if this
was me or EMF/Eclipse I'll check it out and see if I can reproduce the
problem by creating a simple project from an Ecore model file whose name
contains spaces.


I'll put the code into Bugzilla as an enhancement request. I guess for the
code to work headless the plugin which is being used would have to be
found as a Project not a proper plugin. But then if you are running
outside Eclipse you can't expect it to function identically...

Thanks
Re: EPackage to containing PluginID [message #406326 is a reply to message #406313] Thu, 11 January 2007 11:15 Go to previous messageGo to next message
Eclipse UserFriend
Can't reproduce the space %20 problem yet so it seems its User Error ( Mea
Culpa )
Re: EPackage to containing PluginID [message #406440 is a reply to message #406299] Wed, 17 January 2007 13:58 Go to previous messageGo to next message
Eclipse UserFriend
I found a problem with this method, which occurs when the GenModel "lies"
which it unfortunately does with the GenModel in
org.eclipse.emf.edit_2.2.1.v200609210005.jar which gives the plugin as
org.eclipse.emf.edit.tree not org.eclipse.emf.edit

I have a version of RegistryReader which I use to create a global map of
plugin IDs belonging to plugins which have extension instances of the
generated_package extension point which allows me to track the "real
plugin ids"

There is one problem with this as well which is that EcorePlugin does not
make its literals public so I have to copy them...

I am testing this now and will post the code if you are interested... my
helper performs 2 main tasks ..
1) getting hold of "cannonical" EClassifier, EStructuralFeature and
EPackage references so that my code does not have tow ways of getting
instances of the "same" thing
2) keeping a registry of the used plugins so that I can show them in a
Resource/Plugin outline in my editor....
Re: EPackage to containing PluginID [message #406441 is a reply to message #406440] Wed, 17 January 2007 14:22 Go to previous messageGo to next message
Eclipse UserFriend
Heres the code...


package uk.co.his.tool2.emf.resources;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.plugin.RegistryReader;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;

import
uk.co.his.tool2.emf.utils.AssembledCommandEnhancerAFEditingD omain.ResSetWithPluginRefs;
import uk.co.his.tool2.utils.LoggingSupport;
import emf_project_support_plugin.EMFSupportPlugin;

public class EmfRegistryHelper
{
public static interface RegistryListener
{
void packageAdded(String nsURI);
void packageRemoved(String nsURI);
void pluginAdded(String pluginID);
void pluginRemoved(String pluginID);
}

public static class RegistryListenerImpl implements RegistryListener
{

public HashSet packageURIs = new LinkedHashSet();
public HashSet pluginIDs = new LinkedHashSet();
public Set syncPackageURIs = Collections.synchronizedSet(packageURIs);
public Set syncPluginIDs = Collections.synchronizedSet(pluginIDs);

public void packageAdded(String nsURI)
{
syncPackageURIs.add(nsURI);
}

public void packageRemoved(String nsURI)
{
syncPackageURIs.remove(nsURI);
}

public void pluginAdded(String pluginID)
{
syncPluginIDs.add(pluginID);
}

public void pluginRemoved(String pluginID)
{
syncPluginIDs.remove(pluginID);
}

public Set getPluginIDs()
{
synchronized (syncPluginIDs)
{
return (Set) pluginIDs.clone();
}
}

public Set getPackageURIs()
{
synchronized (syncPackageURIs)
{
return (Set) packageURIs.clone();
}
}

}

LinkedHashMap registeredEPackageNsURIsToModelPluginIDs = new
LinkedHashMap();
LinkedHashMap registeredModelPluginIDsToEPackageNSUris = new
LinkedHashMap();

/**
* This contains the mapping from all plugin ids in the Platform Registry
to the generated package NS URIs that the plugin contains
*/
LinkedHashMap globalPluginIDsToEPackageNSUris = new LinkedHashMap();
/**
* onTheFlyPackages are those that the Editor generates when asked to by
the User
* They are tracked for the duration of the generation of the new plugin
run only
* Then the collection is cleared
*/
HashSet onTheFlyPackages = new HashSet();
ResourceSet genModelResSet = new ResourceSetImpl();
boolean checkIDs = true;
ArrayList listeners = new ArrayList();

/**
* This is used to indicate that a User wishes to manually add a
reference to a plugin
* This is useful if they are intending to use it and wish the
ResourceOutlineView to show its Packages for DND
*/
public final static Object EXPLICIT_USER_REF = new Object();

public static Collection getRegisteredEPackageNsURIs()
{
EPackage.Registry registry = EPackage.Registry.INSTANCE;
return registry.keySet();
}

public static boolean isValidEPackageNsURI(String ID)
{
EPackage.Registry registry = EPackage.Registry.INSTANCE;
EPackage aPackage = registry.getEPackage(ID);
return (aPackage != null);
}

public static EPackage getEPackage(String nsURI)
{
EPackage.Registry registry = EPackage.Registry.INSTANCE;
return registry.getEPackage(nsURI);
}

public static EmfRegistryHelper getHelper(Resource res)
{
if(res == null) return null;
ResourceSet resSet = res.getResourceSet();
if(resSet instanceof ResSetWithPluginRefs)
{
return ((ResSetWithPluginRefs)resSet).getRegistryHelper();
}
return null;
}

public static void printOutRegistryNamespaces()
{
IExtensionRegistry registry = Platform.getExtensionRegistry();
String[] nameSpaces = registry.getNamespaces();
for(int i = 0; i < nameSpaces.length; i++)
{
System.out.println("NameSpace: " + nameSpaces[i]);
}
}

public EmfRegistryHelper()
{
initializeGlobalPluginIdToGenPackageUriMap();
}

public synchronized String
getGeneratedJavaPackageBaseNameForEPackage(String nsURI)
{
Map map = EcorePlugin.getEPackageNsURIToGenModelLocationMap();
if(map == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Cannot load
EcorePlugin NsURI to GenModel location map");
return null;
}
URI genModelLocation = (URI)map.get(nsURI);
if(genModelLocation == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Cannot find
GenModel for EPackage with NS URI " + nsURI);
return null;
}
Resource res = null;
try
{
res = genModelResSet.getResource(genModelLocation, true);
}
finally
{
if(res == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Problem loading
GenModel at " + genModelLocation + " for EPackage with NS URI " + nsURI);
return null;
}
}
if(res != null)
{
GenModel coreGenModel = (GenModel)res.getContents().get(0);
if(coreGenModel != null)
{
for(Iterator iter = coreGenModel.getGenPackages().iterator();
iter.hasNext(); )
{
GenPackage genPackage = (GenPackage) iter.next();
if(nsURI.equals(genPackage.getEcorePackage().getNsURI()))
{
return genPackage.getBasePackage();
}
}
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "GenModel for
EPackage with NS URI " + nsURI + " contains no GenPackage with matching NS
URI");
}
else
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Resource at " +
genModelLocation + " which is meant to contain GenModel for EPackage with
NS URI " + nsURI + " contains no GenModel at its root!");
}
}
else
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Cannot load
GenModel at " + genModelLocation + " for EPackage with NS URI " + nsURI);
}
return null;
}

public String getModelPluginIDfromEPackageNSUri(String nsURI)
{
Map map = EcorePlugin.getEPackageNsURIToGenModelLocationMap();
if(map == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Cannot load
EcorePlugin NsURI to GenModel location map");
return null;
}
URI genModelLocation = (URI)map.get(nsURI);
if(genModelLocation == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Cannot find
GenModel for EPackage with NS URI " + nsURI);
return null;
}
Resource res = null;
try
{
res = genModelResSet.getResource(genModelLocation, true);
}
finally
{
if(res == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Problem loading
GenModel at " + genModelLocation + " for EPackage with NS URI " + nsURI);
return null;
}
}
if(res != null)
{
GenModel coreGenModel = (GenModel)res.getContents().get(0);
if(coreGenModel != null)
{
return coreGenModel.getModelPluginID();
}
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Resource at " +
genModelLocation + " which is meant to contain GenModel for EPackage with
NS URI " + nsURI + " contains no GenModel at its root!");
}
else
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Cannot load
GenModel at " + genModelLocation + " for EPackage with NS URI " + nsURI);
}
return null;
}

public Set getGlobalPluginIdsFromNsUri(String nsURI)
{
HashSet plugins = new HashSet();
for(Iterator iter =
globalPluginIDsToEPackageNSUris.keySet().iterator(); iter.hasNext(); )
{
String pluginID = (String) iter.next();
Set pluginIDs = (Set) globalPluginIDsToEPackageNSUris.get(pluginID);
if(pluginIDs != null)
{
if(pluginIDs.contains(nsURI)) plugins.add(pluginID);
}
}
return plugins;
}




/**
* Return all the generated EPackages contained within a given plugin,
* not just the registered one
* @param pluginID
* @return
*/
public synchronized Collection getAllEPackagesForPluginID(String
pluginID)
{
Set packageNsURIs = (Set)
globalPluginIDsToEPackageNSUris.get(pluginID);
if(packageNsURIs == null) return Collections.EMPTY_SET;
ArrayList packages = new ArrayList(packageNsURIs.size());
for(Iterator iter = packageNsURIs.iterator(); iter.hasNext(); )
{
String nsURI = (String) iter.next();
EPackage ePack = getEPackage(nsURI);
if(ePack != null) packages.add(ePack);
}
return packages;
}

public synchronized Collection
getAllRegisteredEPackagesForPluginID(String pluginID)
{
Set packageNsURIs = (Set)
registeredModelPluginIDsToEPackageNSUris.get(pluginID);
if(packageNsURIs == null) return Collections.EMPTY_SET;
ArrayList packages = new ArrayList(packageNsURIs.size());
for(Iterator iter = packageNsURIs.iterator(); iter.hasNext(); )
{
Object usage = iter.next();
if(usage != EXPLICIT_USER_REF)
{
String nsURI = (String)usage;
EPackage ePack = getEPackage(nsURI);
if(ePack != null) packages.add(ePack);
}
}
return packages;
}

/**
* Obtain a "cannonical" or "normalized" EClassifier reference
* References obtained by dynamic construction, from arbitrary Resources
( i.e. your own file reference )
* ... or even possibly through programmatic references such as
MyPackageClass.eINSTANCE which are not in the same ClassLoader context
* may give identical classes which are different java instances
*
* @param eClassifier
* @return the equivalent registered package EClassifier
*/
public synchronized EClassifier getCannonicalEClassifier(EClassifier
eClassifier, boolean register)
{
EPackage containingPackage = eClassifier.getEPackage();
if(containingPackage == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Unable to get
cannonical EClassifier; unable to find plugin or EPackage for EClassifier
" + eClassifier.getName());
return null;
}
EPackage cannonicalEPackage = getCannonicalEPackage(containingPackage,
register);
if(cannonicalEPackage == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Unable to get
cannonical EClassifier " + eClassifier.getName() + ", cannot get
associated cannonical EPackage");
return null;
}
return cannonicalEPackage.getEClassifier(eClassifier.getName());
}

/**
* Obtain a "cannonical" or "normalized" EStructuralFeature reference
* References obtained by dynamic construction, from arbitrary Resources
( i.e. your own file reference )
* ... or even possibly through programmatic references such as
MyPackageClass.eINSTANCE which are not in the same ClassLoader context
* may give identical features which are different java instances
*
* @param feature
* @return the equivalent registered package EStructuralFeature
*/
public synchronized EStructuralFeature
getCannonicalEStructuralFeature(EStructuralFeature feature, boolean
register)
{
EClass cannonicalClassifier =
(EClass)getCannonicalEClassifier(feature.getEContainingClass (), register);
if(cannonicalClassifier == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Unable to get
cannonical Structural Feature " + feature.getName() + ", cannot get
cannonical owning EClassifier");
return null;
}
EStructuralFeature cannonicalFeature =
cannonicalClassifier.getEStructuralFeature(feature.getName() );
if(cannonicalFeature == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Unable to get
cannonical Structural Feature " + feature.getName() + ", cannot find it in
cannonical owning EClassifier");
return null;
}
return cannonicalFeature;
}


public synchronized EPackage getCannonicalEPackage(String nsURI,
boolean register)
{
EPackage.Registry registry = EPackage.Registry.INSTANCE;
EPackage aPackage = registry.getEPackage(nsURI);
if(aPackage == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Cannot find EMF
package with URI " + nsURI);
return null;
}
if(register)
{
registerEPackageNsURI(nsURI, checkIDs);
}
return aPackage;
}

public EPackage getCannonicalEPackage(EPackage ePackage, boolean
register)
{
return getCannonicalEPackage(ePackage.getNsURI(), register);
}

public synchronized boolean manualEmfPluginRegistration(String
pluginID)
{
if(globalPluginIDsToEPackageNSUris.get(pluginID) == null)
{
LoggingSupport.warn(EMFSupportPlugin.getPlugin(), "Plugin ID " +
pluginID + " is either not a valid plugin or does not contain any
\"generated_package\" extensions, or the Platform.registry has been
updated");
return false;
}
boolean notify = false;
if(registeredModelPluginIDsToEPackageNSUris.get(pluginID) == null)
{
registeredModelPluginIDsToEPackageNSUris.put(pluginID, new
HashSet());
}

((Set)registeredModelPluginIDsToEPackageNSUris.get(pluginID) ).add(EXPLICIT_USER_REF);
if(notify)
{
notifyListenersOfPluginAdd(pluginID);
}
return true;
}

public synchronized void manuallyRemoveEmfPluginRegistration(String
pluginID)
{
if(registeredModelPluginIDsToEPackageNSUris.get(pluginID) == null)
{
LoggingSupport.info(EMFSupportPlugin.getPlugin(), "EMF Plugin " +
pluginID + " is not registered");
return;
}
Set ids = (Set)
registeredModelPluginIDsToEPackageNSUris.get(pluginID);
ids.remove(EXPLICIT_USER_REF);
if(ids.isEmpty())
{
registeredModelPluginIDsToEPackageNSUris.remove(pluginID);
notifyListenersOfPluginRemoved(pluginID);
}
}

public synchronized void removeEPackageReference(String nsURI)
{
removeEPackageReferenceToModelPlugin(nsURI);
}

public void removeEPackageReference(EPackage ePackage)
{
removeEPackageReference(ePackage.getNsURI());
}

public synchronized Collection
getUsedEmfGeneratedPackageModelPluginIDs()
{
return new HashSet(registeredModelPluginIDsToEPackageNSUris.keySet());
}

public synchronized void setCheckIDs(boolean checkIDs)
{
this.checkIDs = checkIDs;
}

/**
* @param listener
* @param update, if true communicates all the current state to the
listener
*/
public synchronized void addListener(RegistryListener listener, boolean
update)
{
listeners.add(listener);
if(update)
{
for(Iterator iter =
registeredModelPluginIDsToEPackageNSUris.keySet().iterator() ;
iter.hasNext(); )
{
String pluginID = (String) iter.next();
listener.pluginAdded(pluginID);
for(Iterator packageNSUriIter =
((Set)registeredModelPluginIDsToEPackageNSUris.get(pluginID) ).iterator();
packageNSUriIter.hasNext(); )
{
String nsURI = (String) packageNSUriIter.next();
listener.packageAdded(nsURI);
}
}
}
}

public synchronized void removeListener(RegistryListener listener)
{
listeners.remove(listener);
}

public synchronized void addOnTheFlyPackage(EPackage ePackage)
{
onTheFlyPackages.add(ePackage);
}

public synchronized Set getOnTheFlyPackages()
{
return onTheFlyPackages;
}

public synchronized void clearOnTheFlyPackages()
{
onTheFlyPackages.clear();
}

private synchronized void notifyListenersOfPackageAdd(String nsURI)
{
for(Iterator iter = listeners.iterator(); iter.hasNext();)
{
RegistryListener listener = (RegistryListener) iter.next();
listener.packageAdded(nsURI);
}
}

protected synchronized void mapEPackageNsURIToPluginID(String
pluginID, String nsURI, boolean check)
{
if(check)
{
if(registeredEPackageNsURIsToModelPluginIDs.get(nsURI) != null &&
registeredEPackageNsURIsToModelPluginIDs.get(nsURI) != pluginID)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "EPackage " +
nsURI + " is already bound to PluginID " +
registeredEPackageNsURIsToModelPluginIDs.get(nsURI) + " but registry gives
" + pluginID);
}
if(globalPluginIDsToEPackageNSUris.get(pluginID) == null)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Plugin ID " +
pluginID + " is not to be found in the global registry ... will find a
substitute if possible");
Set possiblePlugins = getGlobalPluginIdsFromNsUri(nsURI);
if(possiblePlugins.size() == 0)
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "Cannot find
plugin registered in the global registry for EPackage " + nsURI +", will
not be able to locate all EPackages");
}
else if(possiblePlugins.size() > 1)
{
String names = "";
for(Iterator iter = possiblePlugins.iterator(); iter.hasNext(); )
{
names = names + ", " + iter.next();
}
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "EPackage " +
nsURI +", nsURI can be found in several plugins" + names + ". Will not be
able to locate all EPackages");
}
else
{
mapEPackageNsURIToPluginID((String)
possiblePlugins.iterator().next(), nsURI, false);
}
}
}
registeredEPackageNsURIsToModelPluginIDs.put(nsURI, pluginID);
boolean notifyOfPlugin = false;
if(registeredModelPluginIDsToEPackageNSUris.get(pluginID) == null)
{
registeredModelPluginIDsToEPackageNSUris.put(pluginID, new HashSet());
notifyOfPlugin = true;
}
Set packagesInPlugin = (Set)
registeredModelPluginIDsToEPackageNSUris.get(pluginID);
boolean notifyOfPackage = !packagesInPlugin.contains(nsURI);
packagesInPlugin.add(nsURI);
if(notifyOfPlugin)
{
notifyListenersOfPluginAdd(pluginID);
}
if(notifyOfPackage)
{
notifyListenersOfPackageAdd(nsURI);
}
}

private synchronized void registerEPackageNsURI(String nsURI, boolean
check)
{
String existingID = (String)
registeredEPackageNsURIsToModelPluginIDs.get(nsURI);
if(existingID == null)
{
String pluginID = getModelPluginIDfromEPackageNSUri(nsURI);
if(pluginID == null) return;
mapEPackageNsURIToPluginID(pluginID, nsURI, check);
return;
}
else if(check)
{
String pluginID = getModelPluginIDfromEPackageNSUri(nsURI);
if(!existingID.equals(pluginID))
{
LoggingSupport.error(EMFSupportPlugin.getPlugin(), "EPackage " +
nsURI + " is already bound to GenModel with Model Plugin ID value of " +
existingID + " but dynamic lookup gives " + pluginID);
}
}

}

private synchronized void notifyListenersOfPluginAdd(String pluginID)
{
for(Iterator iter = listeners.iterator(); iter.hasNext();)
{
RegistryListener listener = (RegistryListener) iter.next();
listener.pluginAdded(pluginID);
}
}



private synchronized void notifyListenersOfPackageRemoved(String nsURI)
{
for(Iterator iter = listeners.iterator(); iter.hasNext();)
{
RegistryListener listener = (RegistryListener) iter.next();
listener.packageRemoved(nsURI);
}
}

private synchronized void removeEPackageReferenceToModelPlugin(String
nsURI)
{
if(registeredEPackageNsURIsToModelPluginIDs.get(nsURI) == null)
{
LoggingSupport.info(EMFSupportPlugin.getPlugin(), "EMF Plugin
reference with URI " + nsURI + " is not registered");
return;
}
String pluginID = (String)
registeredEPackageNsURIsToModelPluginIDs.get(nsURI);
Set ids = (Set)
registeredModelPluginIDsToEPackageNSUris.get(pluginID);
ids.remove(nsURI);
notifyListenersOfPackageRemoved(nsURI);
if(ids.isEmpty())
{
registeredModelPluginIDsToEPackageNSUris.remove(pluginID);
notifyListenersOfPluginRemoved(pluginID);
}
}

private synchronized void notifyListenersOfPluginRemoved(String pluginID)
{
for(Iterator iter = listeners.iterator(); iter.hasNext();)
{
RegistryListener listener = (RegistryListener) iter.next();
listener.pluginRemoved(pluginID);
}
}

private void initializeGlobalPluginIdToGenPackageUriMap()
{
printOutRegistryNamespaces();
GeneratedPackageToPluginIDReader reader = new
GeneratedPackageToPluginIDReader(globalPluginIDsToEPackageNS Uris);
reader.readRegistry();
printOutGlobalPluginToGenPackageURIMap();
}

private void printOutGlobalPluginToGenPackageURIMap()
{
for(Iterator iter = globalPluginIDsToEPackageNSUris.keySet().iterator();
iter.hasNext(); )
{
String pluginID = (String) iter.next();
System.out.println("Plugin " + pluginID + "-->");
Collection nsURIs = (Collection)
globalPluginIDsToEPackageNSUris.get(pluginID);
for(Iterator nsIter = nsURIs.iterator(); nsIter.hasNext(); )
{
System.out.println("\t" + nsIter.next());
}
System.out.println("");
}
}

/**
* Read the registry and get the names of plugins that define extensions
for Ecores generated_package extension point
*
* Ideally this would re-use
org.eclipse.emf.ecore.plugin.GeneratedPackageRegistryReader as well as the
* Ecore defined literals, particularly EcorePlugin.GENERATED_PACKAGE_PPID
* However none of these are visible.
* The only way to do this in Ecore is via the very arcane way of
iterating through EPackage.Registry.INSTANCE keys and values
* The values are of type RegistryReader.EPackageDescriptor and the name
?can be located by
element.getDeclaringExtension().getContributor().getName()
* see below
*
* @author john
*
*/
protected static class GeneratedPackageToPluginIDReader extends
RegistryReader
{
static final String TAG_PACKAGE = "package";
static final String ATT_URI = "uri";
static final String ATT_CLASS = "class";
static final String ATT_GEN_MODEL = "genModel";
static final String GENERATED_PACKAGE_PPID = "generated_package";

protected Map pluginIDToGeneratedPackageNsUriMap;

public GeneratedPackageToPluginIDReader(Map mapping)
{
super(Platform.getExtensionRegistry(),
EcorePlugin.getPlugin().getBundle().getSymbolicName(),
GENERATED_PACKAGE_PPID);
pluginIDToGeneratedPackageNsUriMap = mapping;
}

protected GeneratedPackageToPluginIDReader(IExtensionRegistry
pluginRegistry, String pluginID, String extensionPointID)
{
super(pluginRegistry, pluginID, extensionPointID);
}

protected void addNsURIRefToPluginID(String pluginID, String nsURI)
{
if(pluginIDToGeneratedPackageNsUriMap.get(pluginID) == null)
{
pluginIDToGeneratedPackageNsUriMap.put(pluginID, new LinkedHashSet());
}
((Collection)
pluginIDToGeneratedPackageNsUriMap.get(pluginID)).add(nsURI) ;
}

protected boolean readElement(IConfigurationElement element)
{
if(element.getName().equals(TAG_PACKAGE))
{
String packageURI = element.getAttribute(ATT_URI);
if(packageURI == null)
{
logMissingAttribute(element, ATT_URI);
}
else
{
String pluginID =
element.getDeclaringExtension().getContributor().getName();
if(pluginID != null)
{
addNsURIRefToPluginID(pluginID, packageURI);
}
else
{
LoggingSupport.warn(EMFSupportPlugin.getPlugin(), "Cannot find
PluginID for Gen package extension with NS URI " + packageURI);
}
return true;
}
}

return false;
}

}
}
Re: EPackage to containing PluginID [message #406442 is a reply to message #406440] Wed, 17 January 2007 14:40 Go to previous messageGo to next message
Eclipse UserFriend
JF,

Please open a bugzilla to fix Tree.genmodel to specify the correct
plugin ID.


JF wrote:
> I found a problem with this method, which occurs when the GenModel
> "lies" which it unfortunately does with the GenModel in
> org.eclipse.emf.edit_2.2.1.v200609210005.jar which gives the plugin as
> org.eclipse.emf.edit.tree not org.eclipse.emf.edit
>
> I have a version of RegistryReader which I use to create a global map
> of plugin IDs belonging to plugins which have extension instances of
> the generated_package extension point which allows me to track the
> "real plugin ids"
>
> There is one problem with this as well which is that EcorePlugin does
> not make its literals public so I have to copy them...
>
> I am testing this now and will post the code if you are interested...
> my helper performs 2 main tasks .. 1) getting hold of "cannonical"
> EClassifier, EStructuralFeature and EPackage references so that my
> code does not have tow ways of getting instances of the "same" thing
> 2) keeping a registry of the used plugins so that I can show them in a
> Resource/Plugin outline in my editor....
>
Re: EPackage to containing PluginID [message #406447 is a reply to message #406442] Thu, 18 January 2007 06:37 Go to previous messageGo to next message
Eclipse UserFriend
Done, reported against 2.2.1 as this thats the version number on the jar

Can I put in an enhancement request for the "non-public" EcorePlugin
extension point literals, or is there a better way of doing this...
Re: EPackage to containing PluginID [message #406449 is a reply to message #406447] Thu, 18 January 2007 08:05 Go to previous messageGo to next message
Eclipse UserFriend
JF,

I suppose you could yes. I didn't suggest it because we can't really
ever change these names... I assume for both these things that it's
sufficient to fix them only in 2.3, right?


JF wrote:
> Done, reported against 2.2.1 as this thats the version number on the jar
>
> Can I put in an enhancement request for the "non-public" EcorePlugin
> extension point literals, or is there a better way of doing this...
>
Re: EPackage to containing PluginID [message #406451 is a reply to message #406449] Thu, 18 January 2007 10:39 Go to previous message
Eclipse UserFriend
Yes 2.3 would be fine...

Using EcorePlugin as the source for these names shows explicitly where
they originate...
Previous Topic:[Announce] EMF 2.3.0 I200701180200 is available
Next Topic:[Announce] EMF 2.2.2 M200701181044 is available
Goto Forum:
  


Current Time: Wed Nov 05 17:06:35 EST 2025

Powered by FUDForum. Page generated in 0.04983 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top