Package org.jconfig

Examples of org.jconfig.Configuration


    public synchronized Configuration load(String configName) throws ConfigurationManagerException {
        return loadPropertiesFile(file,configName);
    }
   
    private Configuration loadPropertiesFile(File file,String configName) throws ConfigurationManagerException {
        Configuration config = new DefaultConfiguration(configName);
        if ( file == null ) {
          ErrorReporter.getErrorHandler().reportError("The file is NULL");
            throw new ConfigurationManagerException("The file is NULL");
        }
        try {
            InputStream inputStream = null;
            if(file.exists()) {
                inputStream = new FileInputStream(file);
            } else {
                ResourceLocator locator = new ResourceLocator(file.getName());
                inputStream = locator.getInputStream();
            }
            if ( inputStream == null ) {
              ErrorReporter.getErrorHandler().reportError("Cannot find the properties file");
                throw new ConfigurationManagerException("Cannot find the properties file");
            }
            Properties myProperties = new Properties();
            myProperties.load(inputStream);
            Enumeration propertyNames = myProperties.propertyNames();
            while (propertyNames.hasMoreElements()) {
                String name = (String) propertyNames.nextElement();
                String value = myProperties.getProperty(name);
                config.setProperty(name, value);
            }
        } catch (Exception e) {
          ErrorReporter.getErrorHandler().reportError("The file cannot be loaded",e);
            throw new ConfigurationManagerException("The file cannot be loaded:"+e.getMessage());
        }
        config.resetCreated();
        return config;
    }
View Full Code Here


        } catch (IOException ioe) {
          ErrorReporter.getErrorHandler().reportError("The parser cannot parse the file",ioe);
            throw new ConfigurationManagerException(
            "The parser cannot open the file: " + ioe.getMessage());
        }       
        Configuration config = parser.parse(doc, configName);
        try {
            java.io.BufferedReader in = new java.io.BufferedReader(new java.io.FileReader(file));
            String str;
            while ((str = in.readLine()) != null) {
                if(str.indexOf("encoding") > -1) config.setEncoding(getEncodingType(str));
            }
            in.close();
        }
        catch (Exception e) {
            // no problem here
        }
        config.resetCreated();
        return config;
    }
View Full Code Here

   
    /**
     * @return
     */
    private Configuration loadConfiguration(String configurationName) throws ConfigurationManagerException {
        Configuration config = new DefaultConfiguration(configurationName);
        try {
            PreparedStatement pstmt = con.prepareStatement("SELECT OID FROM T_CONFIGURATION WHERE NAME = ?");
            pstmt.setString(1, configurationName);
            ResultSet result = pstmt.executeQuery();
            while(result.next()) {
View Full Code Here

        System.setProperty("jconfig.parser","org.jconfig.parser.DefaultConfigParser");       
    }
   
    public void testParseNestedConfig() {
        System.setProperty("jconfig.parser","org.jconfig.parser.NestedConfigParser");
        Configuration config = ConfigurationManager.getConfiguration("nested");
        String next = config.getProperty("inner",null,"inner/myinner");
        assertEquals("value",next);
        next = config.getProperty("hello",null,"inner/myinner/moreinner");
        assertEquals("universe",next);
        next = config.getProperty("text",null,"inner/2");
        assertNull(next);
        next = config.getProperty("special",null,"inner/2");
        assertEquals("one",next);       
        config.setProperty("max","10000","inner/myinner/moreinner");
        next = config.getProperty("max",null,"inner/myinner/moreinner");
        assertEquals("10000",next);
        next = config.getProperty("vartest","not set","inner/myinner/moreinner");
        assertEquals("VarValue-is here",next);
        config.removeProperty("max","inner/myinner/moreinner");
        next = config.getProperty("max",null,"inner/myinner/moreinner");
        assertEquals(null,next);
    }
View Full Code Here

        assertEquals(null,next);
    }
   
     public void testCreateNewTopLevelCategory() {
        System.setProperty("jconfig.parser","org.jconfig.parser.NestedConfigParser");
        Configuration config = ConfigurationManager.getConfiguration("nested");
        config.setProperty("another", "value", "brand/new");    
        assertEquals("value",config.getProperty("another",null,"brand/new"))
     }
View Full Code Here

        assertEquals("value",config.getProperty("another",null,"brand/new"))
     }
    
     public void testCreateNewNestedCategory() {
        System.setProperty("jconfig.parser","org.jconfig.parser.NestedConfigParser");
        Configuration config = ConfigurationManager.getConfiguration("nested");
        config.setProperty("hello", "new", "inner/myinner/new");       
        assertEquals("new",config.getProperty("hello",null,"inner/myinner/new"));    
    }
View Full Code Here

        try {
            XMLFileHandler fileHandler = new XMLFileHandler();
            String filename = System.getProperty("java.io.tmpdir")+"test_config.xml";           
            File file = new File(filename);
            fileHandler.setFile(file);
            Configuration config = ConfigurationManager.getConfiguration("nested");                       
            fileHandler.store(config);
            config = fileHandler.load(file, "MyTest");
            String next = config.getProperty("inner",null,"inner/myinner");
            assertEquals("value",next);
            next = config.getProperty("hello",null,"inner/myinner/moreinner");
            assertEquals("universe",next);
            next = config.getProperty("text",null,"inner/2");
            assertNull(next);
            next = config.getProperty("special",null,"inner/2");
            assertEquals("one",next);  
        }
        catch (Exception e) {
            e.printStackTrace();
            fail("unexpected exception");
View Full Code Here

    public void tearDown() throws Exception {
        System.setProperty("jconfig.parser","org.jconfig.parser.DefaultConfigParser");
    }
   
    public void testParseConfig() {
        Configuration config = ConfigurationManager.getConfiguration("e1");
        String next = config.getProperty("inner",null,"inner/myinner");
        assertEquals("value",next);
        next = config.getProperty("hello",null,"inner/myinner/moreinner");
        assertEquals("universe",next);
        next = config.getProperty("text",null,"inner/2");
        assertNull(next);
        next = config.getProperty("special",null,"inner/2");
        assertEquals("two",next);
        config.setProperty("max","10000","inner/myinner/moreinner");
        next = config.getProperty("max",null,"inner/myinner/moreinner");
        assertEquals("10000",next);
        next = config.getProperty("vartest","not set","inner/myinner/moreinner");
        assertEquals("VarValue-is here",next);
        config.removeProperty("max","inner/myinner/moreinner");
        next = config.getProperty("max",null,"inner/myinner/moreinner");
        assertEquals(null,next);
    }
View Full Code Here

        next = config.getProperty("max",null,"inner/myinner/moreinner");
        assertEquals(null,next);
    }
   
    public void testParseCircularDependency() {
        Configuration config2 = ConfigurationManager.getConfiguration("e1");
        Configuration config = ConfigurationManager.getConfiguration("e3");
        String next = config.getProperty("inner",null,"inner/myinner");
        // should not be set since the base config was not set
        System.out.println("next:"+next);
        assertNull(next);
    }
View Full Code Here

    junit.textui.TestRunner.run(AdvancedConfigParserTest.class);
  }
 
  public void testParseAdvancedConfig() {
            System.setProperty("jconfig.parser","org.jconfig.parser.AdvancedConfigParser");
            Configuration config = ConfigurationManager.getConfiguration("advanced");
            String world = config.getProperty("hello");
            assertEquals("world",world);
        }
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.