Better solution for setting the context. The context is now known as soon as componen...
[utils] / system / general / src / main / java / org / wamblee / system / AbstractComponent.java
index a9752d1f09e7104cee6af9c75685ca9ae7b53a75..8b6109f233a951cf72edae3a6eb5765abc320e2a 100644 (file)
@@ -31,7 +31,8 @@ public abstract class AbstractComponent implements Component {
 
        private static final Log LOG = LogFactory.getLog(AbstractComponent.class);
 
-       private Status _status; 
+       private Status _status;
+       private String _context; 
        private String _name; 
        private List<ProvidedInterface> _provided;
        private List<RequiredInterface> _required;
@@ -50,6 +51,7 @@ public abstract class AbstractComponent implements Component {
        protected AbstractComponent(String aName, ProvidedInterface[] aProvided,
                        RequiredInterface[] aRequired) {
                _status = Status.NOT_STARTED;
+               _context = null; 
                _name = aName;
                _provided = new ArrayList<ProvidedInterface>();
                _provided.addAll(Arrays.asList(aProvided));
@@ -67,6 +69,24 @@ public abstract class AbstractComponent implements Component {
        public final String getName() {
                return _name;
        }
+       
+       @Override
+       public void addContext(String aContext) {
+               if (_context == null ) { 
+                       _context = aContext; 
+               }
+               else { 
+                       _context = aContext + "." + _context;
+               }
+       }
+       
+       @Override
+       public String getQualifiedName() {
+               if ( _context == null ) { 
+                       return getName(); 
+               }
+               return _context + "." + getName(); 
+       }
 
        @Override
        public final ProvidedInterface[] getProvidedServices() {
@@ -79,15 +99,15 @@ public abstract class AbstractComponent implements Component {
        }
 
        @Override
-       public final void start(String aContext) {
-               LOG.info("Initializing '" + aContext + "." + _name + "'");
-               doStart(aContext + "." + getName());
+       public final void start() {
+               LOG.info("Initializing '" + getQualifiedName() + "'");
+               doStart();
                _status = Status.RUNNING;
                if ( _running.size() != _provided.size()) { 
                        List<ProvidedInterface> remaining = 
                                new ArrayList<ProvidedInterface>(_provided);
                        remaining.removeAll(_running);
-                       throw new SystemAssemblyException(aContext + "." + getName() + ": not all services were started, missing " + remaining);
+                       throw new SystemAssemblyException(getQualifiedName() + ": not all services were started, missing " + remaining);
                }
        }
 
@@ -95,7 +115,7 @@ public abstract class AbstractComponent implements Component {
         * Must be implemented for initializing the subsystem. The implementation
         * must call {@link #addService(Service)} for each service that is started.
         */
-       protected abstract void doStart(String aContext);
+       protected abstract void doStart();
 
        /**
         * Implementations must call this method to indicate that a new service has
@@ -104,9 +124,9 @@ public abstract class AbstractComponent implements Component {
         * @param aService
         *            Service.
         */
-       protected final void addService(String aContext,
+       protected final void addService(
                        ProvidedInterface aDescriptor, Object aService) {
-               LOG.info(aContext + ": service '" + aService + "' started.");
+               LOG.info("Interface '" + getQualifiedName() + "." + aDescriptor.getName() + "' started.");
                _running.add(aDescriptor);
                aDescriptor.publish(aService);
        }