1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
package org.apache.commons.contract.store; |
21 | |
|
22 | |
import org.apache.commons.contract.Context; |
23 | |
import org.apache.commons.contract.Store; |
24 | |
import org.apache.commons.contract.StoreException; |
25 | |
import org.apache.commons.contract.constraints.CastException; |
26 | |
import org.apache.commons.contract.constraints.StringConstraints; |
27 | |
import org.apache.commons.i18n.bundles.ErrorBundle; |
28 | |
|
29 | 0 | public class Environment implements Store { |
30 | |
public final static String ID = "environment"; |
31 | |
|
32 | |
public void put(String key, Object value, Context context) throws StoreException { |
33 | |
try { |
34 | 0 | System.setProperty(key, (String)StringConstraints.UNCONSTRAINED.cast(value, context)); |
35 | 0 | } catch (CastException e) { |
36 | 0 | throw new StoreException(new ErrorBundle("storesStringsOnly"), e); |
37 | 0 | } |
38 | 0 | } |
39 | |
|
40 | |
public Object get(String key, Context context) throws StoreException { |
41 | 0 | return System.getProperty(key); |
42 | |
} |
43 | |
|
44 | |
public void dispose(String key, Context context) throws StoreException { |
45 | 0 | throw new StoreException(new ErrorBundle("disposeNotAvailable")); |
46 | |
} |
47 | |
|
48 | |
public String getId() { |
49 | 0 | return ID; |
50 | |
} |
51 | |
} |