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.component;
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 ClusteredBpmScriptConfiguration implements
026: ClusteredBpmScriptConfigurationMBean {
027:
028: public final static String CONFIG_FILE = "component.properties";
029:
030: private String rootDir;
031:
032: private String jmsUrl = "tcp://localhost:61616";
033:
034: private String dataSourceDriverClassName = "org.apache.derby.jdbc.EmbeddedDriver";
035:
036: private String dataSourceUrl = "jdbc:derby:bpmscript;create=true";
037:
038: private String dataSourceUsername = "";
039:
040: private String dataSourcePassword = "";
041:
042: private String hibernateDialect = "org.hibernate.dialect.DerbyDialect";
043:
044: private String processExecutorLibraries = "classpath:/org/bpmscript/jbi/component/bpmscriptlibrary.js";
045:
046: private Properties properties = new Properties();
047:
048: public void save() {
049: properties.setProperty("jmsUrl", jmsUrl);
050: properties.setProperty("dataSourceDriverClassName",
051: dataSourceDriverClassName);
052: properties.setProperty("dataSourceUrl", dataSourceUrl);
053: properties
054: .setProperty("dataSourceUsername", dataSourceUsername);
055: properties
056: .setProperty("dataSourcePassword", dataSourcePassword);
057: properties.setProperty("hibernateDialect", hibernateDialect);
058: properties.setProperty("processExecutorLibraries",
059: processExecutorLibraries);
060:
061: if (rootDir != null) {
062: File f = new File(rootDir, CONFIG_FILE);
063: try {
064: this .properties.store(new FileOutputStream(f), null);
065: } catch (Exception e) {
066: throw new RuntimeException(
067: "Could not store component configuration", e);
068: }
069: }
070: }
071:
072: public boolean load() {
073: if (rootDir == null) {
074: return false;
075: }
076: File f = new File(rootDir, CONFIG_FILE);
077: if (!f.exists()) {
078: return false;
079: }
080: try {
081: properties.load(new FileInputStream(f));
082: } catch (IOException e) {
083: throw new RuntimeException(
084: "Could not load component configuration", e);
085: }
086: if (properties.getProperty("jmsUrl") != null) {
087: jmsUrl = properties.getProperty("jmsUrl");
088: }
089: if (properties.getProperty("dataSourceDriverClassName") != null) {
090: dataSourceDriverClassName = properties
091: .getProperty("dataSourceDriverClassName");
092: }
093: if (properties.getProperty("dataSourceUrl") != null) {
094: dataSourceUrl = properties.getProperty("dataSourceUrl");
095: }
096: if (properties.getProperty("dataSourceUsername") != null) {
097: dataSourceUsername = properties
098: .getProperty("dataSourceUsername");
099: }
100: if (properties.getProperty("dataSourcePassword") != null) {
101: dataSourcePassword = properties
102: .getProperty("dataSourcePassword");
103: }
104: if (properties.getProperty("hibernateDialect") != null) {
105: hibernateDialect = properties
106: .getProperty("hibernateDialect");
107: }
108: if (properties.getProperty("processExecutorLibraries") != null) {
109: processExecutorLibraries = properties
110: .getProperty("processExecutorLibraries");
111: }
112: return true;
113: }
114:
115: public void setRootDir(String rootDir) {
116: this .rootDir = rootDir;
117: }
118:
119: /*
120: * (non-Javadoc)
121: *
122: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#getDataSourceDriverClassName()
123: */
124: /*
125: * (non-Javadoc)
126: *
127: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#getDataSourceDriverClassName()
128: */
129: public String getDataSourceDriverClassName() {
130: return dataSourceDriverClassName;
131: }
132:
133: /*
134: * (non-Javadoc)
135: *
136: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#setDataSourceDriverClassName(java.lang.String)
137: */
138: public void setDataSourceDriverClassName(
139: String dataSourceDriverClassName) {
140: this .dataSourceDriverClassName = dataSourceDriverClassName;
141: }
142:
143: /*
144: * (non-Javadoc)
145: *
146: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#getDataSourceUrl()
147: */
148: /*
149: * (non-Javadoc)
150: *
151: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#getDataSourceUrl()
152: */
153: public String getDataSourceUrl() {
154: return dataSourceUrl;
155: }
156:
157: /*
158: * (non-Javadoc)
159: *
160: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#setDataSourceUrl(java.lang.String)
161: */
162: public void setDataSourceUrl(String dataSourceUrl) {
163: this .dataSourceUrl = dataSourceUrl;
164: }
165:
166: /*
167: * (non-Javadoc)
168: *
169: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#getJmsUrl()
170: */
171: /*
172: * (non-Javadoc)
173: *
174: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#getJmsUrl()
175: */
176: public String getJmsUrl() {
177: return jmsUrl;
178: }
179:
180: /*
181: * (non-Javadoc)
182: *
183: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#setJmsUrl(java.lang.String)
184: */
185: public void setJmsUrl(String jmsUrl) {
186: this .jmsUrl = jmsUrl;
187: }
188:
189: /*
190: * (non-Javadoc)
191: *
192: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#getProcessExecutorLibraries()
193: */
194: /*
195: * (non-Javadoc)
196: *
197: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#getProcessExecutorLibraries()
198: */
199: public String getProcessExecutorLibraries() {
200: return processExecutorLibraries;
201: }
202:
203: /*
204: * (non-Javadoc)
205: *
206: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#setProcessExecutorLibraries(java.lang.String)
207: */
208: public void setProcessExecutorLibraries(
209: String processExecutorLibraries) {
210: this .processExecutorLibraries = processExecutorLibraries;
211: }
212:
213: /*
214: * (non-Javadoc)
215: *
216: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#getHibernateDialect()
217: */
218: public String getHibernateDialect() {
219: return hibernateDialect;
220: }
221:
222: /*
223: * (non-Javadoc)
224: *
225: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#setHibernateDialect(java.lang.String)
226: */
227: public void setHibernateDialect(String hibernateDialect) {
228: this .hibernateDialect = hibernateDialect;
229: }
230:
231: /*
232: * (non-Javadoc)
233: *
234: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#getDataSourcePassword()
235: */
236: public String getDataSourcePassword() {
237: return dataSourcePassword;
238: }
239:
240: /*
241: * (non-Javadoc)
242: *
243: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#setDataSourcePassword(java.lang.String)
244: */
245: public void setDataSourcePassword(String dataSourcePassword) {
246: this .dataSourcePassword = dataSourcePassword;
247: }
248:
249: /*
250: * (non-Javadoc)
251: *
252: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#getDataSourceUsername()
253: */
254: public String getDataSourceUsername() {
255: return dataSourceUsername;
256: }
257:
258: /*
259: * (non-Javadoc)
260: *
261: * @see org.bpmscript.jbi.component.ClusteredBpmScriptConfigurationMBean#setDataSourceUsername(java.lang.String)
262: */
263: public void setDataSourceUsername(String dataSourceUsername) {
264: this .dataSourceUsername = dataSourceUsername;
265: }
266:
267: public String getRootDir() {
268: return rootDir;
269: }
270:
271: }
|