1 /* GiopNamingServiceFactory.java -- handles corbaname: urls
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu
.javax
.naming
.giop
;
41 import gnu
.CORBA
.OrbFunctional
;
43 import gnu
.java
.lang
.CPStringBuilder
;
45 import java
.util
.Enumeration
;
46 import java
.util
.Hashtable
;
47 import java
.util
.Iterator
;
49 import java
.util
.Properties
;
50 import java
.util
.TreeMap
;
52 import javax
.naming
.Context
;
53 import javax
.naming
.Name
;
55 import org
.omg
.CORBA
.ORB
;
58 * The context factory to represent the corbaname: style urls. Such URL states
59 * that the CORBA naming service exists on the given host. This service can
60 * return the required object, finding it by the given name. The names are
61 * parsed using the specification of the corbaname urls. Being the naming
62 * service, the returned context supports creating the subcontexts, forwarding
63 * this task to the existing naming service.
65 * @author Audrius Meskauskas (audriusa@Bioinformatics.org)
67 public class GiopNamingServiceFactory
70 * The default naming service provider. It is assumed, that the naming service
71 * is running on the port 900 of the local host, using the GIOP version 1.2
73 public static final String DEFAULT_PROVIDER
=
74 "corbaloc:iiop:1.2@127.0.0.1:900/NameService";
77 * The table of all instantiated ORB's that are found by they ORB
78 * properties signatures. If all ORB related properties are the same,
79 * the ORB's are shared.
81 public static Hashtable orbs
= new Hashtable();
85 * Create a new instance of the corbaname URL context.
87 public Object
getObjectInstance(Object refObj
, Name name
, Context nameCtx
,
88 Hashtable environment
)
90 String provider
= (String
) environment
.get(Context
.PROVIDER_URL
);
92 provider
= DEFAULT_PROVIDER
;
94 String orbSignature
= getOrbSignature(environment
);
99 orb
= (ORB
) orbs
.get(orbSignature
);
102 Properties props
= new Properties();
103 props
.putAll(environment
);
104 orb
= ORB
.init(new String
[0], props
);
105 orbs
.put(orbSignature
, orb
);
106 final ORB runIt
= orb
;
117 return new GiopNamingServiceURLContext(environment
, this, orb
);
121 * Check if this ORB is still in use (maybe it is time to shutdown it). This
122 * method only works when the Classpath CORBA implementation is used
123 * (otherwise it return without action). The method is called from the close()
124 * method of the created context.
127 * the ORB that maybe is no longer referenced.
129 public void checkIfReferenced(ORB orb
)
133 // We can only do this with the Classpath implementation.
134 if (orb
instanceof OrbFunctional
)
136 OrbFunctional cOrb
= (OrbFunctional
) orb
;
137 // If there are no connected objects, we can destroy the orb.
138 if (cOrb
.countConnectedObjects() == 0)
140 cOrb
.shutdown(false);
143 Enumeration keys
= orbs
.keys();
145 Remove
: while (keys
.hasMoreElements())
147 key
= keys
.nextElement();
148 if (orbs
.get(key
) == orb
)
160 * Get all properties.
162 public String
getOrbSignature(Map props
)
164 TreeMap map
= new TreeMap();
166 CPStringBuilder b
= new CPStringBuilder(50*props
.size());
168 Iterator iter
= map
.entrySet().iterator();
170 while (iter
.hasNext())
172 m
= (Map
.Entry
) iter
.next();
173 b
.append(m
.getKey());
175 b
.append(m
.getValue());