001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020 package org.apache.directory.server.core.jndi; 021 022 023 import java.util.Hashtable; 024 025 import javax.naming.Context; 026 import javax.naming.Name; 027 import javax.naming.NameClassPair; 028 import javax.naming.NameParser; 029 import javax.naming.NamingEnumeration; 030 import javax.naming.NamingException; 031 import javax.naming.ServiceUnavailableException; 032 import javax.naming.event.EventDirContext; 033 import javax.naming.event.NamingListener; 034 import javax.naming.directory.Attributes; 035 import javax.naming.directory.DirContext; 036 import javax.naming.directory.ModificationItem; 037 import javax.naming.directory.SearchControls; 038 import javax.naming.directory.SearchResult; 039 import javax.naming.ldap.Control; 040 import javax.naming.ldap.ExtendedRequest; 041 import javax.naming.ldap.ExtendedResponse; 042 import javax.naming.ldap.LdapContext; 043 044 import javax.naming.Binding; 045 046 047 /** 048 * A do nothing placeholder context whose methods throw ServiceUnavailableExceptions. 049 * JNDI provider returns this context when you perform JNDI operations against the 050 * core directory service that has been shutdown or not started. By returning a 051 * non-null Context we prevent an unnecessary exception being thrown by 052 * {@link javax.naming.InitialContext} and any one of its subclasses. 053 * 054 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 055 * @version $Rev: 924262 $, $Date: 2010-03-17 14:01:17 +0100 (Wed, 17 Mar 2010) $ 056 */ 057 public class DeadContext implements LdapContext, EventDirContext 058 { 059 private final String EXCEPTION_MSG = "Context operation unavailable when " 060 + "invoked after directory service core provider has been shutdown"; 061 062 063 public Control[] getConnectControls() throws NamingException 064 { 065 throw new ServiceUnavailableException( EXCEPTION_MSG ); 066 } 067 068 069 public Control[] getRequestControls() throws NamingException 070 { 071 throw new ServiceUnavailableException( EXCEPTION_MSG ); 072 } 073 074 075 public Control[] getResponseControls() throws NamingException 076 { 077 throw new ServiceUnavailableException( EXCEPTION_MSG ); 078 } 079 080 081 public void reconnect( Control[] connCtls ) throws NamingException 082 { 083 throw new ServiceUnavailableException( EXCEPTION_MSG ); 084 } 085 086 087 public void setRequestControls( Control[] requestControls ) throws NamingException 088 { 089 throw new ServiceUnavailableException( EXCEPTION_MSG ); 090 } 091 092 093 public ExtendedResponse extendedOperation( ExtendedRequest request ) throws NamingException 094 { 095 throw new ServiceUnavailableException( EXCEPTION_MSG ); 096 } 097 098 099 public LdapContext newInstance( Control[] requestControls ) throws NamingException 100 { 101 throw new ServiceUnavailableException( EXCEPTION_MSG ); 102 } 103 104 105 public Attributes getAttributes( String name ) throws NamingException 106 { 107 throw new ServiceUnavailableException( EXCEPTION_MSG ); 108 } 109 110 111 public void modifyAttributes( String name, int mod_op, Attributes attrs ) throws NamingException 112 { 113 throw new ServiceUnavailableException( EXCEPTION_MSG ); 114 } 115 116 117 public Attributes getAttributes( Name name ) throws NamingException 118 { 119 throw new ServiceUnavailableException( EXCEPTION_MSG ); 120 } 121 122 123 public void modifyAttributes( Name name, int mod_op, Attributes attrs ) throws NamingException 124 { 125 throw new ServiceUnavailableException( EXCEPTION_MSG ); 126 } 127 128 129 public void modifyAttributes( Name name, ModificationItem[] mods ) throws NamingException 130 { 131 throw new ServiceUnavailableException( EXCEPTION_MSG ); 132 } 133 134 public DirContext getSchema( String name ) throws NamingException 135 { 136 throw new ServiceUnavailableException( EXCEPTION_MSG ); 137 } 138 139 140 public DirContext getSchemaClassDefinition( String name ) throws NamingException 141 { 142 throw new ServiceUnavailableException( EXCEPTION_MSG ); 143 } 144 145 146 public DirContext getSchema( Name name ) throws NamingException 147 { 148 throw new ServiceUnavailableException( EXCEPTION_MSG ); 149 } 150 151 152 public DirContext getSchemaClassDefinition( Name name ) throws NamingException 153 { 154 throw new ServiceUnavailableException( EXCEPTION_MSG ); 155 } 156 157 158 public void modifyAttributes( String name, ModificationItem[] mods ) throws NamingException 159 { 160 throw new ServiceUnavailableException( EXCEPTION_MSG ); 161 } 162 163 164 public NamingEnumeration<SearchResult> search( String name, Attributes matchingAttributes ) throws NamingException 165 { 166 throw new ServiceUnavailableException( EXCEPTION_MSG ); 167 } 168 169 170 public NamingEnumeration<SearchResult> search( Name name, Attributes matchingAttributes ) throws NamingException 171 { 172 throw new ServiceUnavailableException( EXCEPTION_MSG ); 173 } 174 175 176 public void bind( String name, Object obj, Attributes attrs ) throws NamingException 177 { 178 throw new ServiceUnavailableException( EXCEPTION_MSG ); 179 } 180 181 182 public void rebind( String name, Object obj, Attributes attrs ) throws NamingException 183 { 184 throw new ServiceUnavailableException( EXCEPTION_MSG ); 185 } 186 187 188 public void bind( Name name, Object obj, Attributes attrs ) throws NamingException 189 { 190 throw new ServiceUnavailableException( EXCEPTION_MSG ); 191 } 192 193 194 public void rebind( Name name, Object obj, Attributes attrs ) throws NamingException 195 { 196 throw new ServiceUnavailableException( EXCEPTION_MSG ); 197 } 198 199 200 public Attributes getAttributes( String name, String[] attrIds ) throws NamingException 201 { 202 throw new ServiceUnavailableException( EXCEPTION_MSG ); 203 } 204 205 206 public Attributes getAttributes( Name name, String[] attrIds ) throws NamingException 207 { 208 throw new ServiceUnavailableException( EXCEPTION_MSG ); 209 } 210 211 212 public DirContext createSubcontext( String name, Attributes attrs ) throws NamingException 213 { 214 throw new ServiceUnavailableException( EXCEPTION_MSG ); 215 } 216 217 218 public DirContext createSubcontext( Name name, Attributes attrs ) throws NamingException 219 { 220 throw new ServiceUnavailableException( EXCEPTION_MSG ); 221 } 222 223 224 public NamingEnumeration<SearchResult> search( String name, Attributes matchingAttributes, String[] attributesToReturn ) 225 throws NamingException 226 { 227 throw new ServiceUnavailableException( EXCEPTION_MSG ); 228 } 229 230 231 public NamingEnumeration<SearchResult> search( Name name, Attributes matchingAttributes, String[] attributesToReturn ) 232 throws NamingException 233 { 234 throw new ServiceUnavailableException( EXCEPTION_MSG ); 235 } 236 237 238 public NamingEnumeration<SearchResult> search( String name, String filter, SearchControls cons ) throws NamingException 239 { 240 throw new ServiceUnavailableException( EXCEPTION_MSG ); 241 } 242 243 244 public NamingEnumeration<SearchResult> search( Name name, String filter, SearchControls cons ) throws NamingException 245 { 246 throw new ServiceUnavailableException( EXCEPTION_MSG ); 247 } 248 249 250 public NamingEnumeration<SearchResult> search( String name, String filterExpr, Object[] filterArgs, SearchControls cons ) 251 throws NamingException 252 { 253 throw new ServiceUnavailableException( EXCEPTION_MSG ); 254 } 255 256 257 public NamingEnumeration<SearchResult> search( Name name, String filterExpr, Object[] filterArgs, SearchControls cons ) 258 throws NamingException 259 { 260 throw new ServiceUnavailableException( EXCEPTION_MSG ); 261 } 262 263 264 public void close() throws NamingException 265 { 266 throw new ServiceUnavailableException( EXCEPTION_MSG ); 267 } 268 269 270 public String getNameInNamespace() throws NamingException 271 { 272 throw new ServiceUnavailableException( EXCEPTION_MSG ); 273 } 274 275 276 public void destroySubcontext( String name ) throws NamingException 277 { 278 throw new ServiceUnavailableException( EXCEPTION_MSG ); 279 } 280 281 282 public void unbind( String name ) throws NamingException 283 { 284 throw new ServiceUnavailableException( EXCEPTION_MSG ); 285 } 286 287 288 public Hashtable<String,Object> getEnvironment() throws NamingException 289 { 290 throw new ServiceUnavailableException( EXCEPTION_MSG ); 291 } 292 293 294 public void destroySubcontext( Name name ) throws NamingException 295 { 296 throw new ServiceUnavailableException( EXCEPTION_MSG ); 297 } 298 299 300 public void unbind( Name name ) throws NamingException 301 { 302 throw new ServiceUnavailableException( EXCEPTION_MSG ); 303 } 304 305 306 public Object lookup( String name ) throws NamingException 307 { 308 throw new ServiceUnavailableException( EXCEPTION_MSG ); 309 } 310 311 312 public Object lookupLink( String name ) throws NamingException 313 { 314 throw new ServiceUnavailableException( EXCEPTION_MSG ); 315 } 316 317 318 public Object removeFromEnvironment( String propName ) throws NamingException 319 { 320 throw new ServiceUnavailableException( EXCEPTION_MSG ); 321 } 322 323 324 public void bind( String name, Object obj ) throws NamingException 325 { 326 throw new ServiceUnavailableException( EXCEPTION_MSG ); 327 } 328 329 330 public void rebind( String name, Object obj ) throws NamingException 331 { 332 throw new ServiceUnavailableException( EXCEPTION_MSG ); 333 } 334 335 336 public Object lookup( Name name ) throws NamingException 337 { 338 throw new ServiceUnavailableException( EXCEPTION_MSG ); 339 } 340 341 342 public Object lookupLink( Name name ) throws NamingException 343 { 344 throw new ServiceUnavailableException( EXCEPTION_MSG ); 345 } 346 347 348 public void bind( Name name, Object obj ) throws NamingException 349 { 350 throw new ServiceUnavailableException( EXCEPTION_MSG ); 351 } 352 353 354 public void rebind( Name name, Object obj ) throws NamingException 355 { 356 throw new ServiceUnavailableException( EXCEPTION_MSG ); 357 } 358 359 360 public void rename( String oldName, String newName ) throws NamingException 361 { 362 throw new ServiceUnavailableException( EXCEPTION_MSG ); 363 } 364 365 366 public Context createSubcontext( String name ) throws NamingException 367 { 368 throw new ServiceUnavailableException( EXCEPTION_MSG ); 369 } 370 371 372 public Context createSubcontext( Name name ) throws NamingException 373 { 374 throw new ServiceUnavailableException( EXCEPTION_MSG ); 375 } 376 377 378 public void rename( Name oldName, Name newName ) throws NamingException 379 { 380 throw new ServiceUnavailableException( EXCEPTION_MSG ); 381 } 382 383 384 public NameParser getNameParser( String name ) throws NamingException 385 { 386 throw new ServiceUnavailableException( EXCEPTION_MSG ); 387 } 388 389 390 public NameParser getNameParser( Name name ) throws NamingException 391 { 392 throw new ServiceUnavailableException( EXCEPTION_MSG ); 393 } 394 395 396 public NamingEnumeration<NameClassPair> list( String name ) throws NamingException 397 { 398 throw new ServiceUnavailableException( EXCEPTION_MSG ); 399 } 400 401 402 public NamingEnumeration<Binding> listBindings( String name ) throws NamingException 403 { 404 throw new ServiceUnavailableException( EXCEPTION_MSG ); 405 } 406 407 408 public NamingEnumeration<NameClassPair> list( Name name ) throws NamingException 409 { 410 throw new ServiceUnavailableException( EXCEPTION_MSG ); 411 } 412 413 414 public NamingEnumeration<Binding> listBindings( Name name ) throws NamingException 415 { 416 throw new ServiceUnavailableException( EXCEPTION_MSG ); 417 } 418 419 420 public Object addToEnvironment( String propName, Object propVal ) throws NamingException 421 { 422 throw new ServiceUnavailableException( EXCEPTION_MSG ); 423 } 424 425 426 public String composeName( String name, String prefix ) throws NamingException 427 { 428 throw new ServiceUnavailableException( EXCEPTION_MSG ); 429 } 430 431 432 public Name composeName( Name name, Name prefix ) throws NamingException 433 { 434 throw new ServiceUnavailableException( EXCEPTION_MSG ); 435 } 436 437 438 public void addNamingListener( Name name, String s, SearchControls searchControls, NamingListener namingListener ) 439 throws NamingException 440 { 441 throw new ServiceUnavailableException( EXCEPTION_MSG ); 442 } 443 444 445 public void addNamingListener( String s, String s1, SearchControls searchControls, NamingListener namingListener ) 446 throws NamingException 447 { 448 throw new ServiceUnavailableException( EXCEPTION_MSG ); 449 } 450 451 452 public void addNamingListener( Name name, String s, Object[] objects, SearchControls searchControls, 453 NamingListener namingListener ) throws NamingException 454 { 455 throw new ServiceUnavailableException( EXCEPTION_MSG ); 456 } 457 458 459 public void addNamingListener( String s, String s1, Object[] objects, SearchControls searchControls, 460 NamingListener namingListener ) throws NamingException 461 { 462 throw new ServiceUnavailableException( EXCEPTION_MSG ); 463 } 464 465 466 public void addNamingListener( Name name, int i, NamingListener namingListener ) throws NamingException 467 { 468 throw new ServiceUnavailableException( EXCEPTION_MSG ); 469 } 470 471 472 public void addNamingListener( String s, int i, NamingListener namingListener ) throws NamingException 473 { 474 throw new ServiceUnavailableException( EXCEPTION_MSG ); 475 } 476 477 478 public void removeNamingListener( NamingListener namingListener ) throws NamingException 479 { 480 throw new ServiceUnavailableException( EXCEPTION_MSG ); 481 } 482 483 484 public boolean targetMustExist() throws NamingException 485 { 486 throw new ServiceUnavailableException( EXCEPTION_MSG ); 487 } 488 }