1 87 package org.codehaus.loom.components.manager; 88 89 import java.util.HashMap ; 90 import java.util.Map ; 91 import org.codehaus.dna.AbstractLogEnabled; 92 import org.codehaus.dna.Active; 93 import org.codehaus.loom.interfaces.LoomException; 94 import org.codehaus.loom.interfaces.SystemManager; 95 96 101 public abstract class AbstractSystemManager 102 extends AbstractLogEnabled 103 implements SystemManager, Active 104 { 105 private final Map m_entries = new HashMap (); 106 107 private SubContext m_subContext; 108 109 public void initialize() 110 throws Exception 111 { 112 m_subContext = new SubContext( this, null, null ); 113 } 114 115 public void dispose() 116 { 117 m_subContext = null; 118 } 119 120 123 public synchronized void register( final String name, 124 final Object object ) 125 throws LoomException, IllegalArgumentException 126 { 127 checkRegister( name, object ); 128 129 final Object exportedObject = export( name, object ); 130 m_entries.put( name, exportedObject ); 131 } 132 133 136 public synchronized void unregister( final String name ) 137 throws LoomException 138 { 139 final Object entry = m_entries.remove( name ); 140 if( null == entry ) 141 { 142 return; 143 } 144 145 unexport( name, entry ); 146 } 147 148 155 public SystemManager getSubContext( final String parent, 156 final String type ) 157 throws LoomException 158 { 159 return m_subContext.getSubContext( parent, type ); 160 } 161 162 171 protected abstract Object export( String name, Object object ) 172 throws LoomException; 173 174 181 protected abstract void unexport( String name, Object exportedObject ) 182 throws LoomException; 183 184 193 private void checkRegister( final String name, final Object object ) 194 throws LoomException, IllegalArgumentException 195 { 196 if( null == object ) 197 { 198 throw new NullPointerException ( "object" ); 199 } 200 if( null == name ) 201 { 202 throw new NullPointerException ( "name" ); 203 } 204 205 if( null != m_entries.get( name ) ) 206 { 207 final String message = name + 208 " already registered in SystemManager"; 209 throw new LoomException( message ); 210 } 211 } 212 } 213 | Popular Tags |