1 Reply Latest reply on Jul 22, 2002 10:19 AM by Ludovico Basili

    Identify an object as local or remote

    Ludovico Basili Newbie

      Hello,
      in my application, EJBs and client application use value-objects to exchange data.
      These value-objects encapsulate a java.util.HashMap instance and have the following methods to read and write.

      public void set(propName,propVal);
      public Object get(propName);

      Now, I would like to modify the implementation of the above methods.
      I would like them to have a different behavior depending on the fact that they are invoked on the server or on the client.
      In particular, if they are invoked on the client, I want them to check a permission on a map, if they are invoked on the server, the Hashmap is directly accessed.
      I thought at the following implementation:

      public void set(String propName,Object val){
      try {
      Context ctx = new InitialContext();
      Object visibleOnlyOnServer = ctx.lookup("java:/foo");
      // If I am here I should be on the server
      myHashMap.put(propName,val);
      }catch(NamingException ne){
      // I am on the client, because I cannot lookup
      // the object, so check permissions first.
      if (null!=permissionMap.get(propName)){
      myHashMap.put(propName,val);
      }else{
      throw new RuntimeException("Operation not allowed");
      }
      }
      }


      Thanks for paying attention,
      Ludovico Basili