InitialDirContext.java 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /* InitialDirContext.java --
  2. Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.naming.directory;
  32. import java.util.Hashtable;
  33. import javax.naming.Context;
  34. import javax.naming.InitialContext;
  35. import javax.naming.Name;
  36. import javax.naming.NamingEnumeration;
  37. import javax.naming.NamingException;
  38. import javax.naming.NoInitialContextException;
  39. import javax.naming.NotContextException;
  40. /**
  41. * @author Tom Tromey (tromey@redhat.com)
  42. * @date June 25, 2001
  43. */
  44. public class InitialDirContext extends InitialContext implements DirContext
  45. {
  46. public InitialDirContext ()
  47. throws NamingException
  48. {
  49. this (null);
  50. }
  51. protected InitialDirContext (boolean lazy)
  52. throws NamingException
  53. {
  54. super (lazy);
  55. }
  56. public InitialDirContext (Hashtable<?, ?> environment)
  57. throws NamingException
  58. {
  59. super (environment);
  60. }
  61. // The InitialContext docs suggest that this exist. And it does
  62. // seem like a good idea. but the InitialDirContext docs indicate
  63. // it cannot be non-private.
  64. private DirContext getURLOrDefaultInitDirCtx (Name name)
  65. throws NamingException
  66. {
  67. Context c = getURLOrDefaultInitCtx (name);
  68. if (c == null)
  69. throw new NoInitialContextException ();
  70. else if (! (c instanceof DirContext))
  71. throw new NotContextException ();
  72. return (DirContext) c;
  73. }
  74. private DirContext getURLOrDefaultInitDirCtx (String name)
  75. throws NamingException
  76. {
  77. Context c = getURLOrDefaultInitCtx (name);
  78. if (c == null)
  79. throw new NoInitialContextException ();
  80. else if (! (c instanceof DirContext))
  81. throw new NotContextException ();
  82. return (DirContext) c;
  83. }
  84. public Attributes getAttributes (String name)
  85. throws NamingException
  86. {
  87. return getURLOrDefaultInitDirCtx (name).getAttributes (name);
  88. }
  89. public Attributes getAttributes (String name, String[] attrIds)
  90. throws NamingException
  91. {
  92. return getURLOrDefaultInitDirCtx (name).getAttributes (name, attrIds);
  93. }
  94. public Attributes getAttributes (Name name)
  95. throws NamingException
  96. {
  97. return getURLOrDefaultInitDirCtx (name).getAttributes (name);
  98. }
  99. public Attributes getAttributes(Name name, String[] attrIds)
  100. throws NamingException
  101. {
  102. return getURLOrDefaultInitDirCtx (name).getAttributes (name, attrIds);
  103. }
  104. public void modifyAttributes(Name name, int mod_op, Attributes attrs)
  105. throws NamingException
  106. {
  107. getURLOrDefaultInitDirCtx (name).modifyAttributes (name, mod_op, attrs);
  108. }
  109. public void modifyAttributes(String name, int mod_op, Attributes attrs)
  110. throws NamingException
  111. {
  112. getURLOrDefaultInitDirCtx (name).modifyAttributes (name, mod_op, attrs);
  113. }
  114. public void modifyAttributes(Name name, ModificationItem[] mods)
  115. throws NamingException
  116. {
  117. getURLOrDefaultInitDirCtx (name).modifyAttributes (name, mods);
  118. }
  119. public void modifyAttributes(String name, ModificationItem[] mods)
  120. throws NamingException
  121. {
  122. getURLOrDefaultInitDirCtx (name).modifyAttributes (name, mods);
  123. }
  124. public void bind(Name name, Object obj, Attributes attrs)
  125. throws NamingException
  126. {
  127. getURLOrDefaultInitDirCtx (name).bind (name, obj, attrs);
  128. }
  129. public void bind(String name, Object obj, Attributes attrs)
  130. throws NamingException
  131. {
  132. getURLOrDefaultInitDirCtx (name).bind (name, obj, attrs);
  133. }
  134. public void rebind(Name name, Object obj, Attributes attrs)
  135. throws NamingException
  136. {
  137. getURLOrDefaultInitDirCtx (name).rebind (name, obj, attrs);
  138. }
  139. public void rebind(String name, Object obj, Attributes attrs)
  140. throws NamingException
  141. {
  142. getURLOrDefaultInitDirCtx (name).rebind (name, obj, attrs);
  143. }
  144. public DirContext createSubcontext(Name name, Attributes attrs)
  145. throws NamingException
  146. {
  147. return getURLOrDefaultInitDirCtx (name).createSubcontext (name, attrs);
  148. }
  149. public DirContext createSubcontext(String name, Attributes attrs)
  150. throws NamingException
  151. {
  152. return getURLOrDefaultInitDirCtx (name).createSubcontext (name, attrs);
  153. }
  154. public DirContext getSchema(Name name)
  155. throws NamingException
  156. {
  157. return getURLOrDefaultInitDirCtx (name).getSchema (name);
  158. }
  159. public DirContext getSchema(String name)
  160. throws NamingException
  161. {
  162. return getURLOrDefaultInitDirCtx (name).getSchema (name);
  163. }
  164. public DirContext getSchemaClassDefinition(Name name)
  165. throws NamingException
  166. {
  167. return getURLOrDefaultInitDirCtx (name).getSchemaClassDefinition (name);
  168. }
  169. public DirContext getSchemaClassDefinition(String name)
  170. throws NamingException
  171. {
  172. return getURLOrDefaultInitDirCtx (name).getSchemaClassDefinition (name);
  173. }
  174. public NamingEnumeration<SearchResult> search(Name name,
  175. Attributes matchingAttributes,
  176. String[] attributesToReturn)
  177. throws NamingException
  178. {
  179. return getURLOrDefaultInitDirCtx (name).search (name, matchingAttributes,
  180. attributesToReturn);
  181. }
  182. public NamingEnumeration<SearchResult> search(String name,
  183. Attributes matchingAttributes,
  184. String[] attributesToReturn)
  185. throws NamingException
  186. {
  187. return getURLOrDefaultInitDirCtx (name).search (name, matchingAttributes,
  188. attributesToReturn);
  189. }
  190. public NamingEnumeration<SearchResult> search(Name name,
  191. Attributes matchingAttributes)
  192. throws NamingException
  193. {
  194. return getURLOrDefaultInitDirCtx (name).search (name, matchingAttributes);
  195. }
  196. public NamingEnumeration<SearchResult> search(String name,
  197. Attributes matchingAttributes)
  198. throws NamingException
  199. {
  200. return getURLOrDefaultInitDirCtx (name).search (name, matchingAttributes);
  201. }
  202. public NamingEnumeration<SearchResult> search(Name name, String filter,
  203. SearchControls cons)
  204. throws NamingException
  205. {
  206. return getURLOrDefaultInitDirCtx (name).search (name, filter, cons);
  207. }
  208. public NamingEnumeration<SearchResult> search(String name, String filter,
  209. SearchControls cons)
  210. throws NamingException
  211. {
  212. return getURLOrDefaultInitDirCtx (name).search (name, filter, cons);
  213. }
  214. public NamingEnumeration<SearchResult> search(Name name, String filterExpr,
  215. Object[] filterArgs,
  216. SearchControls cons)
  217. throws NamingException
  218. {
  219. return getURLOrDefaultInitDirCtx (name).search (name, filterExpr,
  220. filterArgs, cons);
  221. }
  222. public NamingEnumeration<SearchResult> search(String name,
  223. String filterExpr,
  224. Object[] filterArgs,
  225. SearchControls cons)
  226. throws NamingException
  227. {
  228. return getURLOrDefaultInitDirCtx (name).search (name, filterExpr,
  229. filterArgs, cons);
  230. }
  231. }