public class StandaloneProjectMap extends 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 |
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.
|
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 |
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 |
---|---|
static WeakHashMap<StandaloneProjectMap,Object> |
liveStandaloneProjectMaps
Leak debugging aid.
|
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 |
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(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.
|
static StandaloneProjectMap |
findAdapter(ResourceSet resourceSet)
Return any StandaloneProjectMap already installed as an adapter on a
resourceSet.
|
static StandaloneProjectMap |
getAdapter(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.
|
Map<String,Exception> |
getExceptionMap()
Return the mapping of problem files to exceptions, or null if not yet
computed or if no exceptions thrown.
|
URI |
getLocation(String projectName)
Return the resolveable URI for a given project or bundle name.
|
ProjectManager.IPackageDescriptor |
getPackageDescriptor(URI nsURI)
Return the IPackageDescriptor for a given nsURI.
|
static EPackage.Registry |
getPackageRegistry(ResourceSet resourceSet)
Return the EPackage.Registry for a resourceSet or the Global
EPackage.Registry if resourceSet is null. |
ProjectManager.IProjectDescriptor |
getProjectDescriptor(String projectName)
Return the IProjectDescriptor for a given project or bundle name.
|
Set<String> |
getProjectNames()
Return the names of all the projects/bundles.
|
ProjectManager.IResourceDescriptor |
getResourceDescriptor(URI uri)
Return the IResourceDescriptor for a given URI.
|
static Resource.Factory.Registry |
getResourceFactoryRegistry(ResourceSet resourceSet)
Return the Resource.Factory.Registry for a resourceSet or the Global
Resource.Factory.Registry if resourceSet is null. |
Notifier |
getTarget() |
static URIConverter |
getURIConverter(ResourceSet resourceSet)
Return the URIConverter for a resourceSet or the Global
URIConverter#INSTANCE if resourceSet is null. |
static Map<URI,URI> |
getURIMap(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(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(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(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(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(Object type) |
boolean |
isGlobal() |
void |
notifyChanged(Notification notification)
Internal call-back to observe Resource addition to a ResourceSet..
|
void |
removeResourceDescriptor(ProjectManager.IResourceDescriptor resourceDescriptor)
Remove a resourceDescriptor so that an explicit create precedes without interference.
|
void |
setTarget(Notifier newTarget) |
String |
toString() |
void |
unload(ResourceSet resourceSet) |
void |
useGeneratedResource(Resource resource,
ResourceSet resourceSet)
Use a registered resource for use in conjunction with resourceSet.
|
public static final TracingOption PROJECT_MAP_ADD_EPACKAGE
public static final TracingOption PROJECT_MAP_ADD_GEN_MODEL
public static final TracingOption PROJECT_MAP_ADD_GENERATED_PACKAGE
public static final TracingOption PROJECT_MAP_ADD_URI_MAP
public static final TracingOption PROJECT_MAP_CONFIGURE
public static final TracingOption PROJECT_MAP_GET
public static final TracingOption PROJECT_MAP_INSTALL
public static final TracingOption PROJECT_MAP_RESOLVE
public static WeakHashMap<StandaloneProjectMap,Object> liveStandaloneProjectMaps
public static StandaloneProjectMap findAdapter(ResourceSet resourceSet)
public static StandaloneProjectMap getAdapter(ResourceSet resourceSet)
public static EPackage.Registry getPackageRegistry(ResourceSet resourceSet)
EPackage.Registry
if resourceSet is null.public static Resource.Factory.Registry getResourceFactoryRegistry(ResourceSet resourceSet)
Resource.Factory.Registry
if resourceSet is null.public static URIConverter getURIConverter(ResourceSet resourceSet)
URIConverter#INSTANCE
if resourceSet is null.public static Map<URI,URI> getURIMap(ResourceSet resourceSet)
URIConverter#URI_MAP
if resourceSet is null.public static void initStatics()
public static void initializeURIResourceMap(ResourceSet resourceSet)
public void addResourceDescriptor(ProjectManager.IResourceDescriptor resourceDescriptor)
addResourceDescriptor
in interface ProjectManager
public void configure(ResourceSet resourceSet, ProjectManager.IResourceLoadStrategy resourceLoadStrategy, ProjectManager.IConflictHandler conflictHandler)
configure
in interface ProjectManager
public ProjectManager.IPackageDescriptor getPackageDescriptor(URI nsURI)
getPackageDescriptor
in interface ProjectManager
public ProjectManager.IProjectDescriptor getProjectDescriptor(String projectName)
public Map<String,Exception> getExceptionMap()
public URI getLocation(String projectName)
public ProjectManager.IResourceDescriptor getResourceDescriptor(URI uri)
getResourceDescriptor
in interface ProjectManager
public Notifier getTarget()
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(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(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(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(Object type)
public boolean isGlobal()
isGlobal
in interface ProjectManager
public void notifyChanged(Notification notification)
public void removeResourceDescriptor(ProjectManager.IResourceDescriptor resourceDescriptor)
removeResourceDescriptor
in interface ProjectManager
public void setTarget(Notifier newTarget)
public void unload(ResourceSet resourceSet)
unload
in interface ProjectManager
public void useGeneratedResource(Resource resource, ResourceSet resourceSet)
useGeneratedResource
in interface ProjectManager
Copyright © 2005, 2018 IBM Corporation and others. All Rights Reserved.