1 50 package org.apache.avalon.excalibur.naming; 51 52 import java.util.Hashtable ; 53 54 import javax.naming.Context ; 55 import javax.naming.Name ; 56 import javax.naming.NamingException ; 57 import javax.naming.spi.ObjectFactory ; 58 import javax.naming.spi.StateFactory ; 59 60 68 public abstract class AbstractNamespace 69 implements Namespace 70 { 71 protected ObjectFactory [] m_objectFactorySet; 72 protected StateFactory [] m_stateFactorySet; 73 74 public Object getStateToBind( final Object object, 75 final Name name, 76 final Context parent, 77 final Hashtable environment ) 78 throws NamingException 79 { 80 final StateFactory [] stateFactorySet = m_stateFactorySet; 83 84 for( int i = 0; i < stateFactorySet.length; i++ ) 85 { 86 final Object result = 87 stateFactorySet[ i ].getStateToBind( object, name, parent, environment ); 88 89 if( null != result ) 90 { 91 return result; 92 } 93 } 94 95 return object; 96 } 97 98 public Object getObjectInstance( final Object object, 99 final Name name, 100 final Context parent, 101 final Hashtable environment ) 102 throws Exception 103 { 104 final ObjectFactory [] objectFactorySet = m_objectFactorySet; 107 108 for( int i = 0; i < objectFactorySet.length; i++ ) 109 { 110 final Object result = 111 objectFactorySet[ i ].getObjectInstance( object, name, parent, environment ); 112 113 if( null != result ) 114 { 115 return result; 116 } 117 } 118 119 return object; 120 } 121 122 127 protected synchronized void addStateFactory( final StateFactory stateFactory ) 128 { 129 final StateFactory [] stateFactorySet = 131 new StateFactory [ m_stateFactorySet.length + 1 ]; 132 133 System.arraycopy( m_stateFactorySet, 0, stateFactorySet, 0, m_stateFactorySet.length ); 135 136 stateFactorySet[ m_stateFactorySet.length ] = stateFactory; 138 139 m_stateFactorySet = stateFactorySet; 141 } 142 143 148 protected synchronized void addObjectFactory( final ObjectFactory objectFactory ) 149 { 150 final ObjectFactory [] objectFactorySet = 152 new ObjectFactory [ m_objectFactorySet.length + 1 ]; 153 154 System.arraycopy( m_objectFactorySet, 0, objectFactorySet, 0, m_objectFactorySet.length ); 156 157 objectFactorySet[ m_objectFactorySet.length ] = objectFactory; 159 160 m_objectFactorySet = objectFactorySet; 162 } 163 } 164 | Popular Tags |