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.geronimo.system.properties;
018
019 import org.apache.geronimo.gbean.GBeanInfo;
020 import org.apache.geronimo.gbean.GBeanInfoBuilder;
021
022 import javax.naming.InitialContext;
023 import javax.naming.NamingException;
024
025 /** java.naming.factory.initial=com.sun.jndi.rmi.registry.RegistryContextFactory
026 java.naming.factory.url.pkgs=org.apache.geronimo.naming
027 java.naming.provider.url=rmi://localhost:1099
028
029 */
030 public class NamingProperties {
031
032 static final String JAVA_NAMING_FACTORY_INITIAL = "java.naming.factory.initial";
033 static final String JAVA_NAMING_FACTORY_URL_PKGS = "java.naming.factory.url.pkgs";
034 static final String JAVA_NAMING_PROVIDER_URL = "java.naming.provider.url";
035
036 public NamingProperties(String namingFactoryInitial, String namingFactoryUrlPkgs, String namingProviderUrl) {
037 setNamingFactoryInitial(namingFactoryInitial);
038 setNamingFactoryUrlPkgs(namingFactoryUrlPkgs);
039 setNamingProviderUrl(namingProviderUrl);
040
041 try {
042 // Calling this causes the System properties we just set
043 // to be read in and cached by the vm ensuring we can't
044 // be booted out by another module in the system.
045 new InitialContext().lookup("java:");
046 } catch (Throwable ignore) {
047 }
048 }
049
050 public String getNamingFactoryInitial() {
051 return System.getProperty(JAVA_NAMING_FACTORY_INITIAL);
052 }
053
054 public void setNamingFactoryInitial(String namingFactoryInitial) {
055 System.setProperty(JAVA_NAMING_FACTORY_INITIAL, namingFactoryInitial);
056 }
057
058 public String getNamingFactoryUrlPkgs() {
059 return System.getProperty(JAVA_NAMING_FACTORY_URL_PKGS);
060 }
061
062 public void setNamingFactoryUrlPkgs(String namingFactoryUrlPkgs) {
063 System.setProperty(JAVA_NAMING_FACTORY_URL_PKGS, namingFactoryUrlPkgs);
064 }
065
066 public String getNamingProviderUrl() {
067 return System.getProperty(JAVA_NAMING_PROVIDER_URL);
068 }
069
070 public void setNamingProviderUrl(String namingProviderUrl) {
071 System.setProperty(JAVA_NAMING_PROVIDER_URL, namingProviderUrl);
072 }
073
074 public static final GBeanInfo gbeanInfo;
075
076 static {
077 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(NamingProperties.class);
078 infoFactory.addAttribute("namingFactoryInitial", String.class, true);
079 infoFactory.addAttribute("namingFactoryUrlPkgs", String.class, true);
080 infoFactory.addAttribute("namingProviderUrl", String.class, true, true);
081
082 infoFactory.setConstructor(new String[] {"namingFactoryInitial", "namingFactoryUrlPkgs", "namingProviderUrl"});
083
084 gbeanInfo = infoFactory.getBeanInfo();
085 }
086
087 public static GBeanInfo getGBeanInfo() {
088 return gbeanInfo;
089 }
090 }