public abstract class AbstractComponent extends Object
component that needs initialization. We strongly recommend that component
implementations should be stateless and therefore thread-safe. It provides
an initialization state that helps to prevent accidental coding mistakes.
E.g. you can do this:
public class MyComponentImpl extendsIn advance to this class, we recommend that you extendAbstractComponent{ private OtherComponent otherComponent; public void setOtherComponent(OtherComponent otherComponent) {getInitializationState().requireNotInitilized(); this.otherComponent = otherComponent; } public voiddoInitialize(){ if (this.otherCompoent == null) { setOtherComponent(new OtherComponentDefault()); } } public void doSomething() {getInitializationState().requireInitilized(); // ... do something ... } }
AbstractLoggableComponent.AbstractLoggableComponent| Modifier and Type | Field and Description |
|---|---|
private InitializationState |
initializationState |
| Constructor and Description |
|---|
AbstractComponent()
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
doInitialize()
This method performs the actual
initialization. |
protected void |
doInitialized()
This method is invoked at the end of the actual
initialization. |
protected InitializationState |
getInitializationState()
This method gets the
InitializationState of this component. |
void |
initialize()
This method initializes this class.
|
private final InitializationState initializationState
getInitializationState()@PostConstruct public final void initialize()
protected void doInitialize()
initialization. It is called when
initialize() is invoked for the first time. super.doInitialize().protected void doInitialized()
initialization. It is called when
initialize() is invoked for the first time after doInitialize() is completed and
initialization-state has changed to
initialized. super.doInitialized().protected final InitializationState getInitializationState()
InitializationState of this component.initialize(),
InitializationState.requireInitilized(),
InitializationState.requireNotInitilized()Copyright © 2001–2015 mmm-Team. All rights reserved.