コード例 #1
0
  public List<EventReply> receive() throws IOException {
    byte[] buf = new byte[0xff];
    DatagramPacket packet = new DatagramPacket(buf, 0, 0xff);
    m_dgSocket.receive(packet);
    byte[] data = packet.getData();
    //		System.out.println("receive data is : "+new String(data,"utf-8"));
    StringReader reader = new StringReader(new String(data, 0, packet.getLength(), "utf-8"));
    EventReceipt receipt = null;
    try {

      receipt = (EventReceipt) Unmarshaller.unmarshal(EventReceipt.class, reader);
    } catch (MarshalException e) {
      e.printStackTrace();
    } catch (ValidationException e) {
      e.printStackTrace();
    }

    InetAddress remoteAddr = packet.getAddress();
    int port = packet.getPort();
    List<EventReply> replys = new ArrayList<EventReply>();
    if (receipt != null) {
      String[] uuids = receipt.getUuid();
      for (String uuid : uuids) {
        EventReply reply = new EventReply(remoteAddr, port, uuid);
        replys.add(reply);
      }
    }
    return replys;
  }
コード例 #2
0
 /**
  * {@inheritDoc} Override the java.lang.equals method
  *
  * @see #equal
  */
 public boolean equals(Object object) {
   if (object instanceof RecurringDurationBase) {
     try {
       return equal((RecurringDurationBase) object);
     } catch (ValidationException e) {
       e.printStackTrace();
       return false;
     }
   }
   return false;
 }
  private PollerConfiguration getPollerConfiguration() {
    PollerConfiguration pollconfig = null;

    try {
      PollerConfigFactory.init();
      PollerConfigFactory.reload();
      pollconfig = PollerConfigFactory.getInstance().getConfiguration();
    } catch (MarshalException me) {
      me.printStackTrace();
    } catch (ValidationException ve) {
      ve.printStackTrace();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return pollconfig;
  }
  private void setPollerConfiguration(PollerConfiguration pollconfig) {
    try {
      pollconfig.validate();

      BufferedWriter bw =
          new BufferedWriter(
              new FileWriter(
                  WTProperties.getValue("SNMPConfig.directory") + "poller-configuration.xml"));
      pollconfig.marshal(bw);
      bw.flush();
      bw.close();
    } catch (MarshalException me) {
      me.printStackTrace();
    } catch (ValidationException ve) {
      ve.printStackTrace();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #5
0
ファイル: ExtensionPage.java プロジェクト: CafeGIS/gvSIG2_0
  /** Escribe sobre el config.xml, la nueva configuración. */
  public void marshalPlugins() {
    HashMap pc = Launcher.getPluginConfig();
    Iterator iter = pc.keySet().iterator();

    while (iter.hasNext()) {
      Object obj = iter.next();
      PluginConfig pconfig = (PluginConfig) pc.get(obj);
      Writer writer;

      try {
        FileOutputStream fos =
            new FileOutputStream(
                Launcher.getAndamiConfig().getPluginsDirectory()
                    + File.separator
                    + (String) obj
                    + File.separator
                    + "config.xml");
        // castor uses xerces, and xerces uses UTF-8 by default, so we should use
        // UTF-8 to create the writer, as long as we continue using castor+xerces
        writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8"));

        try {
          pconfig.marshal(writer);
        } catch (MarshalException e1) {
          e1.printStackTrace();
        } catch (ValidationException e1) {
          e1.printStackTrace();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }

      // hay que refrescar la aplicación
      /// ((App)App.instance).run();
    }
  }
コード例 #6
0
  /** {@inheritDoc} */
  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    reloadFiles();

    String query = request.getQueryString();
    if (query != null) {
      java.util.List<String> checkedList = new ArrayList<String>();
      java.util.List<String> deleteList = new ArrayList<String>();

      props.store(
          new FileOutputStream(
              ConfigFileConstants.getFile(ConfigFileConstants.POLLER_CONF_FILE_NAME)),
          null);
      StringTokenizer strTok = new StringTokenizer(query, "&");
      while (strTok.hasMoreTokens()) {
        String token = strTok.nextToken();
        if (token != null) {
          StringTokenizer keyTokens = new StringTokenizer(token, "=");
          String name = null;
          if (keyTokens.hasMoreTokens()) {
            name = (String) keyTokens.nextToken();
          }
          if (keyTokens.hasMoreTokens()) {
            String checked = (String) keyTokens.nextToken();
            if (name != null) {
              if (name.indexOf("delete") == -1) // Not to be
              // deleted
              {
                modifyPollerInfo(checked, name);
                checkedList.add(name);
              } else // Deleted
              {
                String deleteService = name.substring(0, name.indexOf("delete"));
                deleteList.add(deleteService);
              }
            }
          }
        }
      }
      adjustNonChecked(checkedList);
      deleteThese(deleteList);

      Writer poller_fileWriter =
          new OutputStreamWriter(
              new FileOutputStream(
                  ConfigFileConstants.getFile(ConfigFileConstants.POLLER_CONFIG_FILE_NAME)),
              "UTF-8");
      Writer capsd_fileWriter =
          new OutputStreamWriter(
              new FileOutputStream(
                  ConfigFileConstants.getFile(ConfigFileConstants.CAPSD_CONFIG_FILE_NAME)),
              "UTF-8");
      try {
        Marshaller.marshal(pollerConfig, poller_fileWriter);
        Marshaller.marshal(capsdConfig, capsd_fileWriter);
      } catch (MarshalException e) {
        e.printStackTrace();
        throw new ServletException(e.getMessage());
      } catch (ValidationException e) {
        e.printStackTrace();
        throw new ServletException(e.getMessage());
      }
    }

    response.sendRedirect(this.redirectSuccess);
  }