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
{
     /**
      * @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.

* Move *DocumentNameSerializer in Model module (currently in xwiki-core)
* Move *DocumentNameFactory in Model module (currently in xwiki-core)

Here's my +1

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
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to