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.bpmscript.jbi.tasklist;
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: public class TaskListConfiguration implements
026: TaskListConfigurationMBean {
027:
028: public final static String CONFIG_FILE = "component.properties";
029:
030: private String rootDir;
031:
032: private String dataSourceDriverClassName = "org.apache.derby.jdbc.EmbeddedDriver";
033:
034: private String dataSourceUrl = "jdbc:derby:bpmscript;create=true";
035:
036: private String dataSourceUsername = null;
037:
038: private String dataSourcePassword = null;
039:
040: private String hibernateDialect = "org.hibernate.dialect.DerbyDialect";
041:
042: private Properties properties = new Properties();
043:
044: public String getDataSourceDriverClassName() {
045: return dataSourceDriverClassName;
046: }
047:
048: public void setDataSourceDriverClassName(
049: String dataSourceDriverClassName) {
050: this .dataSourceDriverClassName = dataSourceDriverClassName;
051: }
052:
053: public String getDataSourcePassword() {
054: return dataSourcePassword;
055: }
056:
057: public void setDataSourcePassword(String dataSourcePassword) {
058: this .dataSourcePassword = dataSourcePassword;
059: }
060:
061: public String getDataSourceUrl() {
062: return dataSourceUrl;
063: }
064:
065: public void setDataSourceUrl(String dataSourceUrl) {
066: this .dataSourceUrl = dataSourceUrl;
067: }
068:
069: public String getDataSourceUsername() {
070: return dataSourceUsername;
071: }
072:
073: public void setDataSourceUsername(String dataSourceUsername) {
074: this .dataSourceUsername = dataSourceUsername;
075: }
076:
077: public String getHibernateDialect() {
078: return hibernateDialect;
079: }
080:
081: public void setHibernateDialect(String hibernateDialect) {
082: this .hibernateDialect = hibernateDialect;
083: }
084:
085: public String getRootDir() {
086: return rootDir;
087: }
088:
089: public void setRootDir(String rootDir) {
090: this .rootDir = rootDir;
091: }
092:
093: public void save() {
094: properties.setProperty("dataSourceDriverClassName",
095: dataSourceDriverClassName);
096: properties.setProperty("dataSourceUrl", dataSourceUrl);
097: properties
098: .setProperty("dataSourceUsername", dataSourceUsername);
099: properties
100: .setProperty("dataSourcePassword", dataSourcePassword);
101: properties.setProperty("hibernateDialect", hibernateDialect);
102:
103: if (rootDir != null) {
104: File f = new File(rootDir, CONFIG_FILE);
105: try {
106: this .properties.store(new FileOutputStream(f), null);
107: } catch (Exception e) {
108: throw new RuntimeException(
109: "Could not store component configuration", e);
110: }
111: }
112: }
113:
114: public boolean load() {
115: if (rootDir == null) {
116: return false;
117: }
118: File f = new File(rootDir, CONFIG_FILE);
119: if (!f.exists()) {
120: return false;
121: }
122: try {
123: properties.load(new FileInputStream(f));
124: } catch (IOException e) {
125: throw new RuntimeException(
126: "Could not load component configuration", e);
127: }
128: if (properties.getProperty("dataSourceDriverClassName") != null) {
129: dataSourceDriverClassName = properties
130: .getProperty("dataSourceDriverClassName");
131: }
132: if (properties.getProperty("dataSourceUrl") != null) {
133: dataSourceUrl = properties.getProperty("dataSourceUrl");
134: }
135: if (properties.getProperty("dataSourceUsername") != null) {
136: dataSourceUsername = properties
137: .getProperty("dataSourceUsername");
138: }
139: if (properties.getProperty("dataSourcePassword") != null) {
140: dataSourcePassword = properties
141: .getProperty("dataSourcePassword");
142: }
143: if (properties.getProperty("hibernateDialect") != null) {
144: hibernateDialect = properties
145: .getProperty("hibernateDialect");
146: }
147: return true;
148: }
149: }
|