1 8 package org.codehaus.spice.jndikit; 9 10 import java.util.Hashtable ; 11 import javax.naming.Context ; 12 import javax.naming.Name ; 13 import javax.naming.NamingException ; 14 import javax.naming.spi.ObjectFactory ; 15 import javax.naming.spi.StateFactory ; 16 17 24 public abstract class AbstractNamespace 25 implements Namespace 26 { 27 protected ObjectFactory [] m_objectFactorySet; 28 protected StateFactory [] m_stateFactorySet; 29 30 public Object getStateToBind( final Object object, 31 final Name name, 32 final Context parent, 33 final Hashtable environment ) 34 throws NamingException 35 { 36 final StateFactory [] stateFactorySet = m_stateFactorySet; 39 40 for( int i = 0; i < stateFactorySet.length; i++ ) 41 { 42 final Object result = 43 stateFactorySet[ i ].getStateToBind( object, name, parent, environment ); 44 45 if( null != result ) 46 { 47 return result; 48 } 49 } 50 51 return object; 52 } 53 54 public Object getObjectInstance( final Object object, 55 final Name name, 56 final Context parent, 57 final Hashtable environment ) 58 throws Exception 59 { 60 final ObjectFactory [] objectFactorySet = m_objectFactorySet; 63 64 for( int i = 0; i < objectFactorySet.length; i++ ) 65 { 66 final Object result = 67 objectFactorySet[ i ].getObjectInstance( object, name, parent, environment ); 68 69 if( null != result ) 70 { 71 return result; 72 } 73 } 74 75 return object; 76 } 77 78 83 protected synchronized void addStateFactory( final StateFactory stateFactory ) 84 { 85 final StateFactory [] stateFactorySet = 87 new StateFactory [ m_stateFactorySet.length + 1 ]; 88 89 System.arraycopy( m_stateFactorySet, 0, stateFactorySet, 0, m_stateFactorySet.length ); 91 92 stateFactorySet[ m_stateFactorySet.length ] = stateFactory; 94 95 m_stateFactorySet = stateFactorySet; 97 } 98 99 104 protected synchronized void addObjectFactory( final ObjectFactory objectFactory ) 105 { 106 final ObjectFactory [] objectFactorySet = 108 new ObjectFactory [ m_objectFactorySet.length + 1 ]; 109 110 System.arraycopy( m_objectFactorySet, 0, objectFactorySet, 0, m_objectFactorySet.length ); 112 113 objectFactorySet[ m_objectFactorySet.length ] = objectFactory; 115 116 m_objectFactorySet = objectFactorySet; 118 } 119 } 120 | Popular Tags |