Package org.apache.avalon.framework.configuration

Examples of org.apache.avalon.framework.configuration.MutableConfiguration


        }
    }
   
    public void testMutable() throws Exception  
    {  
        MutableConfiguration root = new DefaultConfiguration( "root", "-" );  
        root.setAttribute( "root1", "root1" );  
        root.setAttribute( "root2", "root2" );  
        root.getMutableChild( "child1" ).setAttribute( "child1-attr1", "child1-attr1" );  
        root.getMutableChild( "child1" ).setAttribute( "child1-attr2", "child1-attr2" );  
        root.getMutableChild( "child2" ).setAttribute( "child2-attr1", "child2-attr1" );  
        root.getMutableChild( "child2" ).setAttribute( "child2-attr2", "child2-attr2" );  
       
        assertEquals( "root1", root.getAttribute( "root1" ) );  
        assertEquals( "root2", root.getAttribute( "root2" ) );  
        assertEquals( "child1-attr1", root.getChild( "child1" ).getAttribute( "child1-attr1" ) );  
        assertEquals( "child1-attr2", root.getChild( "child1" ).getAttribute( "child1-attr2" ) );  
        assertEquals( "child2-attr1", root.getChild( "child2" ).getAttribute( "child2-attr1" ) );  
        assertEquals( "child2-attr2", root.getChild( "child2" ).getAttribute( "child2-attr2" ) );  
       
        assertEquals( null, root.getMutableChild( "child3", false ) );  
       
        assertEquals( 2, root.getChildren().length );  
       
        assertEquals( 2, root.getMutableChildren().length );  
        assertEquals( 1, root.getMutableChildren( "child1" ).length );  
        assertEquals( 1, root.getMutableChildren( "child2" ).length );  
        assertTrue( root.getMutableChildren( "child1" )[0] == root.getChild( "child1" ) );  
       
        // Add an immutable child.  
        DefaultConfiguration immutableChild = new DefaultConfiguration( "immutable-child", "-" );  
        immutableChild.makeReadOnly();  
       
        try  
        {  
            immutableChild.setAttribute( "attr", "attr" );  
            fail( "Read-only DefaultConfiguration wasn't read-only!" );  
        }  
        catch (IllegalStateException ise)  
        {  
            // expected  
        }  
       
        root.addChild( immutableChild );  
       
        // OK, ask to have it back.  
        root.getMutableChild( "immutable-child" ).setAttribute( "attr", "attr" );  
       
        assertEquals( 1, root.getChildren( "immutable-child" ).length );  
        assertEquals( "attr", root.getChild( "immutable-child" ).getAttribute( "attr" ) );  
    }    
View Full Code Here


        }
    }
   
    public void testMutable() throws Exception  
    {  
        MutableConfiguration root = new DefaultConfiguration( "root", "-" );  
        root.setAttribute( "root1", "root1" );  
        root.setAttribute( "root2", "root2" );  
        root.getMutableChild( "child1" ).setAttribute( "child1-attr1", "child1-attr1" );  
        root.getMutableChild( "child1" ).setAttribute( "child1-attr2", "child1-attr2" );  
        root.getMutableChild( "child2" ).setAttribute( "child2-attr1", "child2-attr1" );  
        root.getMutableChild( "child2" ).setAttribute( "child2-attr2", "child2-attr2" );  
       
        assertEquals( "root1", root.getAttribute( "root1" ) );  
        assertEquals( "root2", root.getAttribute( "root2" ) );  
        assertEquals( "child1-attr1", root.getChild( "child1" ).getAttribute( "child1-attr1" ) );  
        assertEquals( "child1-attr2", root.getChild( "child1" ).getAttribute( "child1-attr2" ) );  
        assertEquals( "child2-attr1", root.getChild( "child2" ).getAttribute( "child2-attr1" ) );  
        assertEquals( "child2-attr2", root.getChild( "child2" ).getAttribute( "child2-attr2" ) );  
       
        assertEquals( null, root.getMutableChild( "child3", false ) );  
       
        assertEquals( 2, root.getChildren().length );  
       
        assertEquals( 2, root.getMutableChildren().length );  
        assertEquals( 1, root.getMutableChildren( "child1" ).length );  
        assertEquals( 1, root.getMutableChildren( "child2" ).length );  
        assertTrue( root.getMutableChildren( "child1" )[0] == root.getChild( "child1" ) );  
       
        // Add an immutable child.  
        DefaultConfiguration immutableChild = new DefaultConfiguration( "immutable-child", "-" );  
        immutableChild.makeReadOnly();  
       
        try  
        {  
            immutableChild.setAttribute( "attr", "attr" );  
            fail( "Read-only DefaultConfiguration wasn't read-only!" );  
        }  
        catch (IllegalStateException ise)  
        {  
            // expected  
        }  
       
        root.addChild( immutableChild );  
       
        // OK, ask to have it back.  
        root.getMutableChild( "immutable-child" ).setAttribute( "attr", "attr" );  
       
        assertEquals( 1, root.getChildren( "immutable-child" ).length );  
        assertEquals( "attr", root.getChild( "immutable-child" ).getAttribute( "attr" ) );  
    }    
View Full Code Here

        }
    }
   
    public void testMutable() throws Exception  
    {  
        MutableConfiguration root = new DefaultConfiguration( "root", "-" );  
        root.setAttribute( "root1", "root1" );  
        root.setAttribute( "root2", "root2" );  
        root.getMutableChild( "child1" ).setAttribute( "child1-attr1", "child1-attr1" );  
        root.getMutableChild( "child1" ).setAttribute( "child1-attr2", "child1-attr2" );  
        root.getMutableChild( "child2" ).setAttribute( "child2-attr1", "child2-attr1" );  
        root.getMutableChild( "child2" ).setAttribute( "child2-attr2", "child2-attr2" );  
       
        assertEquals( "root1", root.getAttribute( "root1" ) );  
        assertEquals( "root2", root.getAttribute( "root2" ) );  
        assertEquals( "child1-attr1", root.getChild( "child1" ).getAttribute( "child1-attr1" ) );  
        assertEquals( "child1-attr2", root.getChild( "child1" ).getAttribute( "child1-attr2" ) );  
        assertEquals( "child2-attr1", root.getChild( "child2" ).getAttribute( "child2-attr1" ) );  
        assertEquals( "child2-attr2", root.getChild( "child2" ).getAttribute( "child2-attr2" ) );  
       
        assertEquals( null, root.getMutableChild( "child3", false ) );  
       
        assertEquals( 2, root.getChildren().length );  
       
        assertEquals( 2, root.getMutableChildren().length );  
        assertEquals( 1, root.getMutableChildren( "child1" ).length );  
        assertEquals( 1, root.getMutableChildren( "child2" ).length );  
        assertTrue( root.getMutableChildren( "child1" )[0] == root.getChild( "child1" ) );  
       
        // Add an immutable child.  
        DefaultConfiguration immutableChild = new DefaultConfiguration( "immutable-child", "-" );  
        immutableChild.makeReadOnly();  
       
        try  
        {  
            immutableChild.setAttribute( "attr", "attr" );  
            fail( "Read-only DefaultConfiguration wasn't read-only!" );  
        }  
        catch (IllegalStateException ise)  
        {  
            // expected  
        }  
       
        root.addChild( immutableChild );  
       
        // OK, ask to have it back.  
        root.getMutableChild( "immutable-child" ).setAttribute( "attr", "attr" );  
       
        assertEquals( 1, root.getChildren( "immutable-child" ).length );  
        assertEquals( "attr", root.getChild( "immutable-child" ).getAttribute( "attr" ) );  
    }    
View Full Code Here

     * they are read by the cocoon i18n transformer. We want to add in <location> parameters
     * for each
     */
    public void configure(Configuration originalConf) throws ConfigurationException
    {
      MutableConfiguration modifiedConf = new DefaultConfiguration(originalConf,true);
        MutableConfiguration cataloguesConf = modifiedConf.getMutableChild("catalogues", true);
       
        // Find the default catalogue and add our new locations to it.
        for (MutableConfiguration catalogueConf : cataloguesConf.getMutableChildren())
        {
          if (!"false".equals(catalogueConf.getAttribute("aspects","false")))
      {
            // Get the first location element to determine what the base path is.
            String baseCatalogueLocationPath = DEFAULT_BASE_LOCATION;
            Configuration baseCatalogueLocationConf = catalogueConf.getChild("location");
            if (baseCatalogueLocationConf != null)
              baseCatalogueLocationPath = baseCatalogueLocationConf.getValue();
            if (!baseCatalogueLocationPath.endsWith("/"))
              baseCatalogueLocationPath += "/"; // Add a trailing slash if one dosn't exist
             
            String catalogueId = catalogueConf.getAttribute("id","unknown");
           
            // For each aspect add two new locations one inside the aspect's directory
            // and another inside the base location for i18n files.
              for (Aspect aspect : XMLUIConfiguration.getAspectChain())
              {
                // Add a catalogue location inside the default i18n directory in the webapp
                // this will be of the form: "context://i18n/<aspectpath>/" thus for the artifact
                // browser aspect it will be "context://i18n/aspects/ArtifactBrowser/"
                String baseLocationPath = aspect.getPath();
                int idx = baseLocationPath.indexOf("://");
                if (idx > 0)
                  // remove the module directive from the aspect's path so it's just a normal path
                  baseLocationPath = baseLocationPath.substring(idx+3, baseLocationPath.length());
               
                // Now that the module directive has been removed from the path, add in the base i18npath
                baseLocationPath = baseCatalogueLocationPath + baseLocationPath;
               
                MutableConfiguration baseLocation = new DefaultConfiguration("location");
                baseLocation.setValue(baseLocationPath);
                catalogueConf.addChild(baseLocation);
               
               
                // Add a catalogue location inside the aspect's directory
                // (most likely in the jar's resources but if it's not that's okay)
                // For the artifact browser this would be:
                // "resource://aspects/ArtifactBrowser/i18n/"
                String aspectLocationPath = aspect.getPath();
                if (!aspectLocationPath.endsWith("/"))
                  aspectLocationPath += "/"; // Add a trailing slash if one dosn't exist
                aspectLocationPath += "i18n/";
                MutableConfiguration aspectLocation = new DefaultConfiguration("location");
                aspectLocation.setValue(aspectLocationPath);
                catalogueConf.addChild(aspectLocation);
               
                log.info("Adding i18n location path for '"+catalogueId+"' catalogue: "+baseLocationPath);
                log.info("Adding i18n location path for '"+catalogueId+"' catalogue: "+aspectLocationPath);
              } // for each aspect
View Full Code Here

     * they are read by the cocoon i18n transformer. We want to add in <location> parameters
     * for each
     */
    public void configure(Configuration originalConf) throws ConfigurationException
    {
      MutableConfiguration modifiedConf = new DefaultConfiguration(originalConf,true);
        MutableConfiguration cataloguesConf = modifiedConf.getMutableChild("catalogues", true);
       
        // Find the default catalogue and add our new locations to it.
        for (MutableConfiguration catalogueConf : cataloguesConf.getMutableChildren())
        {
          if (!"false".equals(catalogueConf.getAttribute("aspects","false")))
      {
            // Get the first location element to determine what the base path is.
            String baseCatalogueLocationPath = DEFAULT_BASE_LOCATION;
            Configuration baseCatalogueLocationConf = catalogueConf.getChild("location");
            if (baseCatalogueLocationConf != null)
                {
                    baseCatalogueLocationPath = baseCatalogueLocationConf.getValue();
                }
            if (!baseCatalogueLocationPath.endsWith("/"))
                {
                    baseCatalogueLocationPath += "/";
                } // Add a trailing slash if one doesn't exist
             
            String catalogueId = catalogueConf.getAttribute("id","unknown");
           
            // For each aspect add two new locations one inside the aspect's directory
            // and another inside the base location for i18n files.
              for (Aspect aspect : XMLUIConfiguration.getAspectChain())
              {
                // Add a catalogue location inside the default i18n directory in the webapp
                // this will be of the form: "context://i18n/<aspectpath>/" thus for the artifact
                // browser aspect it will be "context://i18n/aspects/ArtifactBrowser/"
                String baseLocationPath = aspect.getPath();
                int idx = baseLocationPath.indexOf("://");
                if (idx > 0)
                    {
                        // remove the module directive from the aspect's path so it's just a normal path
                        baseLocationPath = baseLocationPath.substring(idx + 3, baseLocationPath.length());
                    }
               
                // Now that the module directive has been removed from the path, add in the base i18npath
                baseLocationPath = baseCatalogueLocationPath + baseLocationPath;
               
                MutableConfiguration baseLocation = new DefaultConfiguration("location");
                baseLocation.setValue(baseLocationPath);
                catalogueConf.addChild(baseLocation);
               
               
                // Add a catalogue location inside the aspect's directory
                // (most likely in the jar's resources but if it's not that's okay)
                // For the artifact browser this would be:
                // "resource://aspects/ArtifactBrowser/i18n/"
                String aspectLocationPath = aspect.getPath();
                if (!aspectLocationPath.endsWith("/"))
                    {
                        aspectLocationPath += "/"; // Add a trailing slash if one doesn't exist
                    }
                aspectLocationPath += "i18n/";
                MutableConfiguration aspectLocation = new DefaultConfiguration("location");
                aspectLocation.setValue(aspectLocationPath);
                catalogueConf.addChild(aspectLocation);
               
                log.debug("Adding i18n location path for '"+catalogueId+"' catalogue: "+baseLocationPath);
                log.debug("Adding i18n location path for '"+catalogueId+"' catalogue: "+aspectLocationPath);
              } // for each aspect
View Full Code Here

TOP

Related Classes of org.apache.avalon.framework.configuration.MutableConfiguration

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.