On Mon, Dec 14, 2009 at 10:10, Vincent Massol <vincent(a)massol.net> wrote:
Hi,
Following on the model emails, I'd also like to do the following:
* Introduce a new Model component to access the Model objects from the
Execution Context (same as we do for other modules to prevent everyone
from directly accessing the EC). For now I have:
/**
* Allows accessing Model Objects for current objects (current
document, current wiki, current space, etc) placed in
* the Execution Context.
*
* @version $Id$
* @since 2.2M1
*/
@ComponentRole
public interface Model
Wouldn't ModelContext be more clear unless you plan to make Model
interface the entry point of the whole model to not get only
contextual informations.
{
/**
* @return the current document located in the Execution Context
or null if no current document exist
*/
DocumentName getCurrentDocumentName();
}
I'll also like to add getCurrentWikiName() and getCurrentSpaceName()
later on.
Why later for getCurrentWikiName() ? It's as important as the current
document I think.
* Move *DocumentNameSerializer in Model module (currently in xwiki-core)
* Move *DocumentNameFactory in Model module (currently in xwiki-core)
This will have to be in model sooner or latter so if you are already
able to move it now +1
Here's my +1
+1 for the general concept of component getting current model related
informations.
Thanks
-Vincent
PS: FYI here's how I have implemented Model for now:
/**
* Default implementation bridging to the old XWiki Context to get
current Model Objects.
*
* @version $Id$
* @since 2.2M1
*/
@Component
public class DefaultModel implements Model
{
/**
* The Execution Context from which we get the old XWiki Context
from which we get the current Model Objects.
*/
@Requirement
private Execution execution;
/**
* {@inheritDoc}
* @see org.xwiki.model.Model#getCurrentDocumentName()
*/
public DocumentName getCurrentDocumentName()
{
DocumentName result = null;
// TODO: This is bridge to the old XWiki Context since we
currently don't store the current document in the
// new Execution Context yet. Remove when we do so.
try {
Map<Object, Object> xcontext =
(Map<Object, Object>)
this.execution.getContext().getProperty("xwikicontext");
Object currentDocument = xcontext.get("doc");
result = (DocumentName)
currentDocument
.getClass().getMethod("getDocumentName").invoke(currentDocument);
} catch (Exception e) {
// Shouldn't happen in normal cases. Could happen if the
context doesn't contain the old XWiki Context
// but that would be a bug in the initialization system
somewhere.
}
return result;
}
}
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs
--
Thomas Mortagne