Fork me on GitHub

Create your Components

Component allow reusability and provide good SoC

JRebirth Components

Components definition

A component is a top-level actor of the wB-CS-Mvc pattern.

Each component can communicate with other in a simple way. They are loosely coupled with each other and with the engine itself.

There are 3+1 kinds of components:

  • Command
  • Service
  • Model
  • Behavior

Wave, View and Controller are not JRebirth Components.

Component Overview - Class Diagram

Component Features

Listening Waves

Each Component is able to receive Wave notifications, for doing that they shall listen a WaveType to get registered into the Notifier.

When a Wave is emitted from elsewhere in the application, the Notifier will call right handling method of the Component registered.

It’s possible to use a WaveChecker to filter Wave using a same WaveType.

The listen method taking a Method as parameter is used in conjuction with @OnWave annotation.

Warning: This registration creates a strong reference to Notifier and so avoid the Component to be released and collected by the garbage collector, this can creates memory leaks so don’t forget to call unlisten method when you don’t want to retain the Component.

Please note that if developerMode (developerMode=true) is activated, Wave contract will be checked at runtime and will throw an exception if errors are detected in order to let developers fix it as soon as possible, this detection is only performed when listen methods are called.

47
59
72
79
void listen(final WaveType... waveType);
void listen(final WaveChecker waveChecker, final WaveType... waveType);
void listen(final WaveChecker waveChecker, final Method method, final WaveType... waveType);
void unlisten(final WaveType... waveTypes);

You can learn more about Wave and Notifier on their dedicated documentation pages.

Sending Waves

Any Component is able to emit a new Wave and let the Notifier dispath it to registered Component.

88
100
112
void sendWave(final Wave wave);
<WB extends WaveBean> Wave sendWave(final WaveType waveType, final WB waveBean);
Wave sendWave(final WaveType waveType, final WaveData<?>... waveData);

Parenthood

119
126
152
Component<?> rootComponent();
void rootComponent(final Component<?> rootComponent);
<C extends Component<?>> C findInnerComponent(final InnerComponent<C> innerComponent);

Ready for Facade usage

42
73
void setup() throws CoreException;
boolean release();
61
66
UniqueKey<R> key();
void key(final UniqueKey<R> key);

Ready for Command usage

47
58
70
81
<C extends Command> C getCommand(final Class<C> clazz, final Object... keyPart);
<C extends Command> C getCommand(final UniqueKey<C> commandKey);
<C extends Command> List<C> getCommands(final Class<C> clazz, final Object... keyPart);
<C extends Command> List<C> getCommands(final UniqueKey<C> commandKey);
93
108
Wave callCommand(final Class<? extends Command> commandClass, final WaveData<?>... data);
Wave callCommand(final Class<? extends CommandBean<? extends WaveBean>> commandClass, final WaveBean waveBean, final WaveBean... waveBeans);

Ready for Service usage

47
58
70
81
<S extends Service> S getService(final Class<S> clazz, final Object... keyPart);
<S extends Service> S getService(final UniqueKey<S> serviceKey);
<S extends Service> List<S> getServices(final Class<S> clazz, final Object... keyPart);
<S extends Service> List<S> getServices(final UniqueKey<S> serviceKey);
96
109
<WB extends WaveBean> Wave returnData(final Class<? extends Service> serviceClass, final WaveType waveType, final WB waveBean);
Wave returnData(final Class<? extends Service> serviceClass, final WaveType waveType, final WaveData<?>... data);

Ready for Model usage

45
56
68
79
<M extends Model> M getModel(final Class<M> clazz, final Object... keyPart);
<M extends Model> M getModel(final UniqueKey<M> modelKey);
<M extends Model> List<M> getModels(final Class<M> clazz, final Object... keyPart);
<M extends Model> List<M> getModels(final UniqueKey<M> modelKey);
93
105
<WB extends WaveBean> Wave attachUi(final Class<? extends Model> modelClass, final WB waveBean);
Wave attachUi(final Class<? extends Model> modelClass, final WaveData<?>... data);

Behaviored Component Features

Manage Behavior

Manage Behavior Data