Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EMF Search---Developer Guide"
(→Ecore Query & Helper) |
m (→Introduction) |
||
(12 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
=== Introduction === | === Introduction === | ||
− | Developers have several levels/contexts/ | + | Developers have several levels/contexts/persistence configurations for which they want to use EMF Search. |
One aspect is which modeling level they want their extension to address : | One aspect is which modeling level they want their extension to address : | ||
Line 13: | Line 13: | ||
Another aspect is where and how their meta models are stored : | Another aspect is where and how their meta models are stored : | ||
− | * meta model | + | * meta model persistence layer type |
** Eclipse Resources | ** Eclipse Resources | ||
** Local File System | ** Local File System | ||
** WWW distant resources (Close to be supported) | ** WWW distant resources (Close to be supported) | ||
− | ** DB | + | ** DB persistence (Support planned) |
Line 23: | Line 23: | ||
=== Search Scope & Visitors === | === Search Scope & Visitors === | ||
+ | |||
+ | |||
+ | ==== Search Scope ==== | ||
Line 39: | Line 42: | ||
</source> | </source> | ||
− | + | These IModelSearchScope are populated with specialized visitors depending on the locations considered model resources are stored. | |
− | + | For the moment, main storages area are: | |
− | * | + | * Eclipse Workspace |
+ | **IWorkspaceRoot | ||
+ | **IProject[] | ||
+ | **IResource (IFile, IProject, ...) | ||
+ | **WorkingSet[] | ||
− | * | + | * File System |
+ | **File[] | ||
+ | **Dir[] | ||
+ | |||
+ | * WWW | ||
+ | **URL[] | ||
+ | |||
+ | * J2EE | ||
+ | **TBD | ||
+ | |||
+ | * DataBase storage | ||
+ | ** TBD | ||
+ | |||
+ | ==== Search Visitors ==== | ||
+ | |||
+ | Model Search Visitors are usually driven thanks factories | ||
+ | |||
+ | Usual naming convention for Scope factories : | ||
+ | |||
+ | <Prefix>ModelSearch<LocationType>ScopeFactory, <Prefix>ModelSearchScope<LocationType>Visitor | ||
+ | |||
+ | |||
+ | *File Sytems | ||
+ | **Ecore | ||
+ | ***EcoreModelSearchDirectoryScopeFactory | ||
+ | ***EcoreModelSearchFileSystemVisitor | ||
+ | **UML2 | ||
+ | ***UML2ModelSearchDirectoryScopeFactory | ||
+ | ***UML2ModelSearchFileSystemVisitor | ||
+ | *Custom | ||
+ | ***<Prefix>ModelSearchDirectoryScopeFactory | ||
+ | ***<Prefix>ModelSearchFileSystemVisitor | ||
+ | |||
+ | |||
+ | *HTTP | ||
+ | **Ecore | ||
+ | ***EcoreModelSearchHttpScopeFactory | ||
+ | ***EcoreModelSearchScopeHttpVisitor | ||
+ | **UML2 | ||
+ | ***UML2ModelSearchHttpScopeFactory | ||
+ | ***UML2ModelSearchScopeHttpVisitor | ||
+ | **Custom | ||
+ | ***<Prefix>ModelSearchHttpScopeFactory | ||
+ | ***<Prefix>ModelSearchScopeHttpVisitor | ||
+ | |||
+ | |||
+ | *Workspace (Special case : factory take engine as parameter) | ||
+ | **Ecore, UML2, Custom, ... | ||
+ | ***ModelSearchWorkspaceScopeFactory | ||
+ | ***ModelSearchScopeResourceVisitor | ||
=== Ecore Query & Helper === | === Ecore Query & Helper === | ||
Line 53: | Line 109: | ||
[[Image:EcoreTextualModelSearchQueryBuilderHelper.PNG|Ecore Textual Model Search Query Builder Helper]] | [[Image:EcoreTextualModelSearchQueryBuilderHelper.PNG|Ecore Textual Model Search Query Builder Helper]] | ||
+ | |||
+ | |||
+ | <source lang='java'> | ||
+ | |||
+ | // | ||
+ | // Non Case Sensitive Joker expression matching all text beginning with either 'a' or 'A' | ||
+ | // | ||
+ | private static final String ELEMENT_NAME_VALUATION_BEGINS_WITH_A = "A*"; | ||
+ | |||
+ | // | ||
+ | // In this case IModelSearchScope associated to | ||
+ | // "org.eclipse.emf.search.ecoreSearchEngine" search engine | ||
+ | // will collect any files with *.ecore extension from the current | ||
+ | // workspace. | ||
+ | // | ||
+ | IModelSearchScope scope = | ||
+ | ModelSearchWorkspaceScopeFactory.getInstance(). | ||
+ | createModelSearchWorkspaceScope( | ||
+ | "org.eclipse.emf.search.ecoreSearchEngine" | ||
+ | ); | ||
+ | |||
+ | // | ||
+ | // Creates a new query to apply on the whole workspace. | ||
+ | // This query will open any *.ecore collected in the | ||
+ | // IModelSearchScope built upper in the code | ||
+ | // | ||
+ | IModelSearchQuery query = | ||
+ | EcoreTextualModelSearchQueryBuilderHelper.getInstance(). | ||
+ | buildGlobalTextualModelSearchQuery( | ||
+ | ELEMENT_NAME_VALUATION_BEGINING_WITH_A, | ||
+ | scope, | ||
+ | EcorePackage.eNS_URI | ||
+ | ); | ||
+ | |||
+ | // | ||
+ | // Run the query with Eclise Search infrastructure in backgroud. | ||
+ | // Using a progress monitor allows to cancel this query if executed | ||
+ | // in Eclipse UI & having acces to Job view. | ||
+ | // | ||
+ | query.run(new NullProgressMonitor()); | ||
+ | |||
+ | ISearchResult result = query.getModelSearchResult(); | ||
+ | |||
+ | if (result instanceof IModelSearchResult) { | ||
+ | // | ||
+ | // Model result is a match occurences hierarchical tree mixing matches leaves and intermediate parent nodes | ||
+ | // In this case a vistor flatten leaves in a collection of match occurences | ||
+ | // | ||
+ | Collection<IModelResultEntry> resultEntries = ((IModelSearchResult)result).getResultsFlatenned(); | ||
+ | if (resultEntries.getSource() instanceof EObject) { | ||
+ | // | ||
+ | // User to process this occurence | ||
+ | // | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | |||
[[Image:EcoreTextualModelSearchQueryLauncherHelper.PNG|Ecore Textual Model Search Query Launcher Helper]] | [[Image:EcoreTextualModelSearchQueryLauncherHelper.PNG|Ecore Textual Model Search Query Launcher Helper]] | ||
+ | |||
+ | <source lang='java'> | ||
+ | |||
+ | |||
+ | // | ||
+ | // Non Case Sensitive Joker expression matching all text beginning with either 'a' or 'A' | ||
+ | // | ||
+ | private static final String ELEMENT_NAME_VALUATION_BEGINS_WITH_A = "A*"; | ||
+ | |||
+ | // | ||
+ | // In this case IModelSearchScope associated to | ||
+ | // "org.eclipse.emf.search.ecoreSearchEngine" search engine | ||
+ | // will collect any files with *.ecore extension from the current | ||
+ | // workspace. | ||
+ | // | ||
+ | IModelSearchScope scope = | ||
+ | ModelSearchWorkspaceScopeFactory.getInstance(). | ||
+ | createModelSearchWorkspaceScope( | ||
+ | "org.eclipse.emf.search.ecoreSearchEngine" | ||
+ | ); | ||
+ | |||
+ | // | ||
+ | // 1) | ||
+ | // | ||
+ | // Creates & launches a new query to apply on the whole workspace. | ||
+ | // This query will open any *.ecore collected in the | ||
+ | // IModelSearchScope built upper in the code. | ||
+ | // | ||
+ | // 2) | ||
+ | // | ||
+ | // Run the query with Eclise Search infrastructure in backgroud. | ||
+ | // Using a progress monitor allows to cancel this query if executed | ||
+ | // in Eclipse UI & having acces to Job view. | ||
+ | // | ||
+ | IModelSearchResult query = | ||
+ | EcoreTextualModelSearchQueryLauncheerHelper.getInstance(). | ||
+ | launchGlobalTextualModelSearchQuery( | ||
+ | ELEMENT_NAME_VALUATION_BEGINING_WITH_A, | ||
+ | scope, | ||
+ | EcorePackage.eNS_URI | ||
+ | ); | ||
+ | |||
+ | // | ||
+ | // | ||
+ | query.run(new NullProgressMonitor()); | ||
+ | |||
+ | ISearchResult result = query.getModelSearchResult(); | ||
+ | |||
+ | if (result instanceof IModelSearchResult) { | ||
+ | // | ||
+ | // Model result is a match occurences hierarchical tree mixing matches leaves and intermediate parent nodes | ||
+ | // In this case a vistor flatten leaves in a collection of match occurences | ||
+ | // | ||
+ | Collection<IModelResultEntry> resultEntries = ((IModelSearchResult)result).getResultsFlatenned(); | ||
+ | if (resultEntries.getSource() instanceof EObject) { | ||
+ | // | ||
+ | // User to process this occurence | ||
+ | // | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
=== Custom Queries & Helper === | === Custom Queries & Helper === |
Latest revision as of 06:04, 24 March 2009
Contents
Introduction
Developers have several levels/contexts/persistence configurations for which they want to use EMF Search.
One aspect is which modeling level they want their extension to address :
- meta modeling level
- Ecore meta-modeling (M3)
- UML2 meta-modeling or custom meta-models (M2)
- Model instance (M1)
Another aspect is where and how their meta models are stored :
- meta model persistence layer type
- Eclipse Resources
- Local File System
- WWW distant resources (Close to be supported)
- DB persistence (Support planned)
Depending on these particular situations, EMF Search typical usages exist.
Search Scope & Visitors
Search Scope
EMF Search defines a Scope API contract with IModelSearchScope :
public interface IModelSearchScope<P, O> { List<P> getParticipants(); void addParticipant(P resource); void addParticipants(P[] resources); void removeParticipant(P resource); void removeParticipants(P[] resources); List<P> findPartcipant(Class<O> clazz); String getLabel(); }
These IModelSearchScope are populated with specialized visitors depending on the locations considered model resources are stored.
For the moment, main storages area are:
- Eclipse Workspace
- IWorkspaceRoot
- IProject[]
- IResource (IFile, IProject, ...)
- WorkingSet[]
- File System
- File[]
- Dir[]
- WWW
- URL[]
- J2EE
- TBD
- DataBase storage
- TBD
Search Visitors
Model Search Visitors are usually driven thanks factories
Usual naming convention for Scope factories :
<Prefix>ModelSearch<LocationType>ScopeFactory, <Prefix>ModelSearchScope<LocationType>Visitor
- File Sytems
- Ecore
- EcoreModelSearchDirectoryScopeFactory
- EcoreModelSearchFileSystemVisitor
- UML2
- UML2ModelSearchDirectoryScopeFactory
- UML2ModelSearchFileSystemVisitor
- Ecore
- Custom
- <Prefix>ModelSearchDirectoryScopeFactory
- <Prefix>ModelSearchFileSystemVisitor
- HTTP
- Ecore
- EcoreModelSearchHttpScopeFactory
- EcoreModelSearchScopeHttpVisitor
- UML2
- UML2ModelSearchHttpScopeFactory
- UML2ModelSearchScopeHttpVisitor
- Custom
- <Prefix>ModelSearchHttpScopeFactory
- <Prefix>ModelSearchScopeHttpVisitor
- Ecore
- Workspace (Special case : factory take engine as parameter)
- Ecore, UML2, Custom, ...
- ModelSearchWorkspaceScopeFactory
- ModelSearchScopeResourceVisitor
- Ecore, UML2, Custom, ...
Ecore Query & Helper
Ecore EMF Search comes with several helpers for query building & launching :
// // Non Case Sensitive Joker expression matching all text beginning with either 'a' or 'A' // private static final String ELEMENT_NAME_VALUATION_BEGINS_WITH_A = "A*"; // // In this case IModelSearchScope associated to // "org.eclipse.emf.search.ecoreSearchEngine" search engine // will collect any files with *.ecore extension from the current // workspace. // IModelSearchScope scope = ModelSearchWorkspaceScopeFactory.getInstance(). createModelSearchWorkspaceScope( "org.eclipse.emf.search.ecoreSearchEngine" ); // // Creates a new query to apply on the whole workspace. // This query will open any *.ecore collected in the // IModelSearchScope built upper in the code // IModelSearchQuery query = EcoreTextualModelSearchQueryBuilderHelper.getInstance(). buildGlobalTextualModelSearchQuery( ELEMENT_NAME_VALUATION_BEGINING_WITH_A, scope, EcorePackage.eNS_URI ); // // Run the query with Eclise Search infrastructure in backgroud. // Using a progress monitor allows to cancel this query if executed // in Eclipse UI & having acces to Job view. // query.run(new NullProgressMonitor()); ISearchResult result = query.getModelSearchResult(); if (result instanceof IModelSearchResult) { // // Model result is a match occurences hierarchical tree mixing matches leaves and intermediate parent nodes // In this case a vistor flatten leaves in a collection of match occurences // Collection<IModelResultEntry> resultEntries = ((IModelSearchResult)result).getResultsFlatenned(); if (resultEntries.getSource() instanceof EObject) { // // User to process this occurence // } }
// // Non Case Sensitive Joker expression matching all text beginning with either 'a' or 'A' // private static final String ELEMENT_NAME_VALUATION_BEGINS_WITH_A = "A*"; // // In this case IModelSearchScope associated to // "org.eclipse.emf.search.ecoreSearchEngine" search engine // will collect any files with *.ecore extension from the current // workspace. // IModelSearchScope scope = ModelSearchWorkspaceScopeFactory.getInstance(). createModelSearchWorkspaceScope( "org.eclipse.emf.search.ecoreSearchEngine" ); // // 1) // // Creates & launches a new query to apply on the whole workspace. // This query will open any *.ecore collected in the // IModelSearchScope built upper in the code. // // 2) // // Run the query with Eclise Search infrastructure in backgroud. // Using a progress monitor allows to cancel this query if executed // in Eclipse UI & having acces to Job view. // IModelSearchResult query = EcoreTextualModelSearchQueryLauncheerHelper.getInstance(). launchGlobalTextualModelSearchQuery( ELEMENT_NAME_VALUATION_BEGINING_WITH_A, scope, EcorePackage.eNS_URI ); // // query.run(new NullProgressMonitor()); ISearchResult result = query.getModelSearchResult(); if (result instanceof IModelSearchResult) { // // Model result is a match occurences hierarchical tree mixing matches leaves and intermediate parent nodes // In this case a vistor flatten leaves in a collection of match occurences // Collection<IModelResultEntry> resultEntries = ((IModelSearchResult)result).getResultsFlatenned(); if (resultEntries.getSource() instanceof EObject) { // // User to process this occurence // } }