public class StandaloneProjectMap extends java.lang.Object implements ProjectManager
ProjectMap
provide facilities to assist in
preparing the URIConverter
, the EPackage.Registry
, and the
and URIResourceMap of a ResourceSet
and the global and
EcorePlugin.getPlatformResourceMap()
and
EcorePlugin.getEPackageNsURIToGenModelLocationMap()
to support
arbitrary and compatible use of dynamically loaded resources such as
platform:/plugin and platform:/resource and
generated EPackages such as registered namespace URIs in both plugin and standalone
environments.
StandaloneProjectMap supports only standalone usage and so is free of dependencies on the Eclipse platform. ProjectMap extends StandaloneProjectMap to provide polymorphic standalone and plugin environments.
As a result, when the current file context is my.project/model/MyModel.ecore, and when the classpath contains only the JAR version of Ecore, referencing a resource as any or all of
ResourceSet.getResource(URI, boolean)
.
If the classpath contains distinct imported project and JAR versions of Ecore, referencing
A ProjectMap consists of a map from a project or bundle name to a location
that is resolvable by the conventional Platform URL stream opening
capabilities. Utility methods support export of the map to initialize the
URIMap in a URIConverter
and/or the
EcorePlugin.getPlatformResourceMap()
.
Minimal usage to configure aResourceSet is just
new ProjectMap().initializeResourceSet(aResourceSet);
or ProjectMap.getAdapter(aResourceSet);
Thereafter EMF accesses to projects and bundles should just work.
getProjectDescriptors()
returns a map of project names and bundle names to a
physical location which is established by searching the classpath for folders
and JARs containing .project files. If a manifest is also found, the search
has found a bundle and the Bundle-SymbolicName is read from the manifest.
initializePackageRegistry(ResourceSet)
populates a
registration for each genPackages.ecorePackage referenced from a
genmodel referenced from a
org.eclipse.emf.ecore.generated_package defined in any
plugin.xml found on the classpath. The three declarations ensure
that when appropriate, each of the namespace URI (e.g.
http://www.eclipse.org/emf/2002/Ecore), the project URI (e.g.
platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore) and the
plugin URI (e.g.
platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore) resolve to
the same Resource eliminating most opportunities for meta-model
schizophrenia.
initializePlatformResourceMap(boolean)
populates
EcorePlugin.getPlatformResourceMap()
with a project to
platform:/resource/project entry for each project and a
bundle to platform:/plugin/bundle entry for each
bundle.
initializeGenModelLocationMap(boolean)
exploits the classpath
scan for plugins and projects to identify all plugin.xml files and populate
the EcorePlugin.getEPackageNsURIToGenModelLocationMap()
from the
org.eclipse.emf.ecore.generated_package extension points in the same
way as occurs automatically in a plugin environment.
initializeURIMap(ResourceSet)
installs a
platform:/plugin/project to
platform:/resource/project URI mapping for each project and a
platform:/resource/bundle to
platform:/plugin/bundle URI mapping for each bundle.
The getAdapter(ResourceSet)
method may be used to invoke
initializeResourceSet(ResourceSet)
if not already invoked and to
install the ProjectMap as a ResourceSet adapter allowing an invocation of
findAdapter(ResourceSet)
to find it for subsequent re-use.
Conflicts can only be diagnosed if the StandaloneProjectMap is aware of the conflict, so useGeneratedResource must be invoked if a GeneratedPackage is used without being loaded in the ResourceSet.
Modifier and Type | Class and Description |
---|---|
static class |
StandaloneProjectMap.AbstractResourceDescriptor
PackageDescriptor supports lazy class loading and initialization of a
compiled Ecore package.
|
static class |
StandaloneProjectMap.AbstractResourceLoadStatus |
protected static class |
StandaloneProjectMap.AbstractResourceLoadStrategy |
static class |
StandaloneProjectMap.CreateStrategy
The CreateStrategy uses a programmtically created EPackage for all kinds of access,
and then changes the strategy to the LoadedStrategy for all further accesses.
|
static class |
StandaloneProjectMap.DelegatedMultiplePackageResource
A DelegatedMultiplePackageResource may be installed in a ResourceSet.uriResourceMap so that the
appropriate generated EPackage is resolved as the fragment of a dynamically loaded
resource.
|
static class |
StandaloneProjectMap.DelegatedSinglePackageResource
A DelegatedSinglePackageResource may be installed in a ResourceSet.uriResourceMap so that the
generated EPackage is resolved as a dynamically loaded resource.
|
protected static class |
StandaloneProjectMap.EPackageDescriptor
EPackageDescriptor is an EPackage.Descriptor that loads the appropriate EPackage to resolve a Namespace URI reference
to a generated or dynamically loaded EPackage in accordance with the configured ResourceLoadStrategy.
|
protected static class |
StandaloneProjectMap.GenModelReader
GenModelReader provides the SAX callbacks to support reading
the genPackages element in a genmodel file.
|
static class |
StandaloneProjectMap.LoadBothStrategy
The LoadBothStrategy permits metamodel schizophrenia and so access to the namespace URI resolves to an installed
resource while access to the platform plugin or resource URI resolve to a dynamically loaded resource.
|
static class |
StandaloneProjectMap.LoadDynamicResourceStrategy
The LoadDynamicResourceStrategy uses the dynamic EPackage referenced by the platform resource/plugin URI for all kinds of access,
and then changes the strategy to LoadedStrategy for all further accesses.
|
static class |
StandaloneProjectMap.LoadFirstStrategy
The LoadFirstStrategy uses the EPackage corresponding to the first access as either a namespace URI
or platform plugin.resource URI.Thereafter accesses to the same URI use the first loaded EPackage.
|
static class |
StandaloneProjectMap.LoadGeneratedPackageStrategy
The LoadGeneratedPackageStrategy uses the generated EPackage referenced by the namespace URI for all kinds of access,
and then changes the strategy to the LoadedStrategy for all further accesses.
|
static class |
StandaloneProjectMap.LoadingBothLoadedDynamicResourceStrategy
The LoadingBothLoadedDynamicResourceStrategy supports the using-model behaviour following a LoadBothStrategy
that has loaded a dynamic resource.
|
static class |
StandaloneProjectMap.MapToFirstConflictHandler
MapToFirstConflictHandler resolves conflicts by returning the first loaded EPackage.
|
static class |
StandaloneProjectMap.MapToFirstConflictHandlerWithLog
MapToFirstConflictHandler resolves conflicts by returning the first loaded EPackage.
|
static class |
StandaloneProjectMap.MultiplePackageResourceDescriptor
PackageDescriptor supports lazy class loading and initialization of a
compiled Ecore package.
|
static class |
StandaloneProjectMap.MultiplePackageResourceLoadStatus |
static class |
StandaloneProjectMap.PackageDescriptor
PackageDescriptor supports lazy class loading and initialization of a
compiled Ecore package.
|
static class |
StandaloneProjectMap.PackageLoadStatus |
protected static class |
StandaloneProjectMap.PluginReader
PluginReader provides the SAX callbacks to support reading the
org.eclipse.emf.ecore.generated_package extension point in a plugin.xml
file and activating the GenModelReader to process the
ecorePackage locations.
|
static class |
StandaloneProjectMap.ProjectDescriptor |
static class |
StandaloneProjectMap.SinglePackageResourceDescriptor
PackageDescriptor supports lazy class loading and initialization of a
compiled Ecore package.
|
static class |
StandaloneProjectMap.SinglePackageResourceLoadStatus |
ProjectManager.IConflictHandler, ProjectManager.IPackageDescriptor, ProjectManager.IPackageLoadStatus, ProjectManager.IProjectDescriptor, ProjectManager.IResourceDescriptor, ProjectManager.IResourceLoadStatus, ProjectManager.IResourceLoadStrategy
Modifier and Type | Field and Description |
---|---|
protected boolean |
initializedPlatformResourceMap |
protected boolean |
isGlobal
Whether this is the Global Project Manager
|
static java.util.WeakHashMap<StandaloneProjectMap,java.lang.Object> |
liveStandaloneProjectMaps
Leak debugging aid.
|
protected java.util.Map<org.eclipse.emf.common.util.URI,ProjectManager.IPackageDescriptor> |
nsURI2package
The map of package nsURI to package descriptor.
|
static TracingOption |
PROJECT_MAP_ADD_EPACKAGE |
static TracingOption |
PROJECT_MAP_ADD_GEN_MODEL |
static TracingOption |
PROJECT_MAP_ADD_GENERATED_PACKAGE |
static TracingOption |
PROJECT_MAP_ADD_URI_MAP |
static TracingOption |
PROJECT_MAP_CONFIGURE |
static TracingOption |
PROJECT_MAP_GET |
static TracingOption |
PROJECT_MAP_INSTALL |
static TracingOption |
PROJECT_MAP_RESOLVE |
protected java.util.Map<org.eclipse.emf.common.util.URI,ProjectManager.IResourceDescriptor> |
uri2resource
The map of document URI to resource descriptor.
|
CLASS_PATH, NO_PROJECTS
Constructor and Description |
---|
StandaloneProjectMap(boolean isGlobal) |
Modifier and Type | Method and Description |
---|---|
void |
addResourceDescriptor(ProjectManager.IResourceDescriptor resourceDescriptor)
Call-back to add a resourceDescriptor.
|
void |
configure(org.eclipse.emf.ecore.resource.ResourceSet resourceSet,
ProjectManager.IResourceLoadStrategy resourceLoadStrategy,
ProjectManager.IConflictHandler conflictHandler)
Configure the PackageRegistry associated with ResourceSet to use a resourceLoadStrategy and conflictHandler when
resolving namespace ansd platform URIs.
|
protected ProjectManager.IProjectDescriptor |
createProjectDescriptor(java.lang.String projectName,
org.eclipse.emf.common.util.URI locationURI) |
protected void |
finalize() |
static StandaloneProjectMap |
findAdapter(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Return any StandaloneProjectMap already installed as an adapter on a
resourceSet.
|
static StandaloneProjectMap |
getAdapter(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Return the StandaloneProjectMap already installed as an adapter on a
resourceSet if one exists, else creates, installs, initializes
and returns a new StandaloneProjectMap.
|
java.util.Map<java.lang.String,java.lang.Exception> |
getExceptionMap()
Return the mapping of problem files to exceptions, or null if not yet
computed or if no exceptions thrown.
|
org.eclipse.emf.common.util.URI |
getLocation(java.lang.String projectName)
Return the resolveable URI for a given project or bundle name.
|
ProjectManager.IPackageDescriptor |
getPackageDescriptor(org.eclipse.emf.common.util.URI nsURI)
Return the IPackageDescriptor for a given nsURI.
|
static org.eclipse.emf.ecore.EPackage.Registry |
getPackageRegistry(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Return the EPackage.Registry for a resourceSet or the Global
EPackage.Registry.INSTANCE if resourceSet is null. |
ProjectManager.IProjectDescriptor |
getProjectDescriptor(java.lang.String projectName)
Return the IProjectDescriptor for a given project or bundle name.
|
protected ProjectManager.IProjectDescriptor |
getProjectDescriptorInternal(org.eclipse.emf.common.util.URI platformURI) |
protected java.util.Map<java.lang.String,ProjectManager.IProjectDescriptor> |
getProjectDescriptors()
Return the mapping of project name or bundle name, as defined in a
manifest file to the location of that project as determined by scanning
the classpath.
|
java.util.Set<java.lang.String> |
getProjectNames()
Return the names of all the projects/bundles.
|
ProjectManager.IResourceDescriptor |
getResourceDescriptor(org.eclipse.emf.common.util.URI uri)
Return the IResourceDescriptor for a given URI.
|
static org.eclipse.emf.ecore.resource.Resource.Factory.Registry |
getResourceFactoryRegistry(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Return the Resource.Factory.Registry for a resourceSet or the Global
Resource.Factory.Registry.INSTANCE if resourceSet is null. |
org.eclipse.emf.common.notify.Notifier |
getTarget() |
static org.eclipse.emf.ecore.resource.URIConverter |
getURIConverter(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Return the URIConverter for a resourceSet or the Global
URIConverter.INSTANCE if resourceSet is null. |
static java.util.Map<org.eclipse.emf.common.util.URI,org.eclipse.emf.common.util.URI> |
getURIMap(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Return the URI Map for a resourceSet or the Global
URIConverter.URI_MAP if resourceSet is null. |
void |
initializeGenModelLocationMap(boolean force)
Initialize the
EcorePlugin.getEPackageNsURIToGenModelLocationMap() so that in a
standalone environment the locations of all genmodels are available. |
void |
initializePackageRegistry(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Install lazy EPackageDescriptors in the EPackage.Registry for all
registered packages and their platform:/plugin and platform:/resource
synonyms, which are determined by examining the genPackages.ecorePackage
attribute in all genModels.
|
void |
initializePlatformResourceMap(boolean force)
Initialize the
EcorePlugin.getPlatformResourceMap() so that in a standalone
environment and in conjunction with initializeURIMap(ResourceSet) URIs such as
platform:/resource/project and
platform:/plugin/project are useable. |
void |
initializeResourceSet(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Ensure that both the
EcorePlugin.getPlatformResourceMap() and
ResourceSet.getURIConverter() are initialized so that
platform:/resource/project and
platform:/plugin/project are useable.. |
void |
initializeURIMap(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Initialize the uriMap of a uriConverter so that each of
platform:/resource/project and
platform:/plugin/project resolve the workspace project
resource else the plugin bundle for use in either standalone or plugin
environment.
|
static void |
initializeURIResourceMap(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Activate any ResourceSetImpl.uriResourceMap so that repeated lookups use
a hash rather than linear search.
|
static void |
initStatics()
A simple public static method that may be used to force class
initialization.
|
boolean |
isAdapterForType(java.lang.Object type) |
boolean |
isGlobal() |
protected void |
logException(java.lang.String message,
java.lang.Exception e) |
protected void |
notifyAddedDynamicResource(org.eclipse.emf.ecore.resource.ResourceSet resourceSet,
org.eclipse.emf.ecore.resource.Resource resource)
When a new Resource is added to a watched ResourceSet notify the resourceDescriptor that there is a new
(ResourceSet, Resource) pair so that it install both platform:/plugin and platform:/resource
entries in the ResourceSet's uriResourceMap and install a listener to detect when the Resource is loaded.
|
void |
notifyChanged(org.eclipse.emf.common.notify.Notification notification)
Internal call-back to observe Resource addition to a ResourceSet..
|
protected ProjectManager.IProjectDescriptor |
registerBundle(java.io.File file,
javax.xml.parsers.SAXParser saxParser) |
protected ProjectManager.IProjectDescriptor |
registerProject(java.io.File file) |
void |
removeResourceDescriptor(ProjectManager.IResourceDescriptor resourceDescriptor)
Remove a resourceDescriptor so that an explicit create procedes without interference.
|
protected void |
scanClassPath(java.util.Map<java.lang.String,ProjectManager.IProjectDescriptor> projectDescriptors,
javax.xml.parsers.SAXParser saxParser) |
protected boolean |
scanFolder(java.io.File f,
javax.xml.parsers.SAXParser saxParser,
java.util.Set<java.lang.String> alreadyVisited,
int depth) |
void |
setTarget(org.eclipse.emf.common.notify.Notifier newTarget) |
java.lang.String |
toString() |
void |
unload(org.eclipse.emf.ecore.resource.ResourceSet resourceSet) |
void |
useGeneratedResource(org.eclipse.emf.ecore.resource.Resource resource,
org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Use a registered resource for use in conjunction with resourceSet.
|
@NonNull public static final TracingOption PROJECT_MAP_ADD_EPACKAGE
@NonNull public static final TracingOption PROJECT_MAP_ADD_GEN_MODEL
@NonNull public static final TracingOption PROJECT_MAP_ADD_GENERATED_PACKAGE
@NonNull public static final TracingOption PROJECT_MAP_ADD_URI_MAP
@NonNull public static final TracingOption PROJECT_MAP_CONFIGURE
@NonNull public static final TracingOption PROJECT_MAP_GET
@NonNull public static final TracingOption PROJECT_MAP_INSTALL
@NonNull public static final TracingOption PROJECT_MAP_RESOLVE
public static java.util.WeakHashMap<StandaloneProjectMap,java.lang.Object> liveStandaloneProjectMaps
protected final boolean isGlobal
protected boolean initializedPlatformResourceMap
@Nullable protected java.util.Map<org.eclipse.emf.common.util.URI,ProjectManager.IPackageDescriptor> nsURI2package
@Nullable protected java.util.Map<org.eclipse.emf.common.util.URI,ProjectManager.IResourceDescriptor> uri2resource
@Nullable public static StandaloneProjectMap findAdapter(@NonNull org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
@NonNull public static StandaloneProjectMap getAdapter(@NonNull org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
public static org.eclipse.emf.ecore.EPackage.Registry getPackageRegistry(@Nullable org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
EPackage.Registry.INSTANCE
if resourceSet is null.public static org.eclipse.emf.ecore.resource.Resource.Factory.Registry getResourceFactoryRegistry(@Nullable org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Resource.Factory.Registry.INSTANCE
if resourceSet is null.@NonNull public static org.eclipse.emf.ecore.resource.URIConverter getURIConverter(@Nullable org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
URIConverter.INSTANCE
if resourceSet is null.@NonNull public static java.util.Map<org.eclipse.emf.common.util.URI,org.eclipse.emf.common.util.URI> getURIMap(@Nullable org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
URIConverter.URI_MAP
if resourceSet is null.public static void initStatics()
public static void initializeURIResourceMap(@Nullable org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
public void addResourceDescriptor(@NonNull ProjectManager.IResourceDescriptor resourceDescriptor)
addResourceDescriptor
in interface ProjectManager
public void configure(@Nullable org.eclipse.emf.ecore.resource.ResourceSet resourceSet, @NonNull ProjectManager.IResourceLoadStrategy resourceLoadStrategy, @Nullable ProjectManager.IConflictHandler conflictHandler)
configure
in interface ProjectManager
@NonNull protected ProjectManager.IProjectDescriptor createProjectDescriptor(@NonNull java.lang.String projectName, @NonNull org.eclipse.emf.common.util.URI locationURI)
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
@Nullable public ProjectManager.IPackageDescriptor getPackageDescriptor(@NonNull org.eclipse.emf.common.util.URI nsURI)
getPackageDescriptor
in interface ProjectManager
@Nullable public ProjectManager.IProjectDescriptor getProjectDescriptor(@NonNull java.lang.String projectName)
@NonNull protected ProjectManager.IProjectDescriptor getProjectDescriptorInternal(@NonNull org.eclipse.emf.common.util.URI platformURI)
@Nullable public java.util.Map<java.lang.String,java.lang.Exception> getExceptionMap()
@Nullable public org.eclipse.emf.common.util.URI getLocation(@NonNull java.lang.String projectName)
@Nullable protected java.util.Map<java.lang.String,ProjectManager.IProjectDescriptor> getProjectDescriptors()
e.g. entries such as
org.antlr.runtime =>
archive:file:/C:/Tools/Eclipse/3.7.1/plugins/org.antlr
.runtime_3.2.0.v201101311130.jar!/
org.eclipse.ocl.domain =>
file:/C:/GIT/org.eclipse.ocl/pivot/org.eclipse.ocl.domain/
Any problems arising while creating the project map are gathered into the
exception map accessible using getExceptionMap()
. An overall
problem may be attributed to the null file.
@Nullable public java.util.Set<java.lang.String> getProjectNames()
@Nullable public ProjectManager.IResourceDescriptor getResourceDescriptor(@NonNull org.eclipse.emf.common.util.URI uri)
getResourceDescriptor
in interface ProjectManager
public org.eclipse.emf.common.notify.Notifier getTarget()
getTarget
in interface org.eclipse.emf.common.notify.Adapter
public void initializeGenModelLocationMap(boolean force)
EcorePlugin.getEPackageNsURIToGenModelLocationMap()
so that in a
standalone environment the locations of all genmodels are available.
Initialization is only necessary once and for a standalone environment. If force is true a re-initialization or plugin initialization may be forced.
public void initializePackageRegistry(@Nullable org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
public void initializePlatformResourceMap(boolean force)
EcorePlugin.getPlatformResourceMap()
so that in a standalone
environment and in conjunction with initializeURIMap(ResourceSet)
URIs such as
platform:/resource/project and
platform:/plugin/project are useable.
Initialization is only necessary once and for a standalone environment. If force is true a re-initialization or plugin initialization may be forced.
public void initializeResourceSet(@Nullable org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
EcorePlugin.getPlatformResourceMap()
and
ResourceSet.getURIConverter()
are initialized so that
platform:/resource/project and
platform:/plugin/project are useable..
A null ResourceSet may be used to provoke initialization of the global
EPackage.Registry.INSTANCE and URIConverter.URI_MAP.initializeResourceSet
in interface ProjectManager
public void initializeURIMap(@Nullable org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Note that in a plugin environment, a single platform:/resource/ to platform:/plugin/ mapping is sufficient since platform:/plugin/ is directly resolveable by the Eclipse Platform.
public boolean isAdapterForType(java.lang.Object type)
isAdapterForType
in interface org.eclipse.emf.common.notify.Adapter
public boolean isGlobal()
isGlobal
in interface ProjectManager
protected void logException(@NonNull java.lang.String message, @NonNull java.lang.Exception e)
public void notifyChanged(org.eclipse.emf.common.notify.Notification notification)
notifyChanged
in interface org.eclipse.emf.common.notify.Adapter
protected void notifyAddedDynamicResource(@NonNull org.eclipse.emf.ecore.resource.ResourceSet resourceSet, @NonNull org.eclipse.emf.ecore.resource.Resource resource)
@Nullable protected ProjectManager.IProjectDescriptor registerBundle(@NonNull java.io.File file, @NonNull javax.xml.parsers.SAXParser saxParser)
@Nullable protected ProjectManager.IProjectDescriptor registerProject(@NonNull java.io.File file)
public void removeResourceDescriptor(@NonNull ProjectManager.IResourceDescriptor resourceDescriptor)
removeResourceDescriptor
in interface ProjectManager
protected void scanClassPath(@NonNull java.util.Map<java.lang.String,ProjectManager.IProjectDescriptor> projectDescriptors, @NonNull javax.xml.parsers.SAXParser saxParser)
protected boolean scanFolder(@NonNull java.io.File f, @NonNull javax.xml.parsers.SAXParser saxParser, @NonNull java.util.Set<java.lang.String> alreadyVisited, int depth)
public void setTarget(org.eclipse.emf.common.notify.Notifier newTarget)
setTarget
in interface org.eclipse.emf.common.notify.Adapter
public java.lang.String toString()
toString
in class java.lang.Object
public void unload(@NonNull org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
unload
in interface ProjectManager
public void useGeneratedResource(@NonNull org.eclipse.emf.ecore.resource.Resource resource, @NonNull org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
useGeneratedResource
in interface ProjectManager