Ejemplo n.º 1
0
 private void prepareConfigData(Packet result, String comp_name) throws ConfigurationException {
   if (comp_name.equals("--none--")) {
     newComponentCommand(result);
     return;
   } // end of if (comp_name.equals("--none--"))
   Command.setStatus(result, Command.Status.executing);
   Command.addAction(result, Command.Action.complete);
   // Let's try to sort them to make it easier to find options on
   // configuration page.
   Map<String, Object> allprop = new TreeMap<String, Object>(getAllProperties(comp_name));
   for (Map.Entry<String, Object> entry : allprop.entrySet()) {
     Command.addFieldValue(
         result,
         XMLUtils.escape(entry.getKey()),
         XMLUtils.escape(objectToString(entry.getValue())));
   } // end of for (Map.Entry entry: prop.entrySet())
   Command.addFieldValue(
       result,
       XMLUtils.escape("new-prop-name"),
       XMLUtils.escape(comp_name + "/"),
       "text-single",
       "New property name");
   Command.addFieldValue(
       result, XMLUtils.escape("new-prop-value"), "", "text-single", "New property value");
 }
Ejemplo n.º 2
0
 private void newComponentCommand(Packet result) {
   Command.addFieldValue(result, "Info", "Press:", "fixed");
   Command.addFieldValue(
       result, "Info", "'Next' to set all parameters for the new component.", "fixed");
   Command.setStatus(result, Command.Status.executing);
   Command.addAction(result, Command.Action.next);
   Command.addFieldValue(result, "Component name", "", "text-single", "Component name");
   try {
     Set<Class<MessageReceiver>> receiv_cls =
         ClassUtil.getClassesImplementing(MessageReceiver.class);
     // All message receivers except MessageRouter
     String[] receiv_cls_names = new String[receiv_cls.size() - 1];
     String[] receiv_cls_simple = new String[receiv_cls.size() - 1];
     int idx = 0;
     for (Class<MessageReceiver> reciv : receiv_cls) {
       if (!reciv.getName().equals(ROUTER_COMP_CLASS_NAME)) {
         receiv_cls_names[idx] = reciv.getName();
         receiv_cls_simple[idx++] = reciv.getSimpleName();
       } // end of if (!reciv.getName().equals(ROUTER_COMP_CLASS_NAME))
     } // end of for (MessageReceiver.class reciv: receiv_cls)
     Command.addFieldValue(
         result,
         "Component class",
         EXT_COMP_CLASS_NAME,
         "Component class",
         receiv_cls_simple,
         receiv_cls_names);
   } catch (Exception e) {
     log.log(Level.SEVERE, "Problem loading MessageReceiver implementations", e);
     Command.addFieldValue(
         result,
         "Component class",
         "ERROR!! Problem loading MessageReceiver implementations, "
             + "look in log file for details...",
         "text-single",
         "Component class");
   } // end of try-catch
 }
Ejemplo n.º 3
0
 private void newComponentCommand(Packet packet, Packet result, boolean admin) {
   String params_set = Command.getFieldValue(packet, "Params set");
   if (Command.getAction(packet) != null && Command.getAction(packet).equals("prev")) {
     newComponentCommand(result);
     return;
   } // end of if ()
   if (params_set != null) {
     createNewComponent(packet, result, admin);
     return;
   } // end of if (params_set != null)
   String new_comp_name = Command.getFieldValue(packet, "Component name");
   String new_comp_class = Command.getFieldValue(packet, "Component class");
   if (!checkComponentName(result, new_comp_name)) {
     return;
   } // end of if (!checkComponentName(new_comp_name))
   Command.setStatus(result, Command.Status.executing);
   Command.addFieldValue(result, "Component name", new_comp_name, "hidden");
   Command.addFieldValue(result, "Component class", new_comp_class, "hidden");
   Command.addFieldValue(result, "Info1", "Press:", "fixed");
   try {
     MessageReceiver mr = (MessageReceiver) Class.forName(new_comp_class).newInstance();
     Command.addFieldValue(
         result,
         "Info4",
         "Component name: " + new_comp_name + ", class: " + mr.getClass().getSimpleName(),
         "fixed");
     if (mr instanceof ConnectionManager) {
       String ports = Command.getFieldValue(packet, "TCP/IP ports");
       if (ports == null) {
         Command.addFieldValue(
             result, "Info2", "1. 'Next' to set more component parameters.", "fixed");
         Command.addFieldValue(
             result, "Info3", "2. 'Previous' to go back and select different component.", "fixed");
         Command.addAction(result, Command.Action.next);
         Command.addAction(result, Command.Action.prev);
         Command.addFieldValue(
             result,
             "Info4",
             "This component uses TCP/IP ports, please provide port numbers:",
             "fixed");
         Command.addFieldValue(result, "TCP/IP ports", "5557");
         return;
       } else {
         String[] ports_arr = ports.split(",");
         int[] ports_i = new int[ports_arr.length];
         try {
           for (int i = 0; i < ports_arr.length; i++) {
             ports_i[i] = Integer.decode(ports_arr[i].trim());
           } // end of for (int i = 0; i < ports_arr.length; i++)
           defConfigParams.put(new_comp_name + "/connections/ports", ports_i);
         } catch (Exception e) {
           Command.addFieldValue(
               result, "Info2", "1. 'Next' to set more component parameters.", "fixed");
           Command.addFieldValue(
               result,
               "Info3",
               "2. 'Previous' to go back and select different component.",
               "fixed");
           Command.addAction(result, Command.Action.next);
           Command.addAction(result, Command.Action.prev);
           Command.addFieldValue(
               result,
               "Info4",
               "Incorrect TCP/IP ports provided, please provide port numbers:",
               "fixed");
           Command.addFieldValue(result, "TCP/IP ports", ports);
           return;
         } // end of try-catch
       } // end of else
     }
     Command.addFieldValue(
         result, "Info2", "1. 'Finish' to create component with this parameters.", "fixed");
     Command.addFieldValue(
         result, "Info3", "2. 'Previous' to go back and select different component.", "fixed");
     Command.addAction(result, Command.Action.complete);
     Command.addAction(result, Command.Action.prev);
     mr.setName(new_comp_name);
     if (mr instanceof Configurable) {
       // Load defaults into sorted Map:
       Map<String, Object> comp_props =
           new TreeMap<String, Object>(((Configurable) mr).getDefaults(defConfigParams));
       for (Map.Entry<String, Object> entry : comp_props.entrySet()) {
         Command.addFieldValue(
             result,
             XMLUtils.escape(entry.getKey()),
             XMLUtils.escape(objectToString(entry.getValue())));
       } // end of for (Map.Entry entry: prop.entrySet())
     } else {
       Command.addFieldValue(
           result, "Info6", "Component is not configurable, do you want to create it?", "fixed");
     } // end of else
     Command.addFieldValue(result, "Params set", "true", "hidden");
   } catch (Exception e) {
     log.log(Level.SEVERE, "Problem instantiating component:", e);
     Command.addFieldValue(
         result,
         "Component class",
         "ERROR!! Problem instantiating component, " + "look in log file for details...",
         "text-single",
         "Component class");
   } // end of try-catch
 }