1 8 package org.codehaus.dna.impl; 9 10 import org.codehaus.dna.Active; 11 import org.codehaus.dna.Composable; 12 import org.codehaus.dna.Configurable; 13 import org.codehaus.dna.Configuration; 14 import org.codehaus.dna.ConfigurationException; 15 import org.codehaus.dna.LogEnabled; 16 import org.codehaus.dna.Logger; 17 import org.codehaus.dna.MissingResourceException; 18 import org.codehaus.dna.ResourceLocator; 19 20 26 public class ContainerUtil 27 { 28 38 public static void enableLogging( final Object object, 39 final Logger logger ) 40 { 41 if( object instanceof LogEnabled ) 42 { 43 if( null == logger ) 44 { 45 final String message = "Null logger."; 46 throw new IllegalArgumentException ( message ); 47 } 48 ( (LogEnabled)object ).enableLogging( logger ); 49 } 50 } 51 52 64 public static void compose( final Object object, 65 final ResourceLocator locator ) 66 throws MissingResourceException 67 { 68 if( object instanceof Composable ) 69 { 70 if( null == locator ) 71 { 72 final String message = "Null locator."; 73 throw new IllegalArgumentException ( message ); 74 } 75 ( (Composable)object ).compose( locator ); 76 } 77 } 78 79 91 public static void configure( final Object object, 92 final Configuration configuration ) 93 throws ConfigurationException 94 { 95 if( object instanceof Configurable ) 96 { 97 if( null == configuration ) 98 { 99 final String message = "Null configuration."; 100 throw new IllegalArgumentException ( message ); 101 } 102 ( (Configurable)object ).configure( configuration ); 103 } 104 } 105 106 114 public static void initialize( final Object object ) 115 throws Exception 116 { 117 if( object instanceof Active ) 118 { 119 ( (Active)object ).initialize(); 120 } 121 } 122 123 131 public static void dispose( final Object object ) 132 throws Exception 133 { 134 if( object instanceof Active ) 135 { 136 ( (Active)object ).dispose(); 137 } 138 } 139 } 140 | Popular Tags |