Esempio n. 1
0
  public void deleteServer(Object server) {
    String id = ((Server) server).getName();
    Server serverIns = (Server) server;
    DOMConfigurator config = null;
    try {
      Bundle bundle = Platform.getBundle(Application.PLUGIN_ID);
      URL fileURL = FileLocator.toFileURL(BundleUtility.find(bundle, "configuration/nabee.xml"));

      config = new DOMConfigurator(fileURL.getPath());

      config.deleteConf("monitor/server", id);

      if (serverIns.getConnect().isConnect()) serverIns.getConnect().getProtocol()._close();

    } catch (ParserConfigurationException e) {
      IMessageBox.Error(shell, NBLabel.get(0x008F));
      return;
    } catch (TransformerException e) {
      IMessageBox.Error(shell, NBLabel.get(0x008F));
      return;
    } catch (IOException e) {
      IMessageBox.Error(shell, NBLabel.get(0x008F));
      return;
    } catch (SAXException e) {
      IMessageBox.Error(shell, NBLabel.get(0x008F));
      return;
    } catch (Exception e) {
      IMessageBox.Error(shell, NBLabel.get(0x008F));
      return;
    }

    serverIns.getParent().removeChild(id);
    treeViewer.refresh();
  }
Esempio n. 2
0
  public void addServer(HashMap<String, String> params) {
    Model root = (Model) treeViewer.getInput();
    Server server =
        new Server(
            root,
            params.get("SERVER_NAME"),
            Activator.getImageDescriptor("/icons/disconserver.gif").createImage(display));
    ServerConnect serverConnect =
        new ServerConnect(
            NBLabel.get(0x0099) + " : " + NBLabel.get(0x0098),
            Activator.getImageDescriptor("/icons/net_connect.gif").createImage(display));

    serverConnect.setChannel(params.get("IP_MONADDRESS"));
    serverConnect.setChannelPort(
        Integer.parseInt(params.get("MONPORT").equals("") ? "0" : params.get("MONPORT")));
    serverConnect.setHostAddr(params.get("IP_ADDRESS"));
    serverConnect.setHostPort(
        Integer.parseInt(params.get("PORT").equals("") ? "0" : params.get("PORT")));
    serverConnect.setServerEncoding(params.get("ENCODING"));
    serverConnect.setUser(params.get("USER"));

    server.setConnection(serverConnect);

    if (!params.get("SAVE_FLAG").equals("")) serverConnect.setPassword(params.get("PASSWORD"));

    treeViewer.insert(root, server, -1);
    treeViewer.refresh();
  }
Esempio n. 3
0
  public void disconnectServer(boolean needAlert) {
    if (needAlert && IMessageBox.Confirm(shell, NBLabel.get(0x0094)) != SWT.OK) return;

    Server server = null;
    IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();

    if (selection.getFirstElement() instanceof Server) {
      server = (Server) selection.getFirstElement();
    } else {
      IMessageBox.Error(shell, NBLabel.get(0x0091));
      return;
    }

    closeConnection(server);
  }
Esempio n. 4
0
  public void openInstanceView(
      String serverName, InstanceList instanceList, NBFields netFields, Server server) {
    try {
      ArrayList<Boolean> runStateList = new ArrayList<Boolean>();
      if (netFields != null) {
        @SuppressWarnings("unchecked")
        ArrayList<NBFields> nList = (ArrayList<NBFields>) netFields.get("INSTANCE_LIST");
        ArrayList<String> iList = new ArrayList<String>();

        try {
          for (int i = 0; i < nList.size(); i++) {
            iList.add((String) nList.get(i).get("INSTANCE_NAME"));
            runStateList.add(((String) nList.get(i).get("RUNNING")).equals("true"));
          }
          instanceList.setList(iList);
        } catch (NullPointerException e) {
        }
      }

      IPCProtocol protocol = server.getConnect().getProtocol();

      InstanceView instanceView = (InstanceView) getSite().getPage().showView(InstanceView.ID);
      instanceView.setProtocol(protocol);
      instanceView.setPartName(serverName);
      instanceView.setInstance(serverName, instanceList.getList(), runStateList);
      instanceView.setPartProperty("SERVER_NAME", serverName);
      instanceView.setServer(server);
    } catch (PartInitException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0096));
    }
  }
Esempio n. 5
0
  @Override
  public void createPartControl(Composite parent) {
    setPartName(NBLabel.get(0x0050));
    this.display = parent.getDisplay();
    this.shell = parent.getShell();

    treeViewer = new TreeViewer(parent, SWT.NONE);
    getSite().setSelectionProvider(treeViewer);

    treeViewer.setContentProvider(new NBContentProvider());
    treeViewer.setLabelProvider(new NBLabelProvider(parent.getDisplay()));
    treeViewer.setUseHashlookup(true);

    registContextMenu(parent);
    addRetargetableAction(parent);

    treeViewer.addDoubleClickListener(genDbClickListener());
    treeViewer.addSelectionChangedListener(genSelectChangedListener());

    treeViewer.setInput(ResourceFactory.getServerRoot());
  }
Esempio n. 6
0
  private boolean controlServer(int messageType, IPCProtocol protocol) {
    NBFields fields = new NBFields();

    fields.put(IPC.NB_MSG_TYPE, messageType);
    fields.put(IPC.NB_LOAD_CLASS, "com.nabsys.management.server.ControlServer");

    try {

      fields = protocol.execute(fields);

      if ((Integer) fields.get(IPC.NB_MSG_RETURN) == IPC.FAIL) {
        IMessageBox.Error(shell, (String) fields.get("RTN_MSG"));
        return false;
      } else {
        return true;
      }
    } catch (SocketClosedException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      closeConnection();
      return false;
    } catch (TimeoutException e) {
      IMessageBox.Error(shell, e.getMessage());
      return false;
    } catch (NetException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      closeConnection();
      return false;
    } catch (UnsupportedEncodingException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      closeConnection();
      return false;
    } catch (NoSuchAlgorithmException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      closeConnection();
      return false;
    } catch (DataTypeException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      closeConnection();
      return false;
    } catch (ProtocolException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      closeConnection();
      return false;
    }
  }
Esempio n. 7
0
  private NBFields getServerConfigInfo(IPCProtocol protocol) {
    NBFields fields = new NBFields();
    fields.put(IPC.NB_LOAD_CLASS, "com.nabsys.management.server.ServerConfig");
    fields.put("CMD_CODE", "R");

    try {
      fields = protocol.execute(fields);

      if ((Integer) fields.get(IPC.NB_MSG_RETURN) == IPC.FAIL) {
        IMessageBox.Error(shell, (String) fields.get("RTN_MSG"));
      }
    } catch (SocketClosedException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      closeConnection();
      fields = null;
    } catch (TimeoutException e) {
      IMessageBox.Error(shell, e.getMessage());
      fields = null;
    } catch (NetException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      closeConnection();
      fields = null;
    } catch (UnsupportedEncodingException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      closeConnection();
      fields = null;
    } catch (NoSuchAlgorithmException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      closeConnection();
      fields = null;
    } catch (DataTypeException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      closeConnection();
      fields = null;
    } catch (ProtocolException e) {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      closeConnection();
      fields = null;
    }

    return fields;
  }
Esempio n. 8
0
  private void registContextMenu(Composite parent) {
    IWorkbenchWindow window = getSite().getWorkbenchWindow();

    IWorkbenchAction renameAction = ActionFactory.RENAME.create(window);
    renameAction.setToolTipText(NBLabel.get(0x006B));
    renameAction.setText(NBLabel.get(0x006E));

    IWorkbenchAction refreshAction = ActionFactory.REFRESH.create(window);
    refreshAction.setToolTipText(NBLabel.get(0x025F));
    refreshAction.setText(NBLabel.get(0x0260));

    IWorkbenchAction deleteAction = ActionFactory.DELETE.create(window);
    deleteAction.setToolTipText(NBLabel.get(0x0062));
    deleteAction.setText(NBLabel.get(0x0068));

    MenuManager newMgr = new MenuManager("&New                    ", "file.mnuNew");
    newMgr.add(new NewServerAction(window));
    newMgr.add(new Separator());
    newMgr.add(new GroupMarker("file.new.OTHERS"));

    MenuManager mgr = new MenuManager();
    mgr.add(newMgr);
    mgr.add(new Separator());
    mgr.add(ResourceFactory.CONNECT.create(window));
    mgr.add(ResourceFactory.DISCONNECT.create(window));
    mgr.add(new Separator());
    mgr.add(refreshAction);
    mgr.add(new Separator());
    mgr.add(deleteAction);
    mgr.add(renameAction);
    mgr.add(new Separator());
    mgr.add(new PropertyAction(window));

    Menu menu = mgr.createContextMenu(parent);
    treeViewer.getTree().setMenu(menu);
  }
Esempio n. 9
0
  public boolean connectServer(HashMap<String, String> params) {
    ServerConnect connect = null;
    Server server = null;

    if (!treeViewer.getSelection().isEmpty()) {
      IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();

      if (selection.getFirstElement() instanceof Server) {
        server = (Server) selection.getFirstElement();
        connect = server.getConnect();
      } else {
        IMessageBox.Error(shell, NBLabel.get(0x0090));
        return true;
      }

      if (params.containsKey("SAVE_FLAG") && params.get("SAVE_FLAG").equals("true"))
        connect.setPassword(params.get("PASSWORD"));

      params.put("IP_ADDRESS", connect.getHostAddr());
      params.put("PORT", Integer.toString(connect.getHostPort()));
      params.put("ENCODING", connect.getServerEncoding());
    } else if (params.containsKey("SERVER_NAME")) {
      String serverName = params.get("SERVER_NAME");

      ArrayList<Model> children = ((Model) treeViewer.getInput()).getChildren();
      for (int i = 0; i < children.size(); i++) {
        if (serverName.equals(children.get(i).getName())) {
          server = (Server) children.get(i);
          connect = ((Server) children.get(i)).getConnect();
        }
      }

    } else {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      return true;
    }

    try {
      Socket socket =
          new Socket(params.get("IP_ADDRESS"), Integer.parseInt(params.get("PORT")), 4096, 30);

      InstanceHeaderFields fields = new InstanceHeaderFields();
      fields.put(
          "LENGTH", new TelegramFieldContext("LENGTH", "LENGTH", 0, 4, true, ' ', ' ', 'I', ""));
      fields.put(
          "MSG_TYPE",
          new TelegramFieldContext("MSG_TYPE", "MSG_TYPE", 1, 4, true, ' ', ' ', 'I', ""));
      fields.put(
          "RETURN", new TelegramFieldContext("RETURN", "RETURN", 2, 4, true, ' ', ' ', 'I', ""));
      fields.setLengthFieldIndex("LENGTH");
      fields.setMsgTypeFieldIndex("MSG_TYPE");
      fields.setReturnFieldIndex("RETURN");

      IPCProtocol protocol =
          new IPCProtocol(
              socket, params.get("USER"), params.get("PASSWORD"), fields, params.get("ENCODING"));
      connect.setProtocol(protocol);

      NBFields netFields = new NBFields();
      netFields.put(IPC.NB_LOAD_CLASS, "com.nabsys.management.instance.InstanceConfig");
      netFields.put("CMD_CODE", "L");

      netFields = protocol.execute(netFields);

      if (protocol.getUserAuthority().equals("Admin")) {
        new ServerConfig(
            server,
            NBLabel.get(0x0049),
            Activator.getImageDescriptor("/icons/config_obj.gif").createImage(display));
        new UserList(
            server,
            NBLabel.get(0x009D),
            Activator.getImageDescriptor("/icons/user_view.gif").createImage(display));
        new InstanceList(
            server,
            NBLabel.get(0x0093),
            Activator.getImageDescriptor("/icons/pview.gif").createImage(display));
        terminateAction.setEnabled(true);
      } else if (protocol.getUserAuthority().equals("Operator")) {
        new UserList(
            server,
            NBLabel.get(0x009D),
            Activator.getImageDescriptor("/icons/user_view.gif").createImage(display));
        new InstanceList(
            server,
            NBLabel.get(0x0093),
            Activator.getImageDescriptor("/icons/pview.gif").createImage(display));
      } else if (protocol.getUserAuthority().equals("Developer")) {
        new InstanceList(
            server,
            NBLabel.get(0x0093),
            Activator.getImageDescriptor("/icons/pview.gif").createImage(display));
      }

      server.setImage(Activator.getImageDescriptor("/icons/conserver.gif").createImage(display));
      treeViewer.refresh();

      connectAction.setEnabled(false);
      disconnectAction.setEnabled(true);

      treeViewer.expandToLevel(server, 1);

      openInstanceView(server.getName(), server.getInstance(), netFields, server);

    } catch (NumberFormatException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (NetException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return false;
    } catch (SocketClosedException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (ClassNotFoundException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (TimeoutException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return false;
    } catch (UnsupportedEncodingException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (NoSuchAlgorithmException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (DataTypeException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (ProtocolException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (Exception e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    }
    return true;
  }