DCL Manual |
---|
Federal University of Minas Gerais
September 19, 2012
DCL (Dependency Constraint Language) is a declarative, statically checked domain-specific language that supports the definition of structural constraints between modules. The main purpose of the proposed language is to support the definition of constraints between modules, restricting the spectrum of dependencies that are allowed in object-oriented systems.
To use DCL, you must have installed the IDE Eclipse. The plugin has primarily been tested with Eclipse 3.7 and should work with 3.x releases, but let us know if you have any problems.
The plugin runs under Java 1.5/5.0, or newer.
To install DCL, please follow the steps below:
The procedure above is also explained using this video.
Example. Assume the following definitions:
1: module Math: java.lang.Math 2: module Exception: java.lang.RuntimeException, java.io.IOException
Math
(line 1) includes only class java.lang.Math
.
In line 2, module Exception
consists of classes java.lang.RuntimeException
and java.io.IOException
.
*
selects all classes of a package.Example. Assume the following definition:
1: module View: org.foo.view.*
View
contains all classes of package org.foo.view
.Example. Assume the following definition:
1: module Model: org.foo.model.**
Model
includes all classes of package org.foo.model
and its internal packages,
such as org.foo.model.dao, org.foo.model.dao.impl, org.foo.model.dto,
etc.
+
selects subtypes of a given type.Example. Assume the following definition:
1: module Remote: java.rmi.UnicastRemoteObject+
Remote
denotes all subclasses of java.rmi.UnicastRemoteObject
.
Example. Assume the following definition:
1: module Frame: "org.foo.[a-zA-Z0-9/.]*Frame"
Frame
consists of all classes whose qualified name begins with org.foo.
and ends with Frame
.
Example. Assume the following definition:
1: module DataStructure: org.foo.util.*, org.foo.view.Tree
DataStructure
includes all classes of package org.foo.util
and class
Tree
of package org.foo.view
.
A
(using the new operator) in a module that has not been defined as a factory for this type.
• only MA can-dep MA
: Only classes of module MA
can depend on types defined in module MB
.
The literal dep
refers to dependency type, which can be either more generic (depend
)
or more specific (access, declare, create, extend, implement, throw, and useannotation
).
For example, the constraint only DAOFactory can-create DAO
defines that only a factory class can create data access objects.
• MA can-dep-only MB
: Classes of module MA
can depend only on types defined in module MB
.
For example, the constraint Util can-depend-only Util, $java
defines that utility classes can only depend on their own classes or Java API classes.
• MA cannot-dep MB
: Classes of module MA
cannot depend on types defined in module MB
.
For example, the constraint Facade cannot-handle DTO
defines that facade classes cannot manipulate entity classes.
Example. Assume the following DCL constraints:
1: module Formulas: org.foo.formulas.* 2: only Formulas can-access java.lang.Math
Formulas
groups the classes from package org.foo.formulas
(line 1).
Then, in line 2, a restriction only allows module Formulas
to access the standard Java class that provides mathematical operations.
Otherwise, DCL will report an architectural violation (divergence).
Example. Assume the following DCL constraints:
1: module DomainFacades: org.foo.facades.* 2: module Domain: org.foo.model.Domain+ 3: DomainFacades can-declare-only Domain, $java
DomainFacades
groups all facade classes (line 1)
and module Domain
refers to domain classes, i.e., subclasses from org.foo.model.Domain
(line 2).
Then, in line 3, a constraint defines that module DomainFacades
can declare only domain objects and types of Java library.
Otherwise, DCL will report an architectural violation (divergence).
Example. Assume the following DCL constraints:
1: module Factory: org.foo.Factory 2: module Product: org.foo.Product+ 3: only Factory can-create Product
Factory
contains only the class org.foo.Factory
(line 1)
and module Product
groups the class org.foo.Product
and its subclasses (line 2).
Then, in line 3, a constraint defines that only module Factory
can create products, i.e., instantiate classes from module Product
.
Otherwise, DCL will report an architectural violation (divergence).
Example. Assume the following DCL constraints:
1: module Servlets: org.foo.controller.servlets.* 2: module BaseHttpServlet: javax.servlet.http.HttpServlet 3: only Servlets can-extend BaseHttpServlet
Servlets
contains all classes from package org.foo.controller.servlets
(line 1) and module BaseHttpServlet
refers to the class javax.servlet.http.HttpServlet
, which is the default Java class to handle requests and responses using the HTTP
protocol (line 2).
Then, in line 3, a restriction ensures that only classes from module Servlets
are allowed to extend the class javax.servlet.http.HttpServlet
.
Otherwise, DCL will report an architectural violation (divergence).
Example. Assume the following DCL constraints:
1: module Filters: "org.foo.[a-zA-Z0-9/.]*Filter" 2: Filters can-implement-only java.util.EventListener
Filters
groups the classes from package org.foo
that have sufix Filter
(line 1).
Then, in line 2, a constraint defines that classes from module Filters
can implement only the interface java.util.EventListener.
Otherwise, DCL will report an architectural violation (divergence).
Example. Assume the following DCL constraints:
1: module DAO: "org.foo.model.dao.[a-zA-Z0-9/.]*DAO" 2: DAO cannot-throw java.sql.SQLException+
DAO
contains classes from package org.foo.model.dao
that have suffix DAO
(line 1).
Then, in line 2, a restriction prohibits that methods from DAO
classes returns with exceptions from JDBC library activated (i.e., exceptions like java.sql.SQLException
and its subclasses).
Otherwise, DCL will report an architectural violation (divergence).
Example. Assume the following DCL constraints:
1: $system cannot-useannotation java.lang.SuppressWarnings
$system
, which refers to the class of the system under analysis.
Therefore, this restriction prohibits any class of the system to use the annotation
java.lang.SuppressWarnings
, which is a native annotation of Java
responsible for suppressing warnings.
Otherwise, DCL will report an architectural violation (divergence).
P
do not implement an
interface I
, as determined by the intended architecture of the system.
• MA must-dep MB
: Classes of module MA
must depend on types defined
in module MB
. For example, the constraint DTO must-implement
java.io.Serializable
defines that entity classes must implement
Java’s serializable interface.
Example. Assume the following DCL constraints:
1: module Servlets: org.foo.controller.servlets.* 2: module BaseHttpServlet: javax.servlet.http.HttpServlet 3: Servlets must-extend BaseHttpServlet
Servlets
contains the classes of package
org.foo.controller.servlets
(line 1) and module BaseHttpServlet
refers to class javax.servlet.http.HttpServlet
,
which is the standard class to handle requests and responses using HTTP
protocol.
Then, in line 3, a constraint requires that the classes of module Servlets
extend the class javax.servlet.http.HttpServlet
.
Otherwise, DCL will report an architectural violation (absence).Example. Assume the following DCL constraints:
1: module Filters: "org.foo.[a-zA-Z0-9/.]*Filter" 2: Filters must-implement java.util.EventListener
Filters
groups classes from package org.foo
that have suffix Filter
(line 1).
Then, in line 2, a constraint requires that classes from module Filters
must implement the interface java.util.EventListener
.
Otherwise, DCL will report an architectural violation (absence).Example. Assume the following DCL constraints:
1: module DAO: org.foo.model.dao.impl.* 2: module DAOException: org.foo.model.dao.DAOException 3: DAO must-throw DAOException
DAO
groups all classes of package org.foo.model.dao.impl
(line 1)
and module DAOException
(line 2) refers to class org.foo.model.dao.DAOException
.
Then, in line 3, a constraint requires that all methods declared in module DAO
must declare that they can return with exceptions declared in module DAOException
.
Otherwise, DCL will report an architectural violation (absence).Example. Assume the following DCL constraints:
1: module DTO: org.foo.model.dto.* 2: module JPA: javax.persistence.** 3: DTO must-useannotation JPA
DTO
(line 1) groups all classes of package org.foo.model.dto
and module JPA
(line 2) includes classes of javax.persistence
and its internal packages.
Then, in line 3, a constraint requires that all classes in module DTO
must use at least an annotation declared in module JPA
.
Otherwise, DCL will report an architectural violation (absence).