allows the visual composition of components by
constructing CompJava diagrams and generating
code from them. For a graphical representation of
component composition, we use CompJava
component diagrams which are UML 2 component
diagrams (OMG, 2007) enriched with component
fragments and plugs.
Component fragments structure the component
code so that a component has (practically) no
methods. A component fragment may be used as a
kind of filter for subcomponents or for building a
component directly from Java code. A plug is used
as a connection point for the “wiring“.
We use the composition of a chat client of an
instant messaging system as a running example.
Instant messaging is a distributed application formed
from services, distributed components and local
components. Here we present mainly local aspects.
The instant messaging system was developed by a
student without prior knowledge of CompJava as a
diploma thesis (M. Klenk, 2002).
2.1 Example
The CompJava Designer (see Figure 1) displays: a
CompJava diagram in its main window; a palette
with tools for constructing CompJava diagrams; and
(bottom) a textual editor for properties of CompJava
diagram objects. The diagram is a CompJava
composition design diagram that shows the design of
the composition of the MainWindow component of
the chat client.
MainWindow is a component of component type
MainWindowType (analogous to class and interface).
It presents in encapsulated windows all information
about chats and users except for the exchanged
messages. MainWindow receives new information
from the server about events via the provided
MainWinEvent port, and it sends off information
about events from its user via the required
MainWinInput port. It is composed from
subcomponents with the types
MainWindowGUIType, DiscussionWindow-Type,
LoginWindowType, and ConfirmLoginWindowType,
and from two component fragments implementing
the interface MainWinEvent res. InnerEvent.
The inside of the ports of a parent component
like MainWindow may be “wired“ to ports of
subcomponents or to component fragments like that
implementing MainWinEvent. Ports of
subcomponents may be “wired“ to ports of other
subcomponents, like the required ports of
MainWindowGUIType to provided ports of
DiscussionWindowType and LoginWindowType, or
via the intermediary of a plug (depicted by a
diamond) like pInnerEvent of type InnerEvent (see
middle right) to a component fragment like the one
implementing the interface InnerEvent.
The “wiring“, depicted by arrows, which
represents the connect- and attach-statements of the
CompJava language (compare 3.2), is subject to
consistency constraints. The conditions to be
fulfilled for composing components are: the port-
matching constraint is that a provided (port)
interface extends (incl. equals) a required (port)
interface; and the n:1 multiplicity constraint is that a
required port is connected or attached to only one
provided port res. plug, and a plug is attached to
only one component fragment or provided port.
These constraints are checked in real-time by the
editor.
2.2 CompJava Diagrams
The CompJava Designer allows constructing four
different kinds of CompJava diagrams:
• A Port Interface Diagram defines port
interfaces in the form of Java interfaces (in
UML or text form).
• A Component Type Diagram defines a
component type specifying all port interfaces by
which a component of that type may collaborate
with the outside. It specifies also the
distribution-related property whether the ports
may be invoked remotely (via RMI/Corba) or
may define services.
• A Composition Design Diagram shows the
design of the composition of a component (see
Figure 1). It specifies: the component type (but
not name) of subcomponents; component
fragments; the wiring; and also whether the
implementation of the component may be
distributed, i.e. it may have remote
subcomponents. The design of a component
fragment specifies the interface it implements; it
specifies indirectly (via the wiring) the plugs or
ports from which it may invoke methods
• A Composition Implementation Diagram
shows the implementation of the composition of
a component. It is constructed from a
composition design diagram by selecting the
subcomponents, which each must have the
specified component type; and by implementing
the specified component fragments, and
possibly inner classes. A component fragment is
implemented either by an anonymous class, an
inner class or as a method block (the latter is
depicted like an anonymous class without class
VISUAL COMPOSITION OF COMPONENT SYSTEMS
133