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 the framework.
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 some 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, POST, etc.
62 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 can 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 can be arbitrary strings.
106 
107 The string representation of an action key is as follows:
108 
109 <div class="ini">
110 ```
111 controller?context?action
112 ```
113 </div>
114 
115 @note Since question marks (?) are used to separate the parts of an action key,
116 a question mark is not allowed inside the parts itself.
117 
118 wCMF uses action keys in the following places:
119 
120 1. In __routing definitions__ controller names are assigned to action keys.
121  \link wcmf::lib::presentation::ActionMapper `ActionMapper`\endlink uses these
122  definitions to execute the correct controller when the application is in a
123  certain state.
124 2. In __view definitions__ template filenames are assigned to action keys.
125  \link wcmf::lib::presentation::view::View `View`\endlink determines the view
126  template to be displayed for the current application state.
127 3. In __permission definitions__ roles are assigned to action keys. In this case
128  the controller value of the action key is interpreted as resource and can
129  also define an entity type or entity instance.
130  \link wcmf::lib::security::PermissionManager `PermissionManager`\endlink uses
131  this when checking permissions on a given resource.
132 
133 Since parts of the action key can be omitted in the definition, an algorithm has
134 to choose, which action key fits a given value triple best. This algorithm is
135 implemented in the method
136 \link wcmf::lib::config::ActionKey::getBestMatch `ActionKey::getBestMatch`\endlink.
137 It checks action key lists against the following search values until a match is
138 found:
139 
140 <div class="ini">
141 ```
142  1. controller?context?action
143  2. controller??action
144  3. controller?context?
145  4. ?context?action
146  5. ??action
147  6. controller??
148  7. ?context?
149 ```
150 </div>
151 
152 As a rule of thumb the action key which describes the state of the application the
153 most accurate is favored.
154 
155 __Examples:__
156 
157 The following examples are taken from the `ActionMapping` configuration section,
158 which defines which \link wcmf::lib::presentation::Controller `Controller`\endlink
159 to execute for a given action key (see \ref pres_routingint).
160 
161 Always execute \link wcmf::application::controller::SaveController `SaveController`\endlink
162 when action _update_ is requested, no matter which state the application is in:
163 
164 <div class="ini">
165 ```
166 ??update = wcmf\application\controller\SaveController
167 ```
168 </div>
169 
170 Always execute `AuthorController` when the application context is _author_ as
171 long as no action is specified:
172 
173 <div class="ini">
174 ```
175 ?author? = app\src\controller\AuthorController
176 ```
177 </div>
178 */