KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > core > system > JVMParameterProvider


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created
14  * @author
15  */

16 package org.pentaho.core.system;
17
18 import java.math.BigDecimal JavaDoc;
19 import java.util.Date JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Properties JavaDoc;
22
23 import org.pentaho.core.solution.IParameterProvider;
24 import org.pentaho.util.ParameterHelper;
25
26 public class JVMParameterProvider implements IParameterProvider {
27
28   public String JavaDoc getStringParameter(String JavaDoc name, String JavaDoc defaultValue) {
29     return System.getProperty(name, defaultValue);
30   }
31
32   public long getLongParameter(String JavaDoc name, long defaultValue) {
33     String JavaDoc pValue = this.getStringParameter(name, null);
34     if (pValue == null) {
35       return defaultValue;
36     } else {
37       try {
38         return Long.parseLong(pValue);
39       } catch (Exception JavaDoc ex) {
40         return defaultValue;
41       }
42     }
43   }
44
45   public Date JavaDoc getDateParameter(String JavaDoc name, Date JavaDoc defaultValue) {
46     return ParameterHelper.parameterToDate(getStringParameter(name, null), defaultValue);
47   }
48
49   public Object JavaDoc getDecimalParameter(String JavaDoc name, Object JavaDoc defaultValue) {
50     String JavaDoc pValue = this.getStringParameter(name, null);
51     if (pValue == null) {
52       return defaultValue;
53     } else {
54       try {
55         return new BigDecimal JavaDoc(pValue);
56       } catch (Exception JavaDoc ex) {
57         return defaultValue;
58       }
59     }
60   }
61
62   public Iterator JavaDoc getParameterNames() {
63     Properties JavaDoc props = System.getProperties();
64     return props.keySet().iterator();
65   }
66
67   public String JavaDoc getParameterType(String JavaDoc name) {
68     return "string"; //$NON-NLS-1$
69
}
70
71   public Object JavaDoc getParameter(String JavaDoc name) {
72     return System.getProperty(name);
73   }
74
75 }
76
77
78
Popular Tags