예제 #1
0
  public void rebind(Name name, Object obj) throws NamingException {
    if (name.size() == 0) throw new NamingException(L.l("can't bind root"));

    AbstractModel model = _model;

    int i = 0;
    for (; i + 1 < name.size(); i++) {
      String first = name.get(i);

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        continue;
      }

      value = dereference(value, null, model);

      if (value instanceof Context) {
        ((Context) value).bind(name.getSuffix(i + 1), obj);
        return;
      } else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }

    String first = name.get(i);

    if (obj == null) obj = NullValue.NULL;

    model.bind(first, getReference(model, obj));
  }
 public void bind(String name, Object obj) throws NamingException {
   ResolveResult res = getRootURLContext(name, myEnv);
   Context ctx = (Context) res.getResolvedObj();
   try {
     ctx.bind(res.getRemainingName(), obj);
   } finally {
     ctx.close();
   }
 }
 public void bind(Name name, Object obj) throws NamingException {
   if (name.size() == 1) {
     bind(name.get(0), obj);
   } else {
     Context ctx = getContinuationContext(name);
     try {
       ctx.bind(name.getSuffix(1), obj);
     } finally {
       ctx.close();
     }
   }
 }
예제 #4
0
  public static void foo() throws Exception {
    String url = "iiop://localhost:2809";
    //  		String url = "corbaloc:iiop:localhost:2809";
    // String factory = "com.ibm.ejs.ns.jndi.CNInitialContextFactory";
    String factory = "com.ibm.websphere.naming.WsnInitialContextFactory";

    Properties prop = new Properties();
    prop.put(Context.INITIAL_CONTEXT_FACTORY, factory);
    prop.put(Context.PROVIDER_URL, url);
    // prop.put("java.naming.factory.url.pkgs","com.ibm.websphere.naming");
    Context ctx = new InitialContext(prop);
    ctx.bind("test", new String("test"));
    String s = (String) ctx.lookup("test");
    ctx.unbind("test");
    System.out.println("\nEnd Mytest session.Client...\n");
  }
예제 #5
0
  /** Binds an object to the context. */
  public void bind(String name, Object obj) throws NamingException {
    String tail = name;
    AbstractModel model = _model;

    if (obj == null) obj = NullValue.NULL;

    while (true) {
      String first = parseFirst(tail);
      String rest = parseRest(tail);

      if (first == null) throw new NamingException(L.l("can't bind root"));

      if (rest == null) {
        Object value = model.lookup(first);

        if (value != null)
          throw new NamingException(L.l("`{0}' is already bound to `{1}'", name, value));

        model.bind(first, getReference(model, obj));

        return;
      }

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        tail = rest;
        continue;
      }

      value = dereference(value, null, model);

      if (value instanceof Context) {
        ((Context) value).bind(rest, obj);
        return;
      } else if (value != null) {
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      } else {
        throw new NameNotFoundException(getFullPath(name));
      }
    }
  }
예제 #6
0
  public static void main(String[] args) throws RemoteException, NamingException {
    /*System.setProperty("java.security", "server.policy");
    System.setSecurityManager(new SecurityManager());*/

    System.out.println("创建服务器端实现...");

    WareHouseImpl backupWS = new WareHouseImpl(null);
    WareHouseImpl wareHouse1 = new WareHouseImpl(backupWS);

    wareHouse1.add("garmin", new Product("garmin 110", 200.0));
    backupWS.add("java", new Book("Core Java", 30.0, "1234565"));

    System.out.println("绑定服务端实现到注册表...");
    /*创建一个命名上下文,用来访问RMI注册表*/
    Context namingContext = new InitialContext();

    // 解决端口没有注册,connection refused的问题

    LocateRegistry.createRegistry(1099);
    namingContext.bind("rmi://localhost:1099/wareHouseNO1", wareHouse1);
    System.out.println("等待远程客户端调用...");
  }