/**
   * This method gets called when a property we're interested in is about to change. In case we
   * don't like the new value we throw a PropertyVetoException to prevent the actual change from
   * happening.
   *
   * @param evt a <tt>PropertyChangeEvent</tt> object describing the event source and the property
   *     that will change.
   * @exception PropertyVetoException if we don't want the change to happen.
   */
  public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
    if (evt.getPropertyName().equals(PROP_STUN_SERVER_ADDRESS)) {
      // make sure that we have a valid fqdn or ip address.

      // null or empty port is ok since it implies turning STUN off.
      if (evt.getNewValue() == null) return;

      String host = evt.getNewValue().toString();
      if (host.trim().length() == 0) return;

      boolean ipv6Expected = false;
      if (host.charAt(0) == '[') {
        // This is supposed to be an IPv6 litteral
        if (host.length() > 2 && host.charAt(host.length() - 1) == ']') {
          host = host.substring(1, host.length() - 1);
          ipv6Expected = true;
        } else {
          // This was supposed to be a IPv6 address, but it's not!
          throw new PropertyVetoException("Invalid address string" + host, evt);
        }
      }

      for (int i = 0; i < host.length(); i++) {
        char c = host.charAt(i);
        if (Character.isLetterOrDigit(c)) continue;

        if ((c != '.' && c != ':') || (c == '.' && ipv6Expected) || (c == ':' && !ipv6Expected))
          throw new PropertyVetoException(host + " is not a valid address nor host name", evt);
      }

    } // is prop_stun_server_address
    else if (evt.getPropertyName().equals(PROP_STUN_SERVER_PORT)) {

      // null or empty port is ok since it implies turning STUN off.
      if (evt.getNewValue() == null) return;

      String port = evt.getNewValue().toString();
      if (port.trim().length() == 0) return;

      try {
        Integer.valueOf(evt.getNewValue().toString());
      } catch (NumberFormatException ex) {
        throw new PropertyVetoException(port + " is not a valid port! " + ex.getMessage(), evt);
      }
    }
  }
Beispiel #2
0
  public VirtualMachine attach(Map arguments)
      throws IOException, IllegalConnectorArgumentsException {
    int pid = 0;
    try {
      pid = Integer.parseInt(argument(ARG_PID, arguments).value());
    } catch (NumberFormatException nfe) {
      throw (IllegalConnectorArgumentsException)
          new IllegalConnectorArgumentsException(nfe.getMessage(), ARG_PID).initCause(nfe);
    }

    checkProcessAttach(pid);

    VirtualMachine myVM = null;
    try {
      try {
        Class vmImplClass = loadVirtualMachineImplClass();
        myVM = createVirtualMachine(vmImplClass, pid);
      } catch (InvocationTargetException ite) {
        Class vmImplClass = handleVMVersionMismatch(ite);
        if (vmImplClass != null) {
          return createVirtualMachine(vmImplClass, pid);
        } else {
          throw ite;
        }
      }
    } catch (Exception ee) {
      if (DEBUG) {
        System.out.println("VirtualMachineImpl() got an exception:");
        ee.printStackTrace();
        System.out.println("pid = " + pid);
      }
      throw (IOException) new IOException().initCause(ee);
    }
    setVMDisposeObserver(myVM);
    return myVM;
  }