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.cxfse;
018
019 import java.io.File;
020 import java.io.FileInputStream;
021 import java.io.IOException;
022 import java.io.InputStream;
023 import java.util.Properties;
024
025 public class CxfSeConfiguration {
026
027 public static final String CONFIG_FILE = "component.properties";
028
029 private String rootDir;
030 private String componentName = "servicemix-cxf-se";
031 private Properties properties = new Properties();
032 private String busCfg;
033
034 public boolean load() {
035 File f = null;
036 InputStream in = null;
037 if (rootDir != null) {
038 // try to find the property file in the workspace folder
039 f = new File(rootDir, CONFIG_FILE);
040 if (!f.exists()) {
041 f = null;
042 }
043 }
044 if (f == null) {
045 // find property file in classpath if it is not available in workspace
046 in = this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE);
047 if (in == null) {
048 return false;
049 }
050 }
051
052 try {
053 if (f != null) {
054 properties.load(new FileInputStream(f));
055 } else {
056 properties.load(in);
057 }
058 } catch (IOException e) {
059 throw new RuntimeException("Could not load component configuration", e);
060 }
061 if (properties.getProperty(componentName + ".busCfg") != null) {
062 setBusCfg(properties.getProperty(componentName + ".busCfg"));
063 }
064
065 return true;
066 }
067
068 /**
069 * @return Returns the rootDir.
070 * @org.apache.xbean.Property hidden="true"
071 */
072 public String getRootDir() {
073 return rootDir;
074 }
075
076 /**
077 * @param rootDir The rootDir to set.
078 */
079 public void setRootDir(String rootDir) {
080 this.rootDir = rootDir;
081 }
082
083 /**
084 * @return Returns the componentName.
085 * @org.apache.xbean.Property hidden="true"
086 */
087 public String getComponentName() {
088 return componentName;
089 }
090
091 /**
092 * @param componentName The componentName to set.
093 */
094 public void setComponentName(String componentName) {
095 this.componentName = componentName;
096 }
097
098 public void setBusCfg(String busCfg) {
099 this.busCfg = busCfg;
100 }
101
102 public String getBusCfg() {
103 return busCfg;
104 }
105
106 }