+0

Thanks,
Marius

On Fri, Feb 3, 2012 at 1:32 PM, Vincent Massol <[email protected]> wrote:
> Hi devs,
>
> Thomas and I have been brainstorming about the need to introduce a generic 
> notion of Environment in XWiki Commons. The idea is that there are some 
> modules that are currently in Platform that should/could be moved to Commons.
>
> To name just two:
> * Cache
> * Extension
>
> However these modules need a notion of Environment. They don't need the full 
> notion of Container that we have in Platform though (they don't need the 
> notion of request/response/session for example).
>
> So here's a proposal.
>
> * Introduce the following modules:
>
> xwiki-commons-environment
>  |_ xwiki-commons-environment-api
>  |_ xwiki-commons-environment-standard
>  |_ xwiki-commons-environment-servlet
>
> * With the following Java content:
>
> - in xwiki-commons-environment-api:
>
> Environment (Interface)
>  |_ getTemporaryDirectory() --> File
>  |_ getPermanentDirectory() --> File
>  |_ getResource() --> URL
>  |_ getResourceAsStream() --> InputStream
>
> - in xwiki-commons-environment-standard
>
> @Named("default")
> StandardEnvironment
>  |_ setResourceDirectory(File)
>  |_ setTemporaryDirectory(File)
>  |_ setPermanentDirectory(File)
>
> - in xwiki-commons-environment-servlet
>
> @Named("default")
> ServletEnvironment
>  |_ setTemporaryDirectory(File)
>  |_ setPermanentDirectory(File)
>
> Usage from other components:
>
> @Inject
> private Environment environment;
>
> * Usage in a standard environment (standard as in Java SE):
>
> ECM ecm = new ECM();
> ecm.initialize(getClass().getClassLoader());
> StandardEnvironment env = (StandardEnvironment) ecm.lookup(Environment.class);
> env.setPermanentDirectory(new File(…));
> …
>
> However to make it simpler to initialize XWiki in a standard environment we 
> will provide a System helper class in xwiki-commons-environment-standard:
>
> ECM ecm = System.initialize() <-- uses System classloader and sets tmp dir to 
> java.io.tmp.dir, no permanent dir set, no resource dir
> ECM ecm = System.initialize(File permanentDirectory) <-- uses System 
> classloader and sets tmp dir to java.io.tmp.dir, resource dir points to 
> permanent dir
> ECM ecm = System.initialize(File temporaryDirectory, File resourceDirectory) 
> <-- uses System classloader and sets tmp dir to java.io.tmp.dir
> ECM ecm = System.initialize(File temporaryDirectory, File resourceDirectory, 
> File temporaryDirectory) <-- uses System classloader
> ECM ecm = System.initialize(File temporaryDirectory, File resourceDirectory, 
> File temporaryDirectory, ClassLoader classLoader)
> ECM ecm = System.initialize(ClassLoader classLoader) <--  Sets tmp dir to 
> java.io.tmp.dir, no permanent dir set, no resource dir
>
> Note: in 99% of use cases the user just has to write the following to 
> initialize XWiki: ECM ecm = System.initialize();
>
> * Technical impl details:
> - getTemporaryDirectory default to java.io.tmpdir
> - getResource default to getPermanentDir
>
> * Relationship with Container:
> - We initialize the Environment component in the Container init classes 
> (DefaultServletContainerInitializer for Servlets)
> - We deprecate ApplicationContext. Code that's using ApplicationContext is 
> now asked to use the Environment component instead
>
> Here's my +1
>
> 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

Reply via email to