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.cxfbc;
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    import org.apache.servicemix.jbi.security.auth.AuthenticationService;
026    
027    public class CxfBcConfiguration {
028    
029        public static final String CONFIG_FILE = "component.properties"; 
030        
031        private String rootDir;
032        private String componentName = "servicemix-cxf-bc";
033        private Properties properties = new Properties();
034        private String busCfg;
035        private transient AuthenticationService authenticationService;
036        
037        
038        /**
039         * The JNDI name of the AuthenticationService object
040         */
041        private String authenticationServiceName = "java:comp/env/smx/AuthenticationService";
042        
043        
044        /**
045         * @return the authenticationService
046         */
047        public AuthenticationService getAuthenticationService() {
048            return authenticationService;
049        }
050    
051        /**
052         * @param authenticationService the authenticationService to set
053         */
054        public void setAuthenticationService(AuthenticationService authenticationService) {
055            this.authenticationService = authenticationService;
056        }
057    
058        /**
059         * @return the authenticationServiceName
060         */
061        public String getAuthenticationServiceName() {
062            return authenticationServiceName;
063        }
064    
065        /**
066         * @param authenticationServiceName the authenticationServiceName to set
067         */
068        public void setAuthenticationServiceName(String authenticationServiceName) {
069            this.authenticationServiceName = authenticationServiceName;
070        }
071    
072        
073        public boolean load() {
074            File f = null;
075            InputStream in = null;
076            if (rootDir != null) {
077                // try to find the property file in the workspace folder
078                f = new File(rootDir, CONFIG_FILE);
079                if (!f.exists()) {
080                    f = null;
081                }
082            }
083            if (f == null) {
084                // find property file in classpath if it is not available in workspace 
085                in = this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE);
086                if (in == null) {
087                    return false;
088                }
089            }
090    
091            try {
092                if (f != null) {
093                    properties.load(new FileInputStream(f));
094                } else {
095                    properties.load(in);
096                }
097            } catch (IOException e) {
098                throw new RuntimeException("Could not load component configuration", e);
099            }
100            if (properties.getProperty(componentName + ".busCfg") != null) {
101                setBusCfg(properties.getProperty(componentName + ".busCfg"));
102            }
103            
104            return true;
105        }
106    
107        /**
108         * @return Returns the rootDir.
109         * @org.apache.xbean.Property hidden="true"
110         */
111        public String getRootDir() {
112            return rootDir;
113        }
114    
115        /**
116         * @param rootDir The rootDir to set.
117         */
118        public void setRootDir(String rootDir) {
119            this.rootDir = rootDir;
120        }
121    
122        /**
123         * @return Returns the componentName.
124         * @org.apache.xbean.Property hidden="true"
125         */
126        public String getComponentName() {
127            return componentName;
128        }
129    
130        /**
131         * @param componentName The componentName to set.
132         */
133        public void setComponentName(String componentName) {
134            this.componentName = componentName;
135        }
136    
137        public void setBusCfg(String busCfg) {
138            this.busCfg = busCfg;
139        }
140    
141        public String getBusCfg() {
142            return busCfg;
143        }
144        
145    }