1. /*
  2. * @(#)ContinuationContext.java 1.4 00/02/02
  3. *
  4. * Copyright 1999, 2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.naming.spi;
  11. import java.util.Hashtable;
  12. import javax.naming.*;
  13. /**
  14. * This class is for dealing with federations/continuations.
  15. *
  16. * @author Rosanna Lee
  17. * @author Scott Seligman
  18. * @version 1.4 00/02/02
  19. * @since 1.3
  20. */
  21. class ContinuationContext implements Context, Resolver {
  22. protected CannotProceedException cpe;
  23. protected Context contCtx = null;
  24. protected ContinuationContext(CannotProceedException cpe) {
  25. this.cpe = cpe;
  26. }
  27. protected Context getTargetContext() throws NamingException {
  28. if (contCtx == null) {
  29. if (cpe.getResolvedObj() == null)
  30. throw (NamingException)cpe.fillInStackTrace();
  31. contCtx = NamingManager.getContext(cpe.getResolvedObj(),
  32. cpe.getAltName(),
  33. cpe.getAltNameCtx(),
  34. cpe.getEnvironment());
  35. if (contCtx == null)
  36. throw (NamingException)cpe.fillInStackTrace();
  37. }
  38. return contCtx;
  39. }
  40. public Object lookup(Name name) throws NamingException {
  41. Context ctx = getTargetContext();
  42. return ctx.lookup(name);
  43. }
  44. public Object lookup(String name) throws NamingException {
  45. Context ctx = getTargetContext();
  46. return ctx.lookup(name);
  47. }
  48. public void bind(Name name, Object newObj) throws NamingException {
  49. Context ctx = getTargetContext();
  50. ctx.bind(name, newObj);
  51. }
  52. public void bind(String name, Object newObj) throws NamingException {
  53. Context ctx = getTargetContext();
  54. ctx.bind(name, newObj);
  55. }
  56. public void rebind(Name name, Object newObj) throws NamingException {
  57. Context ctx = getTargetContext();
  58. ctx.rebind(name, newObj);
  59. }
  60. public void rebind(String name, Object newObj) throws NamingException {
  61. Context ctx = getTargetContext();
  62. ctx.rebind(name, newObj);
  63. }
  64. public void unbind(Name name) throws NamingException {
  65. Context ctx = getTargetContext();
  66. ctx.unbind(name);
  67. }
  68. public void unbind(String name) throws NamingException {
  69. Context ctx = getTargetContext();
  70. ctx.unbind(name);
  71. }
  72. public void rename(Name name, Name newName) throws NamingException {
  73. Context ctx = getTargetContext();
  74. ctx.rename(name, newName);
  75. }
  76. public void rename(String name, String newName) throws NamingException {
  77. Context ctx = getTargetContext();
  78. ctx.rename(name, newName);
  79. }
  80. public NamingEnumeration list(Name name) throws NamingException {
  81. Context ctx = getTargetContext();
  82. return ctx.list(name);
  83. }
  84. public NamingEnumeration list(String name) throws NamingException {
  85. Context ctx = getTargetContext();
  86. return ctx.list(name);
  87. }
  88. public NamingEnumeration listBindings(Name name) throws NamingException {
  89. Context ctx = getTargetContext();
  90. return ctx.listBindings(name);
  91. }
  92. public NamingEnumeration listBindings(String name) throws NamingException {
  93. Context ctx = getTargetContext();
  94. return ctx.listBindings(name);
  95. }
  96. public void destroySubcontext(Name name) throws NamingException {
  97. Context ctx = getTargetContext();
  98. ctx.destroySubcontext(name);
  99. }
  100. public void destroySubcontext(String name) throws NamingException {
  101. Context ctx = getTargetContext();
  102. ctx.destroySubcontext(name);
  103. }
  104. public Context createSubcontext(Name name) throws NamingException {
  105. Context ctx = getTargetContext();
  106. return ctx.createSubcontext(name);
  107. }
  108. public Context createSubcontext(String name) throws NamingException {
  109. Context ctx = getTargetContext();
  110. return ctx.createSubcontext(name);
  111. }
  112. public Object lookupLink(Name name) throws NamingException {
  113. Context ctx = getTargetContext();
  114. return ctx.lookupLink(name);
  115. }
  116. public Object lookupLink(String name) throws NamingException {
  117. Context ctx = getTargetContext();
  118. return ctx.lookupLink(name);
  119. }
  120. public NameParser getNameParser(Name name) throws NamingException {
  121. Context ctx = getTargetContext();
  122. return ctx.getNameParser(name);
  123. }
  124. public NameParser getNameParser(String name) throws NamingException {
  125. Context ctx = getTargetContext();
  126. return ctx.getNameParser(name);
  127. }
  128. public Name composeName(Name name, Name prefix) throws NamingException {
  129. Context ctx = getTargetContext();
  130. return ctx.composeName(name, prefix);
  131. }
  132. public String composeName(String name, String prefix)
  133. throws NamingException {
  134. Context ctx = getTargetContext();
  135. return ctx.composeName(name, prefix);
  136. }
  137. public Object addToEnvironment(String propName, Object value)
  138. throws NamingException {
  139. Context ctx = getTargetContext();
  140. return ctx.addToEnvironment(propName, value);
  141. }
  142. public Object removeFromEnvironment(String propName)
  143. throws NamingException {
  144. Context ctx = getTargetContext();
  145. return ctx.removeFromEnvironment(propName);
  146. }
  147. public Hashtable getEnvironment() throws NamingException {
  148. Context ctx = getTargetContext();
  149. return ctx.getEnvironment();
  150. }
  151. public String getNameInNamespace() throws NamingException {
  152. Context ctx = getTargetContext();
  153. return ctx.getNameInNamespace();
  154. }
  155. public ResolveResult resolveToClass(Name name, Class contextType)
  156. throws NamingException {
  157. if (cpe.getResolvedObj() == null)
  158. throw (NamingException)cpe.fillInStackTrace();
  159. Resolver res = NamingManager.getResolver(cpe.getResolvedObj(),
  160. cpe.getAltName(),
  161. cpe.getAltNameCtx(),
  162. cpe.getEnvironment());
  163. if (res == null)
  164. throw (NamingException)cpe.fillInStackTrace();
  165. return res.resolveToClass(name, contextType);
  166. }
  167. public ResolveResult resolveToClass(String name, Class contextType)
  168. throws NamingException {
  169. if (cpe.getResolvedObj() == null)
  170. throw (NamingException)cpe.fillInStackTrace();
  171. Resolver res = NamingManager.getResolver(cpe.getResolvedObj(),
  172. cpe.getAltName(),
  173. cpe.getAltNameCtx(),
  174. cpe.getEnvironment());
  175. if (res == null)
  176. throw (NamingException)cpe.fillInStackTrace();
  177. return res.resolveToClass(name, contextType);
  178. }
  179. public void close() throws NamingException {
  180. cpe = null;
  181. if (contCtx != null) {
  182. contCtx.close();
  183. contCtx = null;
  184. }
  185. }
  186. }