001 /** 002 * 003 * Copyright 2004 Protique Ltd 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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 **/ 018 019 package org.activemq.jndi; 020 021 import javax.naming.NamingException; 022 import javax.naming.Reference; 023 import java.util.Properties; 024 025 /** 026 * Faciliates objects to be stored in JNDI as properties 027 */ 028 029 public abstract class JNDIBaseStorable implements JNDIStorableInterface { 030 private Properties properties = null; 031 032 033 /** 034 * Set the properties that will represent the instance in JNDI 035 * 036 * @param props 037 */ 038 protected abstract void buildFromProperties(Properties props); 039 040 /** 041 * Initialize the instance from properties stored in JNDI 042 * 043 * @param props 044 */ 045 046 protected abstract void populateProperties(Properties props); 047 048 /** 049 * set the properties for this instance as retrieved from JNDI 050 * 051 * @param props 052 */ 053 054 public synchronized void setProperties(Properties props) { 055 this.properties = props; 056 buildFromProperties(props); 057 } 058 059 /** 060 * Get the properties from this instance for storing in JNDI 061 * 062 * @return the properties 063 */ 064 065 public synchronized Properties getProperties() { 066 if (this.properties == null) { 067 this.properties = new Properties(); 068 } 069 populateProperties(this.properties); 070 return this.properties; 071 } 072 073 074 /** 075 * Retrive a Reference for this instance to store in JNDI 076 * 077 * @return the built Reference 078 * @throws NamingException if error on building Reference 079 */ 080 public Reference getReference() throws NamingException { 081 return JNDIReferenceFactory.createReference(this.getClass().getName(), this); 082 } 083 084 } 085