On Feb 4, 2012, at 7:00 AM, Sergiu Dumitriu wrote:
On 02/03/2012 06:32 AM, Vincent Massol 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
Is this java.lang.System?
No
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
What happens with ApplicationContextListener and ApplicationContextListenerManager?
Good point, I had missed those. I propose to deprecate them too. I don't think we need
replacements for them since we now haven events sent when the application is initialized.
We could add new events when we need them.
The other components in the container-api will remain
unchanged?
Yes.
Thanks
-Vincent