View Javadoc

1   /*
2    * Copyright (C) The Apache Software Foundation. All rights reserved.
3    *
4    * This software is published under the terms of the Apache Software License
5    * version 1.1, a copy of which has been included with this distribution in
6    * the LICENSE file.
7    */
8   package org.apache.avalon.excalibur.naming;
9   
10  import java.util.Hashtable;
11  import javax.naming.Context;
12  import javax.naming.NameParser;
13  import javax.naming.NamingException;
14  import javax.naming.spi.InitialContextFactory;
15  import javax.naming.spi.ObjectFactory;
16  import javax.naming.spi.StateFactory;
17  
18  /***
19   * This is the default namespace implementation.
20   *
21   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
22   * @version $Revision: 1.2 $
23   */
24  public class DefaultNamespace
25      extends AbstractNamespace
26  {
27      protected NameParser             m_nameParser;
28  
29      public DefaultNamespace( final NameParser nameParser )
30      {
31          this( nameParser,
32                new ObjectFactory[ 0 ],
33                new StateFactory[ 0 ] );
34      }
35  
36      public DefaultNamespace( final NameParser nameParser,
37                               final ObjectFactory[] objectFactorySet,
38                               final StateFactory[] stateFactorySet )
39      {
40          m_nameParser = nameParser;
41          m_objectFactorySet = objectFactorySet;
42          m_stateFactorySet = stateFactorySet;
43      }
44  
45      public synchronized void addStateFactory( final StateFactory stateFactory )
46      {
47          //create new array of factory objects
48          final StateFactory[] stateFactorySet =
49              new StateFactory[ m_stateFactorySet.length + 1 ];
50  
51          //copy old factory objects to new array
52          System.arraycopy( m_stateFactorySet, 0, stateFactorySet, 0, m_stateFactorySet.length );
53  
54          //add in new factory at end
55          stateFactorySet[ m_stateFactorySet.length ] = stateFactory;
56  
57          //update factory set
58          m_stateFactorySet = stateFactorySet;
59      }
60  
61      public synchronized void addObjectFactory( final ObjectFactory objectFactory )
62      {
63          //create new array of factory objects
64          final ObjectFactory[] objectFactorySet =
65              new ObjectFactory[ m_objectFactorySet.length + 1 ];
66  
67          //copy old factory objects to new array
68          System.arraycopy( m_objectFactorySet, 0, objectFactorySet, 0, m_objectFactorySet.length );
69  
70          //add in new factory at end
71          objectFactorySet[ m_objectFactorySet.length ] = objectFactory;
72  
73          //update factory set
74          m_objectFactorySet = objectFactorySet;
75      }
76  
77      public NameParser getNameParser()
78      {
79          return m_nameParser;
80      }
81  }