Package org.jconfig

Examples of org.jconfig.Configuration


     *  Description of the Method
     *
     *@param  doc  Description of the Parameter
     */
    public static Configuration parse(Document doc,String configName) {       
        Configuration configuration = new DefaultConfiguration(configName);
        String currentCategory;
        getVariables(doc,configuration);
        // first we get all nodes where the element is category
        NodeList nl = doc.getElementsByTagName("category");
        for (int i = 0; i < nl.getLength(); i++) {
            // now we get every node from the list
            Node n = nl.item(i);
            // and get the name attribute for this category
            NamedNodeMap curAtt = n.getAttributes();
            Node curNode = curAtt.getNamedItem("name");
            currentCategory = curNode.getNodeValue();           
            configuration.setCategory(currentCategory);
            // now we process all children for this category
            for (Node child = n.getFirstChild(); child != null; child = child.getNextSibling()) {
                if (child.getNodeName().equals("property")) {
                    // we have found a property element and now we grab the name and value
                    // attributes
                    NamedNodeMap myAtt = child.getAttributes();
                    Node myNode = myAtt.getNamedItem("name");
                    String name = myNode.getNodeValue();
                    myNode = myAtt.getNamedItem("value");
                    String value = myNode.getNodeValue();
                    // if we have both then lets store it
                    if (name != null && value != null) {
                        // the key is always category/name
                        // e.g. general/congig_file                                               
                        configuration.setProperty(name,value,currentCategory);
                    }
                }
            }
        }
        return configuration;
View Full Code Here


        true,
        false,
        false));

    // now we have to crate one attribute per property found
    Configuration configuration =
      ConfigurationManager.getConfiguration(configurationName);
    Category category = configuration.getCategory(categoryName);
    Properties properties = category.getProperties();
    Enumeration propertiesEnum = properties.keys();

    while (propertiesEnum.hasMoreElements()) {
View Full Code Here

    // Check for a recognized attributeName and call the corresponding getter
    if (attributeName.equals("name")) {
      value = categoryName;
    } else {
      Configuration configuration =
        ConfigurationManager.getConfiguration(configurationName);
      Category category = configuration.getCategory(categoryName);

      if (category.getProperty(attributeName) != null) {
        value = category.getProperty(attributeName);
      }
    }
View Full Code Here

          + dClassName
          + " with null attribute name");
    }
   

    Configuration configuration =
      ConfigurationManager.getConfiguration(configurationName);
    Category category = configuration.getCategory(categoryName);
    category.setProperty(attributeName, (String) value);
  }
View Full Code Here

    }
   
    void categoryMBeanRegistration() {
       
        // registers all categories
        Configuration configuration =
        ConfigurationManager.getConfiguration(configurationName);
        String[] categoryNames = configuration.getCategoryNames();
        for (int i = 0; i < categoryNames.length; i++) {
            registerCategoryMBean(categoryNames[i]);
        }
    }
View Full Code Here

        categoryMBeanRegistration();
    }
   
    void categoryMBeanDeregistration() {
        // deregisters all categories
        Configuration configuration =
        ConfigurationManager.getConfiguration(configurationName);
        String[] categoryNames = configuration.getCategoryNames();
        for (int i = 0; i < categoryNames.length; i++) {
            unregisterCategoryMBean(categoryNames[i]);
        }
       
        // categories are removed
View Full Code Here

              throw new ConfigurationManagerException("The parser cannot parse the file: " + se.getMessage());
          } catch (IOException ioe) {
            ErrorReporter.getErrorHandler().reportError("The parser cannot open the file",ioe);
              throw new ConfigurationManagerException("The parser cannot open the file: " + ioe.getMessage());
          }    
          Configuration config = parser.parse(doc, configurationName);               
          config.resetCreated();
          return config;
    }
        else {
          ErrorReporter.getErrorHandler().reportError("The file:"+filename+" not found in classpath");
            throw new ConfigurationManagerException("The file could not be found in the classpath");
View Full Code Here

            while ((line=nis.readLine()) != null ) {
                content.add(line);
            }
            nis.close();
            boolean addVar = false;
            Configuration cfg = new ExtensibleConfiguration(configurationName);
            String currentCategoryName = null;
            for ( int i = 0; i < content.size();i++) {
                String tmp = (String)content.get(i);
                if ( tmp != null && tmp.length() > 0 && !tmp.startsWith("#") ) {
                  if ( tmp.startsWith(" ") || tmp.startsWith("\t") ) {
                    if ( tmp.indexOf(":") != -1 ) {
                      String left = tmp.substring(0,tmp.indexOf(":"));
                        left = left.trim();
                        String right = tmp.substring(tmp.indexOf(":")+1);
                        right = right.trim();          
                        if ( addVar ) {
                          cfg.setVariable(left,right);
                        }
                        else {
                          cfg.setProperty(left,right,currentCategoryName);
                        }
                    }
                  }
                  else {
                    String name = tmp;
            name = name.trim();
                      if ( name.endsWith(":")) {
                        name = name.substring(0,name.length()-1);
                      }
                      if ( name.equalsIgnoreCase("variables")) {
                        addVar = true;
                      }
                      else {
                        addVar = false;
                        String extend = null;
                        if ( name.startsWith("extends")) {
                          int pos = name.indexOf(":");
                          if ( pos != -1 ) {
                            cfg.setBaseConfiguration(name.substring(pos+1).trim());
                          }
                        }
                        else {
                          if ( tmp.indexOf(" extends ") != -1 ) {
                              extend = name.substring(name.indexOf(" extends ")+9);
                              extend = extend.trim();
                              name = name.substring(0,name.indexOf(" extends "));                           
                          }
                          Category ec = new DefaultCategory(name);
                          if ( extend != null ) {
                              ec.setExtendsCategory(extend);
                          }
                          cfg.setCategory(ec);
                          currentCategoryName = name;
                        }
                      }
                  }
                }
View Full Code Here

     *
     * @param doc
     *            Description of the Parameter
     */
    public Configuration parse(Document doc, String configName) {
        Configuration configuration = new NestedConfiguration(configName);
        String currentCategory;
        getBaseConfigName(doc, configuration);
        getVariables(doc, configuration);
        getIncludeProperties(doc, configuration);
        Element root = doc.getDocumentElement();
        // first we get all nodes where the element is category
        for (Node child = root.getFirstChild(); child != null; child = child
                .getNextSibling()) {
            if (child.getNodeName().equals("category")) {
                NamedNodeMap curAtt = child.getAttributes();
                Node curNode = curAtt.getNamedItem("name");
                currentCategory = curNode.getNodeValue();
                NestedCategory category = new NestedCategory(currentCategory);
                getCategory(child, category, configName);
                configuration.setCategory(category);
            }
        }
        return configuration;
    }
View Full Code Here

     *  Description of the Method
     *
     *@param  doc  Description of the Parameter
     */
    public Configuration parse(Document doc,String configName) {       
        Configuration configuration = new DefaultConfiguration(configName);
        String currentCategory;
        getVariables(doc,configuration);
        // first we get all nodes where the element is category
        NodeList nl = doc.getElementsByTagName("category");
        for (int i = 0; i < nl.getLength(); i++) {
            // now we get every node from the list
            Node n = nl.item(i);
            // and get the name attribute for this category
            NamedNodeMap curAtt = n.getAttributes();
            Node curNode = curAtt.getNamedItem("name");
            currentCategory = curNode.getNodeValue();           
            configuration.setCategory(currentCategory);
            // now we process all children for this category
            for (Node child = n.getFirstChild(); child != null; child = child.getNextSibling()) {
                // we take the tag name as property name               
                if ( child.getNodeType() == 1 && child.getFirstChild() != null ) {
                    String name = child.getNodeName();                                 
                    String value = child.getFirstChild().getNodeValue();                   
                    if (name != null && value != null) {
                        // the key is always category/name
                        // e.g. general/congig_file                                               
                        configuration.setProperty(name,value,currentCategory);
                    }               
                }
            }
        }
        return configuration;
View Full Code Here

TOP

Related Classes of org.jconfig.Configuration

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.