Package org.jconfig

Examples of org.jconfig.Configuration


    public Configuration load(String configurationName) throws ConfigurationManagerException {   
        InitialDirContext ctx = getContext();
        if ( ctx == null ) {
            throw new ConfigurationManagerException("There is no connection to the LDAP server");
        }
        Configuration config = new DefaultConfiguration(null);
        getCategories(ctx,config);
        getAllProperties(ctx,config);
        return config;
    }
View Full Code Here


    }
   
    /**
     * @throws ConfigurationManagerException  */
    public synchronized Configuration load() throws ConfigurationManagerException {
        Configuration c = load( url );
        addFileListener(this);
        return ( c );
    }
View Full Code Here

            throw new ConfigurationManagerException("The parser cannot parse the XML: " + 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, configName);       
        config.resetCreated();
        return config;
    }
View Full Code Here

            }
            if ( braces != 0 ) {
              ErrorReporter.getErrorHandler().reportError("Unmatched brackets in script file");
                throw new ConfigurationManagerException("Unmatched brackets in script file");
            }
            Configuration cfg = new ExtensibleConfiguration(configurationName);
            boolean process = false;
            String currentCategoryName = null;
            for ( int i = 0; i < content.size();i++) {
                String tmp = (String)content.get(i);
                tmp = tmp.trim();
                if ( process ) {
                    if ( tmp.startsWith("}") ) {
                        process = false;                    
                    }
                    else {                                               
                        String left = tmp.substring(0,tmp.indexOf("=")-1);
                        left = left.trim();
                        String right = tmp.substring(tmp.indexOf("=")+1);
                        right = right.trim();                                               
                        cfg.setProperty(left,right,currentCategoryName);                       
                    }
                }
                if ( tmp.startsWith("category") && tmp.indexOf("{") != -1 ) {
                    process = true;
                    String name = tmp.substring(9);
                    name = name.substring(0,name.indexOf("{"));
                    name = name.trim();                   
                    String extend = null;
                    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;
                }
            }
            return cfg;
        }
View Full Code Here

            e.printStackTrace();
        }
    }

    public String showConfiguration() {
        Configuration myConfig = ConfigurationManager.getConfiguration(configName);
        if ( myConfig != null ) {
            StringBuffer buffer = new StringBuffer();
            buffer.append("<pre>");
            buffer.append(myConfig.toString());
            buffer.append("</pre>");
            return buffer.toString();
        }
        else {
            return null;
View Full Code Here

            return null;
        }
    }
   
    public void removeProperty(String name, String category) {
        Configuration config = ConfigurationManager.getConfiguration(configName);
        config.removeProperty(name, category);
    }
View Full Code Here

    public void saveConfiguration() throws Exception {
        ConfigurationManager.getInstance().save(configName);
    }
   
    public void setProperty(String name, String value, String category) {
        Configuration config = ConfigurationManager.getConfiguration(configName);
        config.setProperty(name, value, category);
    }
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;
        getBaseConfigName(doc, configuration);
        getVariables(doc,configuration);
        getIncludeProperties(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();
//            System.err.println("processing for currentCategory "+currentCategory);
            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");
                    if ( myNode != null ) {
                      String name = myNode.getNodeValue();
                      myNode = myAtt.getNamedItem("value");
                      if ( myNode != null ) {
                        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);
                        }
                      }
                      else {
                        ErrorReporter.getErrorHandler().reportError("No attribute 'value' found for property - ignoring entry");
                      }
View Full Code Here

        return name;
    }
   
    public void setName(String name) {
        this.name = name;
        Configuration config = ConfigurationManager.getConfiguration(name);
        loadConfiguration(name);
    }
View Full Code Here

     *  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

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.