1. /*
  2. * @(#)ContinuationContext.java 1.9 04/05/05
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.naming.spi;
  8. import java.util.Hashtable;
  9. import javax.naming.*;
  10. /**
  11. * This class is for dealing with federations/continuations.
  12. *
  13. * @author Rosanna Lee
  14. * @author Scott Seligman
  15. * @version 1.9 04/05/05
  16. * @since 1.3
  17. */
  18. class ContinuationContext implements Context, Resolver {
  19. protected CannotProceedException cpe;
  20. protected Hashtable env;
  21. protected Context contCtx = null;
  22. protected ContinuationContext(CannotProceedException cpe,
  23. Hashtable env) {
  24. this.cpe = cpe;
  25. this.env = env;
  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. env);
  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)
  89. throws NamingException
  90. {
  91. Context ctx = getTargetContext();
  92. return ctx.listBindings(name);
  93. }
  94. public NamingEnumeration listBindings(String name) throws NamingException {
  95. Context ctx = getTargetContext();
  96. return ctx.listBindings(name);
  97. }
  98. public void destroySubcontext(Name name) throws NamingException {
  99. Context ctx = getTargetContext();
  100. ctx.destroySubcontext(name);
  101. }
  102. public void destroySubcontext(String name) throws NamingException {
  103. Context ctx = getTargetContext();
  104. ctx.destroySubcontext(name);
  105. }
  106. public Context createSubcontext(Name name) throws NamingException {
  107. Context ctx = getTargetContext();
  108. return ctx.createSubcontext(name);
  109. }
  110. public Context createSubcontext(String name) throws NamingException {
  111. Context ctx = getTargetContext();
  112. return ctx.createSubcontext(name);
  113. }
  114. public Object lookupLink(Name name) throws NamingException {
  115. Context ctx = getTargetContext();
  116. return ctx.lookupLink(name);
  117. }
  118. public Object lookupLink(String name) throws NamingException {
  119. Context ctx = getTargetContext();
  120. return ctx.lookupLink(name);
  121. }
  122. public NameParser getNameParser(Name name) throws NamingException {
  123. Context ctx = getTargetContext();
  124. return ctx.getNameParser(name);
  125. }
  126. public NameParser getNameParser(String name) throws NamingException {
  127. Context ctx = getTargetContext();
  128. return ctx.getNameParser(name);
  129. }
  130. public Name composeName(Name name, Name prefix)
  131. throws NamingException
  132. {
  133. Context ctx = getTargetContext();
  134. return ctx.composeName(name, prefix);
  135. }
  136. public String composeName(String name, String prefix)
  137. throws NamingException {
  138. Context ctx = getTargetContext();
  139. return ctx.composeName(name, prefix);
  140. }
  141. public Object addToEnvironment(String propName, Object value)
  142. throws NamingException {
  143. Context ctx = getTargetContext();
  144. return ctx.addToEnvironment(propName, value);
  145. }
  146. public Object removeFromEnvironment(String propName)
  147. throws NamingException {
  148. Context ctx = getTargetContext();
  149. return ctx.removeFromEnvironment(propName);
  150. }
  151. public Hashtable getEnvironment() throws NamingException {
  152. Context ctx = getTargetContext();
  153. return ctx.getEnvironment();
  154. }
  155. public String getNameInNamespace() throws NamingException {
  156. Context ctx = getTargetContext();
  157. return ctx.getNameInNamespace();
  158. }
  159. public ResolveResult
  160. resolveToClass(Name name, Class<? extends Context> contextType)
  161. throws NamingException
  162. {
  163. if (cpe.getResolvedObj() == null)
  164. throw (NamingException)cpe.fillInStackTrace();
  165. Resolver res = NamingManager.getResolver(cpe.getResolvedObj(),
  166. cpe.getAltName(),
  167. cpe.getAltNameCtx(),
  168. env);
  169. if (res == null)
  170. throw (NamingException)cpe.fillInStackTrace();
  171. return res.resolveToClass(name, contextType);
  172. }
  173. public ResolveResult
  174. resolveToClass(String name, Class<? extends Context> contextType)
  175. throws NamingException
  176. {
  177. if (cpe.getResolvedObj() == null)
  178. throw (NamingException)cpe.fillInStackTrace();
  179. Resolver res = NamingManager.getResolver(cpe.getResolvedObj(),
  180. cpe.getAltName(),
  181. cpe.getAltNameCtx(),
  182. env);
  183. if (res == null)
  184. throw (NamingException)cpe.fillInStackTrace();
  185. return res.resolveToClass(name, contextType);
  186. }
  187. public void close() throws NamingException {
  188. cpe = null;
  189. env = null;
  190. if (contCtx != null) {
  191. contCtx.close();
  192. contCtx = null;
  193. }
  194. }
  195. }