Naming_Context_Interface.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   Naming_Context_Interface.h
00006  *
00007  *  $Id: Naming_Context_Interface.h 77001 2007-02-12 07:54:49Z johnnyw $
00008  *
00009  *  @author Marina Spivak <marina@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef TAO_NAMING_CONTEXT_INTERFACE_H
00014 #define TAO_NAMING_CONTEXT_INTERFACE_H
00015 
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "orbsvcs/CosNamingS.h"
00019 
00020 #include "orbsvcs/Naming/naming_serv_export.h"
00021 #include "ace/Null_Mutex.h"
00022 
00023 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00024 
00025 class TAO_Naming_Context_Impl;
00026 
00027 // This is to remove "inherits via dominance" warnings from MSVC.
00028 #if defined (_MSC_VER)
00029 # pragma warning (disable : 4250)
00030 #endif /* _MSC_VER */
00031 
00032 /**
00033  * @class TAO_Naming_Context
00034  *
00035  * @brief This class plays a role of the 'Abstraction' (aka 'Interface')
00036  * in the Bridge pattern architecture of the CosNaming::NamingContext
00037  * implementation.
00038  *
00039  * This class simply forwards all client requests to a concrete
00040  * NamingContext implementation through its <impl_> pointer.  See
00041  * README file for more info.  Comments for the idl methods
00042  * describe methods semantics - actual actions are carried out by
00043  * concrete implementors.
00044  */
00045 
00046 class TAO_Naming_Serv_Export TAO_Naming_Context :
00047   public virtual POA_CosNaming::NamingContextExt
00048 {
00049 public:
00050 
00051   // = Initialization and termination methods.
00052   /// Constructor.  Initializes <impl_> with a concrete implementation.
00053   TAO_Naming_Context (TAO_Naming_Context_Impl *impl);
00054 
00055   /// Destructor.
00056   ~TAO_Naming_Context (void);
00057 
00058   // = CosNaming::NamingContext idl interface methods.
00059 
00060   /**
00061    * Create a binding for name <n> and object <obj> in the naming
00062    * context.  Compound names are treated as follows: ctx->bind (<c1;
00063    * c2; c3; cn>, obj) = (ctx->resolve (<c1; c2; cn-1>))->bind (<cn>,
00064    * obj) if the there already exists a binding for the specified
00065    * name, <AlreadyBound> exception is thrown.  Naming contexts should
00066    * be bound using <bind_context> and <rebind_context> in order to
00067    * participate in name resolution later.
00068    */
00069   virtual void bind (const CosNaming::Name &n,
00070                      CORBA::Object_ptr obj);
00071 
00072   /**
00073    * This is similar to <bind> operation above, except for when the
00074    * binding for the specified name already exists in the specified
00075    * context.  In that case, the existing binding is replaced with the
00076    * new one.
00077    */
00078   virtual void rebind (const CosNaming::Name &n,
00079                        CORBA::Object_ptr obj);
00080 
00081   /**
00082    * This is the version of <bind> specifically for binding naming
00083    * contexts, so that they will participate in name resolution when
00084    * compound names are passed to be resolved.
00085    */
00086   virtual void bind_context (const CosNaming::Name &n,
00087                              CosNaming::NamingContext_ptr nc);
00088 
00089   /**
00090    * This is a version of <rebind> specifically for naming contexts,
00091    * so that they can participate in name resolution when compound
00092    * names are passed.
00093    */
00094   virtual void rebind_context (const CosNaming::Name &n,
00095                                CosNaming::NamingContext_ptr nc);
00096 
00097   /**
00098    * Return object reference that is bound to the name.  Compound name
00099    * resolve is defined as follows: ctx->resolve (<c1; c2; cn>) =
00100    * ctx->resolve (<c1; c2 cn-1>)->resolve (<cn>) The naming service
00101    * does not return the type of the object.  Clients are responsible
00102    * for "narrowing" the object to the appropriate type.
00103    */
00104   virtual CORBA::Object_ptr resolve (const CosNaming::Name &n);
00105 
00106   /**
00107    * Remove the name binding from the context.  When compound names
00108    * are used, unbind is defined as follows: ctx->unbind (<c1; c2;
00109    * cn>) = (ctx->resolve (<c1; c2; cn-1>))->unbind (<cn>)
00110    */
00111   virtual void unbind (const CosNaming::Name &n);
00112 
00113 
00114   /**
00115    * This operation returns a new naming context implemented by the
00116    * same naming server in which the operation was invoked.  The
00117    * context is not bound.
00118    */
00119   virtual CosNaming::NamingContext_ptr new_context ();
00120 
00121   /**
00122    * This operation creates a new context and binds it to the name
00123    * supplied as an argument.  The newly-created context is
00124    * implemented by the same server as the context in which it was
00125    * bound (the name argument excluding the last component).
00126    */
00127   virtual CosNaming::NamingContext_ptr bind_new_context (
00128       const CosNaming::Name &n);
00129 
00130   /**
00131    * Delete the naming context.  The user should take care to <unbind> any
00132    * bindings in which the given context is bound to some names, to
00133    * avoid dangling references when invoking <destroy> operation.
00134    * NOTE: <destory> is a no-op on the root context.
00135    * NOTE: after <destroy> is invoked on a Naming Context, all
00136    * BindingIterators associated with that Naming Context are also destroyed.
00137    */
00138   virtual void destroy (void);
00139 
00140   /**
00141    * Returns at most the requested number of bindings <how_many> in
00142    * <bl>.  If the naming context contains additional bindings, they
00143    * are returned with a BindingIterator.  In the naming context does
00144    * not contain any additional bindings <bi> returned as null.
00145    */
00146   virtual void list (CORBA::ULong how_many,
00147                      CosNaming::BindingList_out bl,
00148                      CosNaming::BindingIterator_out bi);
00149 
00150   /**
00151    * Stringify the name using '\' as the escape character. The
00152    * characters '.' , '/' and '\' are to be escaped. If the input name
00153    * is invalid i.e. if the number of characters in the name is zero,
00154    * an InvalidName exception is to be raised.
00155    */
00156   virtual char * to_string (const CosNaming::Name &n);
00157 
00158   /**
00159    * The in parameter is an stringified name. This function removes the
00160    * escape character '\' and destringifies the stringified name and returns
00161    * it.
00162    */
00163   virtual CosNaming::Name * to_name (const char *sn);
00164 
00165   /**
00166    * The in parameter addr refers to the address of the naming context
00167    * and sn refers to the strigified name of the object in that
00168    * context. This function returns a fully formed URL string like
00169    * iiopname://1.1@myhost.555xyz.com:9999/a/b/c
00170    */
00171   virtual char * to_url ( const char * addr,
00172                           const char * sn);
00173 
00174   /**
00175    * Similar to <resolve> as in the CosNaming::NamingContext interface.
00176    * It accepts a strigified name as an argument instead of a Name.
00177    */
00178   virtual CORBA::Object_ptr resolve_str (const char * n);
00179 
00180   /// Returns the Default POA of this Servant object
00181   virtual PortableServer::POA_ptr _default_POA (void);
00182 
00183 private:
00184 
00185   enum Hint
00186     {
00187       HINT_ID,
00188       HINT_KIND
00189     };
00190 
00191   /**
00192    * This private function is used as a helper to <to_name>. It reads
00193    * character by character from 'src' and depending on the character,
00194    * either assigns it to 'dest' or returns back to the calling
00195    * function. If the character is a seperator between the 'id' and
00196    * 'kind' fields or a seperator between two name components, the
00197    * control is returned back to the calling function <to_name>.
00198    */
00199   void to_name_helper (char *dest, const char*& src, Hint hint);
00200 
00201   /**
00202    * This method functions similar to <to_name_helper>. If the
00203    * character read is '.' or '/' or '\', an escape character '\' is
00204    * prepended before the character.
00205    */
00206   void to_string_helper_assign (char * &k, const char * &src);
00207 
00208   /**
00209    * This method helps count the number of characters in 'src' so
00210    * that memory can be allocated for the return parameter. For
00211    * all '.' , '/' and '\', the count is incremented by 'one' to
00212    * account for the escape character that needs to be
00213    * added. Seperators between 'id' and 'kind' as well as seperators
00214    * between the name components are also counted.
00215    */
00216   void to_string_helper_length (CORBA::ULong &len, const char * &src);
00217 
00218   /// Return 1 if the character is alphanumeric or a non-scaped
00219   /// punctuation.
00220   static int to_url_is_alnum_or_punctuation (char c);
00221 
00222   /// Validate the to_url() method input, and compute the size of the
00223   /// returned URL address.
00224   static size_t to_url_validate_and_compute_size (const char *add,
00225                                                   const char *sn);
00226 
00227 protected:
00228 
00229   /// A concrete implementor of the NamingContext functions.
00230   TAO_Naming_Context_Impl *impl_;
00231 };
00232 
00233 /**
00234  * @class TAO_Naming_Context_Impl
00235  *
00236  * @brief This abstract base class plays a role of the 'Implementor' in the Bridge
00237  * pattern architecture of the NamingContext implementation.
00238  *
00239  * Subclasses of TAO_Naming_Context_Impl provide concrete
00240  * implementations of the NamingContext functionality.
00241  */
00242 class TAO_Naming_Serv_Export TAO_Naming_Context_Impl
00243 {
00244 
00245 public:
00246 
00247   /// Destructor.
00248   virtual ~TAO_Naming_Context_Impl (void);
00249 
00250   // = CosNaming::NamingContext idl interface methods.
00251 
00252   /**
00253    * Create a binding for name <n> and object <obj> in the naming
00254    * context.  Compound names are treated as follows: ctx->bind (<c1;
00255    * c2; c3; cn>, obj) = (ctx->resolve (<c1; c2; cn-1>))->bind (<cn>,
00256    * obj) if the there already exists a binding for the specified
00257    * name, <AlreadyBound> exception is thrown.  Naming contexts should
00258    * be bound using <bind_context> and <rebind_context> in order to
00259    * participate in name resolution later.
00260    */
00261   virtual void bind (const CosNaming::Name &n,
00262                      CORBA::Object_ptr obj) = 0;
00263 
00264   /**
00265    * This is similar to <bind> operation above, except for when the
00266    * binding for the specified name already exists in the specified
00267    * context.  In that case, the existing binding is replaced with the
00268    * new one.
00269    */
00270   virtual void rebind (const CosNaming::Name &n,
00271                        CORBA::Object_ptr obj) = 0;
00272 
00273   /**
00274    * This is the version of <bind> specifically for binding naming
00275    * contexts, so that they will participate in name resolution when
00276    * compound names are passed to be resolved.
00277    */
00278   virtual void bind_context (const CosNaming::Name &n,
00279                              CosNaming::NamingContext_ptr nc) = 0;
00280 
00281   /**
00282    * This is a version of <rebind> specifically for naming contexts,
00283    * so that they can participate in name resolution when compound
00284    * names are passed.
00285    */
00286   virtual void rebind_context (const CosNaming::Name &n,
00287                                CosNaming::NamingContext_ptr nc) = 0;
00288 
00289   /**
00290    * Return object reference that is bound to the name.  Compound name
00291    * resolve is defined as follows: ctx->resolve (<c1; c2; cn>) =
00292    * ctx->resolve (<c1; c2 cn-1>)->resolve (<cn>) The naming service
00293    * does not return the type of the object.  Clients are responsible
00294    * for "narrowing" the object to the appropriate type.
00295    */
00296   virtual CORBA::Object_ptr resolve (const CosNaming::Name &n) = 0;
00297 
00298   /**
00299    * Remove the name binding from the context.  When compound names
00300    * are used, unbind is defined as follows: ctx->unbind (<c1; c2;
00301    * cn>) = (ctx->resolve (<c1; c2; cn-1>))->unbind (<cn>)
00302    */
00303   virtual void unbind (const CosNaming::Name &n) = 0;
00304 
00305   /**
00306    * This operation returns a new naming context implemented by the
00307    * same naming server in which the operation was invoked.  The
00308    * context is not bound.
00309    */
00310   virtual CosNaming::NamingContext_ptr new_context (void) = 0;
00311 
00312   /**
00313    * This operation creates a new context and binds it to the name
00314    * supplied as an argument.  The newly-created context is
00315    * implemented by the same server as the context in which it was
00316    * bound (the name argument excluding the last component).
00317    */
00318   virtual CosNaming::NamingContext_ptr bind_new_context (const CosNaming::Name &n) = 0;
00319 
00320   /**
00321    * Delete the naming context.  The user should take care to <unbind> any
00322    * bindings in which the given context is bound to some names, to
00323    * avoid dangling references when invoking <destroy> operation.
00324    * NOTE: <destory> is a no-op on the root context.
00325    * NOTE: after <destroy> is invoked on a Naming Context, all
00326    * BindingIterators associated with that Naming Context are also destroyed.
00327    */
00328   virtual void destroy (void) = 0;
00329 
00330   /**
00331    * Returns at most the requested number of bindings <how_many> in
00332    * <bl>.  If the naming context contains additional bindings, they
00333    * are returned with a BindingIterator.  In the naming context does
00334    * not contain any additional bindings <bi> returned as null.
00335    */
00336   virtual void list (CORBA::ULong how_many,
00337                      CosNaming::BindingList_out &bl,
00338                      CosNaming::BindingIterator_out &bi) = 0;
00339 
00340   /// Returns the Default POA of this Servant object
00341   virtual PortableServer::POA_ptr _default_POA (void) = 0;
00342 };
00343 
00344 TAO_END_VERSIONED_NAMESPACE_DECL
00345 
00346 #include /**/ "ace/post.h"
00347 
00348 #endif /* TAO_NAMING_CONTEXT_INTERFACE_H */

Generated on Sun Jan 27 16:15:29 2008 for TAO_CosNaming by doxygen 1.3.6