architecture.doxy
1 /*!
2 \page architecture Architecture
3 <div class="has-toc"></div>
4 
5 # Architecture # {#arch_main}
6 
7 The main architectural concept of wCMF is the well known [Model-View-Controller]
8 (http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) pattern.
9 The following sections describe it's implementation in wCMF and introduce some
10 other key concepts, that are useful to know when using wCMF.
11 
12 ## Model ## {#arch_model}
13 
14 An application is usually based on a _domain model_ that represents the real-world
15 concepts of the domain of interest. In object oriented programming this model is
16 implemented using classes. Depending on the application requirements the instances
17 of several of these classes have to be persisted in a storage to keep the contained
18 data. These classes represent the _data model_. The classes that provide the
19 infrastructure for storing data form the _persistence layer_.
20 
21 wCMF defines \link wcmf::lib::persistence::PersistentObject `PersistentObject`\endlink
22 as base class for persistent domain classes. It mainly implements an unique identifier
23 for each instance (see \ref arch_oid), tracking of the persistent state, methods for setting
24 and getting values as well as callback methods for lifecycle events. For the composition
25 of object graphs the derived class \link wcmf::lib::model::Node `Node`\endlink is used
26 as base class. It implements relation support for persistent objects.
27 
28 To retrieve persisted objects \link wcmf::lib::persistence::PersistenceFacade `PersistenceFacade`\endlink
29 is used. The actual operations for creating, reading, updating and deleting objects
30 (e.g. SQL commands) are defined in classes implementing the
31 \link wcmf::lib::persistence::PersistenceMapper `PersistenceMapper`\endlink interface
32 (see [Data Mapper Pattern](http://martinfowler.com/eaaCatalog/dataMapper.html)).
33 Although not necessary there usually exists one mapper class for each persistent
34 domain class. Mapper classes are introduced to the persistent facade by configuration.
35 
36 \image html persistence.png "Persistence layer"
37 
38 Please refer to the section \ref persistence for a more detailed description of the
39 persistence layer.
40 
41 ### Object Identifier ### {#arch_oid}
42 
43 For handling lots of different domain objects an unique identification is crucial.
44 To achieve this, so-called _Object Identifiers_ (_OID_ or _object id_) are used.
45 Various strategies are possible to obtain these identifiers, e.g. a central registry.
46 
47 wCMF composes these object ids from the type of the persistent domain class and a
48 number, which is unique for each type (e.g. _Author::1_). It is important that the object's
49 type can be derived from the object id, because this enables the
50 \link wcmf::lib::persistence::PersistenceFacade `PersistenceFacade`\endlink to
51 determine the \link wcmf::lib::persistence::PersistenceMapper `PersistenceMapper`\endlink
52 for the given object from the configuration. The class
53 \link wcmf::lib::persistence::ObjectId `ObjectId`\endlink implements this concept.
54 
55 ## Presentation ## {#arch_presentation}
56 
57 The _presentation layer_ of a wCMF application enables users to interact with the
58 domain model.
59 
60 Each interaction is initiated by a _request_ and results in a _response_. In a web
61 application the request data is sent by the user's browser to the server as GET or
62 POST variables.
63 
64 wCMF's \link wcmf::lib::presentation::Application `Application`\endlink class
65 transforms the request data into a \link wcmf::lib::presentation::Request `Request`\endlink
66 instance. This instance is then passed to a
67 \link wcmf::lib::presentation::ActionMapper `ActionMapper`\endlink instance, which
68 creates the \link wcmf::lib::presentation::Response `Response`\endlink instance
69 and delegates the actual execution of the request to a
70 \link wcmf::lib::presentation::Controller `Controller`\endlink instance. Different
71 controllers exist for different actions (e.g.
72 \link wcmf::application::controller::ListController `ListController`\endlink for
73 listing objects, \link wcmf::application::controller::SearchController `SearchController`\endlink
74 for searching objects).
75 
76 The controller is determined by matching specific request parameters against a list
77 of so called _action keys_ (see \ref arch_actionkey). As the result of it's execution
78 each controller returns action key parameters in the response data. If these parameters
79 match an existing action key, the associated controller will be executed by passing
80 the current response as input. In this way complex tasks may be executed by chaining
81 several controller calls together.
82 
83 To support various data representations, a
84 \link wcmf::lib::presentation::format::Format `Format`\endlink instance is associated
85 with each request and response. The format is automatically determined by the HTTP
86 _Content-Type_ resp. _Accept_ headers. \link wcmf::lib::presentation::format::Format `Format`\endlink
87 implementations are responsible for de-/serializing the request and response data
88 into the desired format (e.g. _JSON_ or _SOAP_).
89 \link wcmf::lib::presentation::format::impl::HtmlFormat `HtmlFormat`\endlink especially
90 uses a \link wcmf::lib::presentation::view::View `View`\endlink instance to render
91 the response data into a HTML page. wCMF's uses [Smarty](http://www.smarty.net/)
92 as the default template engine for HTML output.
93 
94 \image html presentation.png "Presentation layer"
95 
96 Please refer to the section \ref presentation for a more detailed description of the
97 presentation layer.
98 
99 ### Action Key ### {#arch_actionkey}
100 
101 An important concept of wCMF is that of _Action Keys_. An action key describes the
102 state of the application together with the __action__ to be performed next. The state,
103 which the application is in, results from the current __controller__ and the __context__,
104 in which it is executed. Controllers must exist as classes, whereas contexts and
105 actions may be arbitrary strings.
106 
107 The string representation of an action key is as follows:
108 
109 ~~~~~~~~~~~~~{.ini}
110 controller?context?action
111 ~~~~~~~~~~~~~
112 
113 @note Since question marks (?) are used to separate the parts of an action key,
114 a question mark is not allowed inside the parts itself.
115 
116 wCMF uses action keys for the following concerns:
117 
118 1. In __routing definitions__ controller names are assigned action keys.
119  \link wcmf::lib::presentation::ActionMapper `ActionMapper`\endlink uses these
120  definitions to execute the correct controller when the application is in a
121  certain state.
122 2. In __view definitions__ template filenames are assigned to action keys.
123  \link wcmf::lib::presentation::view::View `View`\endlink determines the view
124  template to be displayed for the current application state.
125 3. In __permission definitions__ roles are assigned to action keys. In this case
126  the controller value of the action key is interpreted as resource and can
127  also define an entity type or entity instance.
128  \link wcmf::lib::security::PermissionManager `PermissionManager`\endlink uses
129  this when checking permissions on a given resource.
130 
131 Since parts of the action key can be omitted in the definition, an algorithm has
132 to choose, which action key fits a given value triplet best. This algorithm is
133 implemented in the method
134 \link wcmf::lib::config::ActionKey::getBestMatch `ActionKey::getBestMatch`\endlink.
135 It checks action key lists against the following search values until a match is
136 found:
137 
138 ~~~~~~~~~~~~~{.ini}
139  1. controller?context?action
140  2. controller??action
141  3. controller?context?
142  4. ?context?action
143  5. ??action
144  6. controller??
145  7. ?context?
146 ~~~~~~~~~~~~~
147 
148 As a rule of thumb the action key which describes the state of the application the
149 most accurate is favored.
150 
151 __Examples:__
152 
153 The following examples are taken from the `ActionMapping` configuration section,
154 which defines which \link wcmf::lib::presentation::Controller `Controller`\endlink
155 to execute for a given action key (see \ref pres_routingint).
156 
157 Always execute \link wcmf::application::controller::SaveController `SaveController`\endlink
158 when action _update_ is requested, no matter which state the application is in:
159 
160 ~~~~~~~~~~~~~{.ini}
161 ??update = wcmf\application\controller\SaveController
162 ~~~~~~~~~~~~~
163 
164 Always execute `AuthorController` when the application context is _author_ as
165 long as no action is specified:
166 
167 ~~~~~~~~~~~~~{.ini}
168 ?author? = app\src\controller\AuthorController
169 ~~~~~~~~~~~~~
170 */