[xwiki-devs] [Proposal][Model] ModelContext & getCurrentEntity()
Hi devs, I'm still working on the Model Reference domain. We've brainstormed with Thomas and we'd like to propose replacing the current ModelContext.getCurrentDocumentName() by ModelContext.getCurrentEntityReference() (which returns an EntityReference). The idea is that a URL could target a document but also a wiki only (e.g the REST API odes that), or a given space only, or even an object or a property. This would mean we would need to have getCurrentDocumentReference() in addition to all the others: getCurrentWikiReference(), getCurrentSpaceReference(). It would also mean a lot of them would be set to null. Last it would mean different ways to access the same information (e.g. getCurrentDocumentReference.getWikiReference() vs getCurrentWikiReference()). We would also add a EntityReference.extractReference(EntityType type) method in order to make it easy to extract information from the a reference path. For example to extract the Wiki from an entity reference: WikiReference wikiRef = context.getCurrentEntityReference(EntityType.WIKI); if (wikiRef != null) .... WDYT? Thanks -Vincent
+1 On Mon, Dec 21, 2009 at 10:29, Vincent Massol <[email protected]> wrote:
Hi devs,
I'm still working on the Model Reference domain. We've brainstormed with Thomas and we'd like to propose replacing the current ModelContext.getCurrentDocumentName() by ModelContext.getCurrentEntityReference() (which returns an EntityReference).
The idea is that a URL could target a document but also a wiki only (e.g the REST API odes that), or a given space only, or even an object or a property. This would mean we would need to have getCurrentDocumentReference() in addition to all the others: getCurrentWikiReference(), getCurrentSpaceReference(). It would also mean a lot of them would be set to null. Last it would mean different ways to access the same information (e.g. getCurrentDocumentReference.getWikiReference() vs getCurrentWikiReference()).
We would also add a EntityReference.extractReference(EntityType type) method in order to make it easy to extract information from the a reference path.
For example to extract the Wiki from an entity reference:
WikiReference wikiRef = context.getCurrentEntityReference(EntityType.WIKI); if (wikiRef != null) ....
WDYT?
Thanks -Vincent _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
On Mon, Dec 21, 2009 at 10:29, Vincent Massol <[email protected]> wrote:
Hi devs,
I'm still working on the Model Reference domain. We've brainstormed with Thomas and we'd like to propose replacing the current ModelContext.getCurrentDocumentName() by ModelContext.getCurrentEntityReference() (which returns an EntityReference).
The idea is that a URL could target a document but also a wiki only (e.g the REST API odes that), or a given space only, or even an object or a property. This would mean we would need to have getCurrentDocumentReference() in addition to all the others: getCurrentWikiReference(), getCurrentSpaceReference(). It would also mean a lot of them would be set to null. Last it would mean different ways to access the same information (e.g. getCurrentDocumentReference.getWikiReference() vs getCurrentWikiReference()).
Note that another point was that we need to make sure the current space is consistent with the current wiki.
We would also add a EntityReference.extractReference(EntityType type) method in order to make it easy to extract information from the a reference path.
For example to extract the Wiki from an entity reference:
WikiReference wikiRef = context.getCurrentEntityReference(EntityType.WIKI); if (wikiRef != null) ....
WDYT?
Thanks -Vincent _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
+1 On 12/21/09 10:29 AM, Vincent Massol wrote:
Hi devs,
I'm still working on the Model Reference domain. We've brainstormed with Thomas and we'd like to propose replacing the current ModelContext.getCurrentDocumentName() by ModelContext.getCurrentEntityReference() (which returns an EntityReference).
The idea is that a URL could target a document but also a wiki only (e.g the REST API odes that), or a given space only, or even an object or a property. This would mean we would need to have getCurrentDocumentReference() in addition to all the others: getCurrentWikiReference(), getCurrentSpaceReference(). It would also mean a lot of them would be set to null. Last it would mean different ways to access the same information (e.g. getCurrentDocumentReference.getWikiReference() vs getCurrentWikiReference()).
We would also add a EntityReference.extractReference(EntityType type) method in order to make it easy to extract information from the a reference path.
For example to extract the Wiki from an entity reference:
WikiReference wikiRef = context.getCurrentEntityReference(EntityType.WIKI); if (wikiRef != null) ....
WDYT?
Thanks -Vincent _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On Mon, Dec 21, 2009 at 2:59 PM, Vincent Massol <[email protected]> wrote:
Hi devs,
I'm still working on the Model Reference domain. We've brainstormed with Thomas and we'd like to propose replacing the current ModelContext.getCurrentDocumentName() by ModelContext.getCurrentEntityReference() (which returns an EntityReference).
The idea is that a URL could target a document but also a wiki only (e.g the REST API odes that), or a given space only, or even an object or a property. This would mean we would need to have getCurrentDocumentReference() in addition to all the others: getCurrentWikiReference(), getCurrentSpaceReference(). It would also mean a lot of them would be set to null. Last it would mean different ways to access the same information (e.g. getCurrentDocumentReference.getWikiReference() vs getCurrentWikiReference()).
We would also add a EntityReference.extractReference(EntityType type) method in order to make it easy to extract information from the a reference path.
For example to extract the Wiki from an entity reference:
WikiReference wikiRef = context.getCurrentEntityReference(EntityType.WIKI); if (wikiRef != null) ....
+1 May be we can avoid the enum type by using generics? <T extends EntityReference> T getCurrentEntityReference(); Not sure if this is a good practice though. - Asiri
WDYT?
Thanks -Vincent _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On Mon, Dec 21, 2009 at 18:10, Asiri Rathnayake <[email protected]> wrote:
On Mon, Dec 21, 2009 at 2:59 PM, Vincent Massol <[email protected]> wrote:
Hi devs,
I'm still working on the Model Reference domain. We've brainstormed with Thomas and we'd like to propose replacing the current ModelContext.getCurrentDocumentName() by ModelContext.getCurrentEntityReference() (which returns an EntityReference).
The idea is that a URL could target a document but also a wiki only (e.g the REST API odes that), or a given space only, or even an object or a property. This would mean we would need to have getCurrentDocumentReference() in addition to all the others: getCurrentWikiReference(), getCurrentSpaceReference(). It would also mean a lot of them would be set to null. Last it would mean different ways to access the same information (e.g. getCurrentDocumentReference.getWikiReference() vs getCurrentWikiReference()).
We would also add a EntityReference.extractReference(EntityType type) method in order to make it easy to extract information from the a reference path.
For example to extract the Wiki from an entity reference:
WikiReference wikiRef = context.getCurrentEntityReference(EntityType.WIKI); if (wikiRef != null) ....
+1
May be we can avoid the enum type by using generics?
<T extends EntityReference> T getCurrentEntityReference();
Not sure if this is a good practice though.
Generic does not exist in the bytecode so impossible to know that you want the EntityType.WIKI if you don't explicitly ask for it.
- Asiri
WDYT?
Thanks -Vincent _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
Hi Thomas,
May be we can avoid the enum type by using generics?
<T extends EntityReference> T getCurrentEntityReference();
Not sure if this is a good practice though.
Generic does not exist in the bytecode so impossible to know that you want the EntityType.WIKI if you don't explicitly ask for it.
Right. Inside the method we'd have no clue what the client code is requesting. Would be cool if we can somehow not depend on the EntityReference implementation type within the getCurrentEntityReference() method (thereby not having to know which type the user wants but just cast and return what is available). But I don't know if this is possible, and this would still mean having to do an unsafe cast like: EntityReference ref = ....; return (T) ref; which is also not that good. Thanks. - Asiri
- Asiri
WDYT?
Thanks -Vincent _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On 12/21/2009 07:31 PM, Asiri Rathnayake wrote:
Hi Thomas,
May be we can avoid the enum type by using generics?
<T extends EntityReference> T getCurrentEntityReference();
Not sure if this is a good practice though.
Generic does not exist in the bytecode so impossible to know that you want the EntityType.WIKI if you don't explicitly ask for it.
Right. Inside the method we'd have no clue what the client code is requesting.
Would be cool if we can somehow not depend on the EntityReference implementation type within the getCurrentEntityReference() method (thereby not having to know which type the user wants but just cast and return what is available). But I don't know if this is possible, and this would still mean having to do an unsafe cast like:
EntityReference ref = ....;
return (T) ref;
which is also not that good.
private Map<Class<T>, T> currentReferences populated at the start of the request; public <T extends EntityReference> T getCurrentEntityReference(Class<T> clazz) { return currentReferences.get(clazz); } Could this work? -- Sergiu Dumitriu http://purl.org/net/sergiu/
participants (5)
-
Asiri Rathnayake -
Jerome Velociter -
Sergiu Dumitriu -
Thomas Mortagne -
Vincent Massol