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.activemq.web.config;
018    
019    import java.util.Collection;
020    
021    import javax.jms.ConnectionFactory;
022    import javax.management.remote.JMXServiceURL;
023    
024    
025    /**
026     * Configuration based on system-properties.
027     * 
028     * 
029     */
030    public class SystemPropertiesConfiguration extends AbstractConfiguration {
031    
032            public static final String PROPERTY_JMS_URL = "webconsole.jms.url";
033        public static final String PROPERTY_JMS_USER = "webconsole.jms.user";
034        public static final String PROPERTY_JMS_PASSWORD = "webconsole.jms.password";
035    
036        public static final String PROPERTY_JMX_URL = "webconsole.jmx.url";
037        public static final String PROPERTY_JMX_USER = "webconsole.jmx.user";
038        public static final String PROPERTY_JMX_PASSWORD = "webconsole.jmx.password";
039    
040            public ConnectionFactory getConnectionFactory() {
041                    String jmsUrl = System.getProperty(PROPERTY_JMS_URL);
042                    if (jmsUrl == null)
043                            throw new IllegalArgumentException(
044                                            "A JMS-url must be specified (system property "
045                                                            + PROPERTY_JMS_URL);
046    
047                    String jmsUser = System.getProperty(PROPERTY_JMS_USER);
048                    String jmsPassword = System.getProperty(PROPERTY_JMS_PASSWORD);
049                    return makeConnectionFactory(jmsUrl, jmsUser, jmsPassword);
050            }
051    
052            public Collection<JMXServiceURL> getJmxUrls() {
053                    String jmxUrls = System.getProperty(PROPERTY_JMX_URL);
054                    return makeJmxUrls(jmxUrls);
055            }
056    
057            public String getJmxPassword() {
058                    return System.getProperty(PROPERTY_JMX_PASSWORD);
059            }
060    
061            public String getJmxUser() {
062                    return System.getProperty(PROPERTY_JMX_USER);
063            }
064    
065    }