Package jade.util

Examples of jade.util.ExtendedProperties


   * ACLMessages for subscription and unsubscription as <em>rma</em> are created and
   * corresponding behaviours are set up.
   */
  public void toolSetup() {

    properties = new ExtendedProperties();

    /*
     * preload agents from argument array if arguments present, otherwise load
     * sniffer.properties file.
     */
 
View Full Code Here


   * Construct default profile with empty argument properties
   */
  public BootProfileImpl() {
    // creates the default profile
    super(true);
    argProp = new ExtendedProperties();
  }
View Full Code Here

   * Construct profile with specified arguments
   * @param args Boot arguments
   */
  public BootProfileImpl(String[] args) throws PropertiesException {
    this();
    ExtendedProperties properties = new ExtendedProperties(args);
    bootProps = (Properties)properties.clone();
    setArgProperties(properties);
  }       
View Full Code Here

    boolean flag = false;


    // Transfer argument properties into profile properties

    ExtendedProperties profileProp = (ExtendedProperties)getProperties();

    boolean isMain = true;
    if (argProp.getProperty(Profile.MAIN) != null) {
      isMain = fetchAndVerifyBoolean(Profile.MAIN);
    }
    else {
      isMain = !fetchAndVerifyBoolean(CONTAINER_KEY);
    }
    if (isMain) {
      profileProp.setProperty(Profile.MAIN, "true");
    }
    else {
      profileProp.setProperty(Profile.MAIN, "false");
      // Since the value is false, we cancel the default done in ProfileImpl's constructor
      setSpecifiers(Profile.MTPS, new ArrayList(0)); // remove default MTP
    }

    String sm = argProp.getProperty(LOCAL_SERVICE_MANAGER);
    if(sm != null) {
      profileProp.setProperty(Profile.LOCAL_SERVICE_MANAGER, sm);
    }

    /* PER IL DF
        value = argProp.getProperty(df.KBDF_MAX_RESULTS);
        if (value != null) {
            profileProp.setProperty(df.KBDF_MAX_RESULTS, value);
        }
        value = argProp.getProperty(df.DBDF_DRIVER);
        if (value != null) {
            profileProp.setProperty(df.DBDF_DRIVER, value);
        }
        value = argProp.getProperty(df.DBDF_URL);
        if (value != null) {
            profileProp.setProperty(df.DBDF_URL, value);
        }*/

    /*
        value = argProp.getProperty(PASSWD_KEY);
        if (value != null) {
            //profileProp.setProperty(Profile.PASSWD_FILE, value);
        }
     */

    value = argProp.getProperty(IMTP);
    if (value != null) {
      profileProp.setProperty(Profile.IMTP, value);
    }

    String host = argProp.getProperty(MAIN_HOST);
    if (host != null) {
      profileProp.setProperty(Profile.MAIN_HOST, host);
    } else {
      host = profileProp.getProperty(Profile.MAIN_HOST);
      if (host == null) {
        host = getDefaultNetworkName();
        profileProp.setProperty(Profile.MAIN_HOST, host);
      }
    }

    String port = argProp.getProperty(MAIN_PORT);
    if (port == null) {
      // Default for a sole main container: use the local port, or
      // the default port if also the local port is null.
      if(isMasterMain()) {
        port = argProp.getProperty(LOCAL_PORT);
      }
      if(port == null) {
        // All other cases: use the default port.
        port = Integer.toString(DEFAULT_PORT);
      }
    }
    profileProp.setProperty(Profile.MAIN_PORT, port);

    String localHost = argProp.getProperty(LOCAL_HOST);
    if(localHost == null) {
      // Default for a sole main container: use the MAIN_HOST property
      if(isMasterMain()) {
        localHost = host;
      }
      else {
        // Default for a peripheral container or an added main container: use the local host
        localHost = getDefaultNetworkName();
      }
    }
    profileProp.setProperty(Profile.LOCAL_HOST, localHost);

    String localPort = argProp.getProperty(LOCAL_PORT);
    if(localPort == null) {
      // Default for a sole main container: use the MAIN_PORT property
      if(isMasterMain()) {
        localPort = port;
      }
      else {
        // Default for a peripheral container or an added main container: use the default port
        localPort = Integer.toString(DEFAULT_PORT);
      }
    }
    profileProp.setProperty(Profile.LOCAL_PORT, localPort);

    value = argProp.getProperty(REMOTE_SERVICE_MANAGER_ADDRESSES);
    if (value != null) {
      try {
        Vector v = Specifier.parseSpecifierList(value);
        // Convert the Vector into a List
        List l = new ArrayList(v.size());
        Enumeration e = v.elements();
        while (e.hasMoreElements()) {
          l.add(e.nextElement());
        }
        setSpecifiers(Profile.REMOTE_SERVICE_MANAGER_ADDRESSES, l);
      }
      catch(Exception e) {
        e.printStackTrace();
      }
    }

    value = argProp.getProperty(NAME_KEY);
    if (value != null) {
      profileProp.setProperty(Profile.PLATFORM_ID, value);
   

    value = argProp.getProperty(LOGIN_KEY);
    if (value != null) {
      profileProp.setProperty(Profile.USERAUTH_KEY, value);
   

    value = argProp.getProperty(MTP_KEY);
    if (value != null) {
      setSpecifiers(Profile.MTPS, parseSpecifiers(value));
    }

    //NOMTP
    flag = fetchAndVerifyBoolean(NOMTP_KEY);
    if (flag) {
      // Since the value was set to true, cancel the MTP settings
      setSpecifiers(Profile.MTPS, new ArrayList(0));
    }

    value = argProp.getProperty(ACLCODEC_KEY);
    if (value != null) {
      setSpecifiers(Profile.ACLCODECS, parseSpecifiers(value));
    }

    // Get agent list (if any)
    value = argProp.getProperty(AGENTS);


    flag = fetchAndVerifyBoolean(GUI_KEY);
    if (flag) {
      // need to run RMA agent
      if (value != null) {
        value = "RMA:jade.tools.rma.rma " + value;  // put before other agents
      } else {
        value = "RMA:jade.tools.rma.rma"// only one
      }
    }

    if (value != null) {
      Vector agentVector = helper.T2(value, false);
      List agents = new ArrayList();

      for (Enumeration e = helper.getCommandLineAgentSpecifiers(agentVector);
      e.hasMoreElements(); ) {
        agents.add((Specifier) e.nextElement());
      }

      setSpecifiers(Profile.AGENTS, agents);
    }

    // Get service list (if any)
    value = argProp.getProperty(SERVICES);
    if(value == null) {
      // Remove mobility service from the list if '-nomobility' was specified
      flag = fetchAndVerifyBoolean(NOMOBILITY_KEY);
      if (flag) {
        value = DEFAULT_SERVICES_NOMOBILITY;
      }
      else {
        value = DEFAULT_SERVICES;
      }
    }

    setSpecifiers(Profile.SERVICES, parseSpecifiers(value));


    // finally, copy into profileProp all the properties that
    // were present in argProp AND were not already present in profileProp.
    // The fact that we do not copy those properties that were already
    // present in profileProp is a sanity check to avoid modification
    // of properties that were set in the code above
    for (Enumeration e=argProp.keys(); e.hasMoreElements(); ) {
      String key = (String)e.nextElement();
      if (getParameter(key,null) == null)
        setParameter(key, argProp.get(key).toString());
    }

    // The following is for debugging only. Probably should not document the "dumpProfile" attribute.
    // Note All the jade.util.leap.ArrayList structures will only print their type unless a
    // toString() method were added to them.
    if (argProp.getBooleanProperty("dumpProfile", false)) {
      ArrayList aList = new ArrayList();
      System.out.println("---------- Jade Boot profile property values ----------");
      for (Enumeration e = profileProp.sortedKeys(); e.hasMoreElements(); ) {
        String key = (String) e.nextElement();
        Object o = profileProp.get(key);
        if (o.getClass().isAssignableFrom(aList.getClass())) {
          System.out.print(key + "=");
          ArrayList al = (ArrayList)o;
          Iterator itor = al.iterator();
          if (!itor.hasNext()) {
            System.out.println("<empty>");
          } else {
            StringBuffer sb = new StringBuffer();
            while (itor.hasNext()) {
              sb.append(itor.next());
              if (itor.hasNext()) {
                sb.append(" ");
              }
            }
            System.out.println(sb.toString());
          }
        } else {
          System.out.println(key + "=" + profileProp.getProperty(key));
        }
      }
      System.out.println("-------------------------------------------------------");
    }
  }
View Full Code Here

  public Boot() {
  }


  public static Properties parseCmdLineArgs(String[] args) throws IllegalArgumentException {
    Properties props = new ExtendedProperties();

    int i = 0;
    while (i < args.length) {
      if (args[i].startsWith("-")) {
        // Parse next option

        // Switch options require special handling
        if (args[i].equalsIgnoreCase("-version")) {
          logger.log(Logger.INFO, "----------------------------------\n"+Runtime.getCopyrightNotice()+"----------------------------------------");
          return null;
        }
        if (args[i].equalsIgnoreCase("-help")) {
          printUsage();
          return null;
        }
        if (args[i].equalsIgnoreCase("-container")) {
          props.setProperty(Profile.MAIN, "false");
        }
        else if(args[i].equalsIgnoreCase("-"+Profile.LOCAL_SERVICE_MANAGER)) {
          props.setProperty(Profile.LOCAL_SERVICE_MANAGER, "true");
        }
        else if (args[i].equalsIgnoreCase("-"+Profile.GUI)) {
          props.setProperty(Profile.GUI, "true");
        }
        else if (args[i].equalsIgnoreCase("-"+Profile.NO_MTP)) {
          props.setProperty(Profile.NO_MTP, "true");
        }       
        // Options that can be specified in different ways require special handling
        else if (args[i].equalsIgnoreCase("-name")) {
          if (++i < args.length) {
            props.setProperty(Profile.PLATFORM_ID, args[i]);
          }
          else {
            throw new IllegalArgumentException("No platform name specified after \"-name\" option");
          }
        }
        else if (args[i].equalsIgnoreCase("-mtp")) {
          if (++i < args.length) {
            props.setProperty(Profile.MTPS, args[i]);
          }
          else {
            throw new IllegalArgumentException("No mtps specified after \"-mtp\" option");
          }
        }
        // The -conf option requires special handling
        else if (args[i].equalsIgnoreCase("-conf")) {
          if (++i < args.length) {
            // Some parameters are specified in a properties file
            try {
              props.load(args[i]);
            }
            catch (Exception e) {
              if(logger.isLoggable(Logger.SEVERE))
                logger.log(Logger.SEVERE, "WARNING: error loading properties from file "+args[i]+". "+e);
           
          }
          else {
            throw new IllegalArgumentException("No configuration file name specified after \"-conf\" option");
          }
        }
        // Default handling for all other properties
        else {
          String name = args[i].substring(1);
          if (++i < args.length) {
            props.setProperty(name, args[i]);
          }
          else {
            throw new IllegalArgumentException("No value specified for property \""+name+"\"");
          }
        }
        ++i;
      }
      else {
        // Get agents at the end of command line
        if (props.getProperty(Profile.AGENTS) != null) {
          if(logger.isLoggable(Logger.WARNING))
            logger.log(Logger.WARNING,"WARNING: overriding agents specification set with the \"-agents\" option");
        }
        String agents = args[i];
        props.setProperty(Profile.AGENTS, args[i]);
        if (++i < args.length) {
          if(logger.isLoggable(Logger.WARNING))
            logger.log(Logger.WARNING,"WARNING: ignoring command line argument "+args[i]+" occurring after agents specification");
          if (agents != null && agents.indexOf('(') != -1 && !agents.endsWith(")")) {
            if(logger.isLoggable(Logger.WARNING))
              logger.log(Logger.WARNING,"Note that agent arguments specifications must not contain spaces");
          }
          if (args[i].indexOf(':') != -1) {
            if(logger.isLoggable(Logger.WARNING))
              logger.log(Logger.WARNING,"Note that agent specifications must be separated by a semicolon character \";\" without spaces");
          }
        }
        break;
      }
    }

    // Consistency check
    if ("true".equals(props.getProperty(Profile.NO_MTP)) && props.getProperty(Profile.MTPS) != null) {
      if(logger.isLoggable(Logger.WARNING))
        logger.log(Logger.WARNING,"WARNING: both \"-mtps\" and \"-nomtp\" options specified. The latter will be ignored");
      props.remove(Profile.NO_MTP);
    }

    return props;
  }
View Full Code Here

        saveB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String param = (String) e.getActionCommand();

                if (param.equals("Save File")) {
                    ExtendedProperties propToSave = extractPropertiesFromGui();

                    //propToSave.list(System.out);
                    try {
                        booter.setProperties(propToSave);

                        propToSave = booter.getProperties();

                        //propToSave.list(System.out);
                        JFileChooser chooser = new JFileChooser();

                        chooser.setFileFilter(new myFileFilter());

                        if (currentDir != null) {
                            chooser.setCurrentDirectory(currentDir);
                        }

                        int returnVal = chooser.showSaveDialog(null);

                        if (returnVal == JFileChooser.APPROVE_OPTION) {
                            currentDir = chooser.getCurrentDirectory();

                            String fileName =
                                chooser.getSelectedFile().getAbsolutePath();
                            boolean ext = hasExtension(fileName);

                            if (ext == false) {
                                fileName = fileName.concat(".conf");
                            }

                            propertyFileName = fileName;

                            try {
                                FileOutputStream out =
                                    new FileOutputStream(fileName);
        // do not save -conf=true otherwise
        // -conf <fileName starts the GUI again
        propToSave.put(BootProfileImpl.CONF_KEY,"false");
                                propToSave.store(out, TITLE);
                                out.close();

                                outProp = propToSave;

                                //dispose();
                            } catch (FileNotFoundException e1) {
                                System.out
                                    .println("File not found Exception");
                            } catch (IOException e2) {
                                System.out.println("IO exception");
                            }
                        }
                    } catch (BootException be) {
                        statusField.setText(be.getMessage());
                    }
                }
            }
        });
        buttonPanel.add(saveB);

        JButton runB = new JButton("Run");

        runB.setToolTipText("Launch the system");
        runB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String param = (String) e.getActionCommand();

                if (param.equals("Run")) {
                    ExtendedProperties propToSave = extractPropertiesFromGui();

                    try {
                        booter.setProperties(propToSave);

                        propToSave = booter.getProperties();

                        boolean different = false;

                        if (propertyFileName != null) {

                            // compares the properties from gui with those in the file
                            ExtendedProperties p =
                                readPropertiesFromFile(propertyFileName);

                            //p.list(System.out);
                            different = compareProperties(propToSave, p);
                        }
View Full Code Here

    /**
     * Extract the values of the configuration properties from the GUI.
     */
    ExtendedProperties extractPropertiesFromGui() {
        ExtendedProperties out = new ExtendedProperties();
        int size = propertyPanel.getComponentCount();

        for (Enumeration it = propertiesVector.elements();
                it.hasMoreElements(); ) {
            PropertyType prop = (PropertyType) it.nextElement();
            String name = prop.getName();
            String type = prop.getType();
            String defaultVal = prop.getDefaultValue();
            boolean found = false;

            for (int i = 0; (i < size) &&!found; i++) {
                JPanel singlePanel = (JPanel) propertyPanel.getComponent(i);
                JLabel label = (JLabel) singlePanel.getComponent(0);

                if (name.equalsIgnoreCase(label.getText())) {
                    found = true;

                    if (type.equalsIgnoreCase(PropertyType.COMBO_TYPE)) {

                        //JComboBox
                        JComboBox box =
                            (JComboBox) singlePanel.getComponent(1);

                        out.setProperty(name.toLowerCase(),
                                        box.getSelectedItem().toString());
                    }

                    else if (type.equalsIgnoreCase(PropertyType.BOOLEAN_TYPE)) {

                        //JCheckBox
                        JCheckBox box =
                            (JCheckBox) singlePanel.getComponent(1);

                        out.setProperty(name.toLowerCase(),
                                        (new Boolean(box.isSelected()))
                                            .toString());
                    } else {

                        //JTextField
                        JTextField textField =
                            (JTextField) singlePanel.getComponent(1);
                        String text = textField.getText();

                        //if the user not specificy a value the default one is saved.
                        if (text.length() == 0) {
                            text = defaultVal;
                        }

                        out.setProperty(name.toLowerCase(), text);
                    }
                }
            }
        }

View Full Code Here

    /**
     * Read the properties from file and update the vector of properties.
     */
    void loadPropertiesFromFile(String fileName)
            throws FileNotFoundException, IOException {
        ExtendedProperties p = readPropertiesFromFile(fileName);

        // update the properties in the vector of properties
        // for every property set the value read in the file and set the command line value to null.
        Enumeration e = p.keys();

        while (e.hasMoreElements()) {
            boolean found = false;
            String name = (String) e.nextElement();
            Enumeration it = propertiesVector.elements();

            while (it.hasMoreElements() &&!found) {
                PropertyType pt = (PropertyType) it.nextElement();

                if (pt.getName().equalsIgnoreCase(name)) {
                    found = true;

                    pt.setDefaultValue(p.getProperty(name));
                }
            }
        }
    }
View Full Code Here

    /**
     * Read the properties from a specific file.
     */
    ExtendedProperties readPropertiesFromFile(String fileName) throws FileNotFoundException, IOException {
        ExtendedProperties p = new ExtendedProperties();
        FileInputStream in = new FileInputStream(fileName);

        p.load(in);
        in.close();

        return p;
    }
View Full Code Here

   * Old method, only for compliance with former versions (prior 3.0)
   */
  public TransportAddress activate(InChannel.Dispatcher disp)
  throws MTPException {
    try {
      return activate(disp,new ProfileImpl(new ExtendedProperties()));
    } catch(Exception e) {
      throw new MTPException(e.getMessage());
    }
  }
View Full Code Here

TOP

Related Classes of jade.util.ExtendedProperties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.