001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.common;
018
019 import java.io.File;
020 import java.io.FileInputStream;
021 import java.io.FileOutputStream;
022 import java.io.IOException;
023 import java.util.Properties;
024
025 /**
026 * Base class for component configuration.
027 * Due to classloading mechanism in JBI, Shared Libraries are
028 * not available at bootstrap time, so this class should be
029 * copied in your own component and modified directly, instead
030 * of inheriting it. This only apply if the bootstrap uses the
031 * configuration.
032 *
033 * @author Guillaume Nodet
034 * @deprecated
035 * @since 3.0
036 */
037 public class PersistentConfiguration {
038
039 public final static String CONFIG_FILE = "component.properties";
040
041 protected String rootDir;
042 protected Properties properties;
043
044 public PersistentConfiguration() {
045 properties = new Properties();
046 }
047
048 public boolean load() {
049 if (rootDir == null) {
050 return false;
051 }
052 File f = new File(rootDir, CONFIG_FILE);
053 if (!f.exists()) {
054 return false;
055 }
056 try {
057 properties.load(new FileInputStream(f));
058 return true;
059 } catch (IOException e) {
060 throw new RuntimeException("Could not load component configuration", e);
061 }
062 }
063
064 public void save() {
065 if (rootDir != null) {
066 File f = new File(rootDir, CONFIG_FILE);
067 try {
068 this.properties.store(new FileOutputStream(f), null);
069 } catch (Exception e) {
070 throw new RuntimeException("Could not store component configuration", e);
071 }
072 }
073 }
074
075 /**
076 * @return Returns the rootDir.
077 */
078 public String getRootDir() {
079 return rootDir;
080 }
081
082 /**
083 * @param rootDir The rootDir to set.
084 */
085 public void setRootDir(String rootDir) {
086 this.rootDir = rootDir;
087 }
088
089 }