KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > common > PersistentConfiguration


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.common;
18
19 import java.io.File JavaDoc;
20 import java.io.FileInputStream JavaDoc;
21 import java.io.FileOutputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 /**
26  * Base class for component configuration.
27  * Due to classloading mechanism in JBI, Shared Libraries are
28  * not available at bootstrap time, so this class should be
29  * copied in your own component and modified directly, instead
30  * of inheriting it. This only apply if the bootstrap uses the
31  * configuration.
32  *
33  * @author Guillaume Nodet
34  * @deprecated
35  * @since 3.0
36  */

37 public class PersistentConfiguration {
38     
39     public final static String JavaDoc CONFIG_FILE = "component.properties";
40     
41     protected String JavaDoc rootDir;
42     protected Properties JavaDoc properties;
43     
44     public PersistentConfiguration() {
45         properties = new Properties JavaDoc();
46     }
47     
48     public boolean load() {
49         if (rootDir == null) {
50             return false;
51         }
52         File JavaDoc f = new File JavaDoc(rootDir, CONFIG_FILE);
53         if (!f.exists()) {
54             return false;
55         }
56         try {
57             properties.load(new FileInputStream JavaDoc(f));
58             return true;
59         } catch (IOException JavaDoc e) {
60             throw new RuntimeException JavaDoc("Could not load component configuration", e);
61         }
62     }
63     
64     public void save() {
65         if (rootDir != null) {
66             File JavaDoc f = new File JavaDoc(rootDir, CONFIG_FILE);
67             try {
68                 this.properties.store(new FileOutputStream JavaDoc(f), null);
69             } catch (Exception JavaDoc e) {
70                 throw new RuntimeException JavaDoc("Could not store component configuration", e);
71             }
72         }
73     }
74
75     /**
76      * @return Returns the rootDir.
77      */

78     public String JavaDoc getRootDir() {
79         return rootDir;
80     }
81
82     /**
83      * @param rootDir The rootDir to set.
84      */

85     public void setRootDir(String JavaDoc rootDir) {
86         this.rootDir = rootDir;
87     }
88
89 }
90
Popular Tags