Save This Page
Home » openejb-3.1.2-src » org.superbiz.registry » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   package org.superbiz.registry;
   18   
   19   //START SNIPPET: code
   20   import static javax.ejb.ConcurrencyManagementType.BEAN;
   21   import javax.ejb.Singleton;
   22   import javax.ejb.ConcurrencyManagement;
   23   import javax.ejb.Startup;
   24   import javax.annotation.PostConstruct;
   25   import javax.annotation.PreDestroy;
   26   import java.util.Properties;
   27   
   28   @Singleton
   29   @ConcurrencyManagement(BEAN)
   30   @Startup
   31   public class PropertyRegistryBean implements PropertyRegistry {
   32   
   33       // Note the java.util.Properties object is a thread-safe
   34       // collections that uses synchronization.  If it didn't
   35       // you would have to use some form of synchronization
   36       // to ensure the PropertyRegistryBean is thread-safe.
   37       private final Properties properties = new Properties();
   38   
   39       // The @Startup method ensures that this method is
   40       // called when the application starts up.
   41       @PostConstruct
   42       public void applicationStartup() {
   43           properties.putAll(System.getProperties());
   44       }
   45   
   46       @PreDestroy
   47       public void applicationShutdown() {
   48           properties.clear();
   49       }
   50   
   51       public String getProperty(String key) {
   52           return properties.getProperty(key);
   53       }
   54   
   55       public String setProperty(String key, String value) {
   56           return (String) properties.setProperty(key, value);
   57       }
   58   
   59       public String removeProperty(String key) {
   60           return (String) properties.remove(key);
   61       }
   62   
   63   }
   64   //END SNIPPET: code

Save This Page
Home » openejb-3.1.2-src » org.superbiz.registry » [javadoc | source]