X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fcore%2FAbstractComponent.java;h=aea2bd6b5cebd7e5bbf804d7044cc0ca2904764e;hb=49ce7cb8387601982d5e6ef186ce206d38f6e3d7;hp=1ac464d0ce1033d9552cd8acca72c74453680921;hpb=ddd261f331280640c5b53c7128230b629ebcd268;p=utils diff --git a/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java b/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java index 1ac464d0..aea2bd6b 100644 --- a/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java +++ b/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java @@ -1,12 +1,12 @@ /* - * Copyright 2007 the original author or authors. - * + * Copyright 2005-2010 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,71 +15,50 @@ */ package org.wamblee.system.core; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; - +import java.util.logging.Logger; /** * Abstract subsystem class making it easy to implement new subsystems. - * - * @param DOCUMENT ME! + * */ public abstract class AbstractComponent implements Component { - /** - * DOCUMENT ME! - */ - private static final Log LOG = LogFactory.getLog(AbstractComponent.class); + private static final Logger LOG = Logger.getLogger(AbstractComponent.class + .getName()); - /** - * DOCUMENT ME! - */ private ThreadLocal> remaining; - /** - * DOCUMENT ME! - */ private String context; - /** - * DOCUMENT ME! - */ private String name; - /** - * DOCUMENT ME! - */ private List provided; - /** - * DOCUMENT ME! - */ private List required; -/** - * Constructs the subsystem. - * - * @param aName - * Name of the system. - * @param aProvided - * Provided services. - * @param aRequired - * Required services. - */ + /** + * Constructs the subsystem. + * + * @param aName + * Name of the system. + * @param aProvided + * Provided services. + * @param aRequired + * Required services. + */ protected AbstractComponent(String aName, List aProvided, List aRequired) { - remaining = new ThreadLocal>(); - context = null; - name = aName; - provided = new ArrayList(aProvided); - required = new ArrayList(aRequired); + remaining = new ThreadLocal>(); + context = null; + name = aName; + provided = new ArrayList(aProvided); + required = new ArrayList(aRequired); } -/** + /** * Constructs the subsystem. * * @param aName @@ -96,20 +75,12 @@ public abstract class AbstractComponent implements Component { /** * Creates a new AbstractComponent object. - * - * @param aName DOCUMENT ME! + * */ protected AbstractComponent(String aName) { this(aName, new ProvidedInterface[0], new RequiredInterface[0]); } - /** - * DOCUMENT ME! - * - * @param aProvided DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public AbstractComponent addProvidedInterface( ProvidedInterface aProvided) { provided.add(aProvided); @@ -117,13 +88,6 @@ public abstract class AbstractComponent implements Component { return this; } - /** - * DOCUMENT ME! - * - * @param aRequired DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public AbstractComponent addRequiredInterface( RequiredInterface aRequired) { required.add(aRequired); @@ -131,21 +95,11 @@ public abstract class AbstractComponent implements Component { return this; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ @Override public final String getName() { return name; } - /** - * DOCUMENT ME! - * - * @param aContext DOCUMENT ME! - */ @Override public void addContext(String aContext) { if (context == null) { @@ -155,21 +109,11 @@ public abstract class AbstractComponent implements Component { } } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ @Override public String getContext() { return context; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ @Override public String getQualifiedName() { if (context == null) { @@ -179,39 +123,23 @@ public abstract class AbstractComponent implements Component { return context + "." + getName(); } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ @Override public final List getProvidedInterfaces() { return Collections.unmodifiableList(provided); } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ @Override public final List getRequiredInterfaces() { return Collections.unmodifiableList(required); } - /** - * DOCUMENT ME! - * - * @param aScope DOCUMENT ME! - * - * @return DOCUMENT ME! - */ @Override public final Type start(Scope aScope) { LOG.info("Initialization starting '" + getQualifiedName() + "'"); List oldRemaining = remaining.get(); - remaining.set(new ArrayList(getProvidedInterfaces())); + remaining + .set(new ArrayList(getProvidedInterfaces())); try { Type runtime = doStart(aScope); @@ -224,63 +152,56 @@ public abstract class AbstractComponent implements Component { } } - /** - * DOCUMENT ME! - */ private void checkNotStartedInterfaces() { if (remaining.get().size() > 0) { - String notProvided = ""; + StringBuffer notProvided = new StringBuffer(); - for (ProvidedInterface provided : remaining.get()) { - notProvided += ("\nComponent " + getQualifiedName() - + " did not start interface " + provided); + for (ProvidedInterface providedIntf : remaining.get()) { + notProvided.append("\nComponent " + getQualifiedName() + + " did not start interface " + providedIntf); } - throw new SystemAssemblyException(notProvided); + throw new SystemAssemblyException(notProvided.toString()); } } /** - * Must be implemented for initializing the subsystem. The - * implementation must call {@link #addInterface(ProvidedInterface, - * Object, Scope)} for each service that is started. - * - * @param aScope DOCUMENT ME! - * + * Must be implemented for initializing the subsystem. The implementation + * must call {@link #addInterface(ProvidedInterface, Object, Scope)} for + * each service that is started. + * + * * @return Returns the runtime of the component. */ protected abstract Type doStart(Scope aScope); /** - * Implementations must call this method to indicate that a new - * service has been started. - * - * @param aDescriptor Provided interface. - * @param aService Implementation of the interface. - * @param aScope scope in which to publish the implementation. - * - * @throws SystemAssemblyException DOCUMENT ME! + * Implementations must call this method to indicate that a new service has + * been started. + * + * @param aDescriptor + * Provided interface. + * @param aService + * Implementation of the interface. + * @param aScope + * scope in which to publish the implementation. + * */ protected final void addInterface(ProvidedInterface aDescriptor, Object aService, Scope aScope) { - LOG.info("Interface '" + getQualifiedName() + "." - + aDescriptor.getName() + "' started."); + LOG.info("Interface '" + getQualifiedName() + "." + + aDescriptor.getName() + "' started."); if (!remaining.get().remove(aDescriptor)) { - throw new SystemAssemblyException("Component '" - + getQualifiedName() + "' started an unexpected interface '" - + aDescriptor - + "' that was not registerd as a provided interface before"); + throw new SystemAssemblyException("Component '" + + getQualifiedName() + "' started an unexpected interface '" + + aDescriptor + + "' that was not registerd as a provided interface before"); } aScope.publishInterface(aDescriptor, aService); } - /** - * DOCUMENT ME! - * - * @param aRuntime DOCUMENT ME! - */ @Override public void stop(Type aRuntime) { LOG.info("Stopping initiated '" + getQualifiedName() + "'"); @@ -288,51 +209,27 @@ public abstract class AbstractComponent implements Component { LOG.info("Stopping completed '" + getQualifiedName() + "'"); } - /** - * DOCUMENT ME! - * - * @param aRuntime DOCUMENT ME! - */ protected abstract void doStop(Type aRuntime); - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ @Override public String toString() { return getQualifiedName(); } - /** - * DOCUMENT ME! - * - * @param aName DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public ProvidedInterface findProvidedInterface(String aName) { - for (ProvidedInterface provided : getProvidedInterfaces()) { - if (provided.getName().equals(aName)) { - return provided; + for (ProvidedInterface providedIntf : getProvidedInterfaces()) { + if (providedIntf.getName().equals(aName)) { + return providedIntf; } } return null; } - /** - * DOCUMENT ME! - * - * @param aName DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public RequiredInterface findRequiredInterface(String aName) { - for (RequiredInterface required : getRequiredInterfaces()) { - if (required.getName().equals(aName)) { - return required; + for (RequiredInterface requiredIntf : getRequiredInterfaces()) { + if (requiredIntf.getName().equals(aName)) { + return requiredIntf; } }