KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > integrity > IntegrityConf


1 /*
2   Copyright (C) 2002 Renaud Pawlak <renaud@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.integrity;
19
20 import org.objectweb.jac.core.rtti.CollectionItem;
21 import org.objectweb.jac.core.rtti.FieldItem;
22 import org.objectweb.jac.core.rtti.MethodItem;
23
24 public interface IntegrityConf {
25
26     /**
27      * Tells that the integrity aspect should maintain integrity
28      * between the roles of associations.
29      *
30      * <p>For instance, if you have a Customer class and an Order
31      * class:</p>
32      *
33      * <pre>
34      * ,----------. 1 n ,-------.
35      * | Customer |--------| Order |
36      * `----------' `-------'
37      * </pre>
38      *
39      * <p>You can declare an association made of Cutomer.orders and
40      * Order.customer, so that setting the cutomer of an order will
41      * automatically add this order in the customer's list of
42      * orders. And vice-versa.</p>
43      *
44      * @see org.objectweb.jac.core.rtti.RttiAC#declareAssociation(FieldItem,FieldItem)
45      */

46     void updateAssociations();
47
48     /**
49      * This method declares a repository collection.
50      *
51      * <p>When an object is added to a relation, it will be
52      * automatically added to the collection of the repository.
53      *
54      * @param repositoryName the JAC object's name of the repository
55      * @param collection the collection to add into (on the instance
56      * given as the first parameter)
57      * @param field objects that are set or added to this field are
58      * added to the repository */

59     void declareRepository(String JavaDoc repositoryName,
60                            CollectionItem collection,
61                            FieldItem field);
62
63     /**
64      * <p>Declare a referential integrity contraint.</p>
65      *
66      * <p>When an object is removed from the target collection, it will
67      * be checked wether it can be allowed.</p>
68      *
69      * <p>Suppose you have Customer class and an Invoice class :</p>
70      * <pre>
71      * ,-----------. 1 * ,----------. 1 * ,---------.
72      * | Customers |-------| Customer |-----------| Invoice |
73      * `-----------' `----------' `---------'
74      * </pre>
75      *
76      * <p>You do not want to allow the removal of a customer from the
77      * Customers repository if there are invoices for that customer. So
78      * you would add the following constraint:</p>
79      *
80      * <code>declareConstraint Invoice.customer Customers.customers FORBIDDEN;</code>
81      *
82      * @param relation
83      * @param target the collection on which checking will occur on
84      * remove, or the reference on which checking will occur when
85      * setting another value.
86      * @param constraint the type of the constraint. It may be
87      * "DELETE_CASCADE" (delete the object holding the reference on the
88      * object to be deleted), "SET_NULL" (set the reference to null, or
89      * remove the object from the collection), FORBIDDEN" (raise an
90      * exception).
91      */

92     void declareConstraint(FieldItem relation,
93                            FieldItem target, String JavaDoc constraint);
94
95     /**
96      * Use this configuration method to add a precondition on a
97      * object's field.
98      *
99      * <p>It means that the initial value of the field will be tested
100      * with the added constraint and if it is not valid, it will be
101      * rejected.</p>
102      *
103      * <p>Constraint methods must return a Boolean that is Boolean.TRUE
104      * if the test has been validated (passed), Boolean.FALSE else. The
105      * class <code>org.objectweb.jac.aspects.integrity.GenericConditions</code>
106      * contains basic tests such as <code>forbiddenValues</code> or
107      * <code>authorizedValues</code>.</p>
108      *
109      * @param field the field to constrain
110      * @param constraint the constraint method used to check the
111      * field's value
112      * @param params the parameters passed to the contraint method
113      * @param errorMsg the error message displayed if the checking has
114      * not been passed
115      *
116      * @see #addPostCondition(FieldItem,MethodItem,Object[],String)
117      */

118     void addPreCondition(FieldItem field,
119                          MethodItem constraint,
120                          Object JavaDoc[] params,
121                          String JavaDoc errorMsg);
122
123     /**
124      * Use this configuration method to add a postcondition on a
125      * object's field.
126      *
127      * <p>It means that the final value of the field will be tested
128      * with the added constraint and if it is not valid, it will be
129      * rejected.</p>
130      *
131      * <p>Constraint methods must return a Boolean that is Boolean.TRUE
132      * if the test has been validated (passed), Boolean.FALSE else. The
133      * class <code>org.objectweb.jac.aspects.integrity.GenericConditions</code>
134      * contains basic tests such as <code>forbiddenValues</code> or
135      * <code>authorizedValues</code>.</p>
136      *
137      * @param field the field to constrain
138      * @param constraint the constraint method used to check the
139      * field's value
140      * @param params the parameters passed to the contraint method
141      * @param errorMsg the error message displayed if the checking has
142      * not been passed
143      *
144      * @see #addPreCondition(FieldItem,MethodItem,Object[],String)
145      */

146     void addPostCondition(FieldItem field,
147                           MethodItem constraint,
148                           Object JavaDoc[] params,
149                           String JavaDoc errorMsg);
150
151 }
152
153
Popular Tags