KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ojb > constraints > ConstraintsBase


1 package xdoclet.modules.ojb.constraints;
2
3 /* Copyright 2004-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import xdoclet.modules.ojb.LogHelper;
19 import xdoclet.modules.ojb.model.ClassDescriptorDef;
20 import xdoclet.modules.ojb.model.DefBase;
21 import xdoclet.modules.ojb.model.PropertyHelper;
22
23 /**
24  * Base class for constraints providing some common functionality.
25  *
26  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
27  */

28 public abstract class ConstraintsBase
29 {
30     /** The checking levels */
31     public static final String JavaDoc CHECKLEVEL_NONE = "none";
32     public static final String JavaDoc CHECKLEVEL_BASIC = "basic";
33     public static final String JavaDoc CHECKLEVEL_STRICT = "strict";
34
35     /**
36      * Constraint that ensures that the proxy-prefetching-limit has a valid value.
37      *
38      * @param def The descriptor (class, reference, collection)
39      * @param checkLevel The current check level (this constraint is checked in basic and strict)
40      */

41     protected void checkProxyPrefetchingLimit(DefBase def, String JavaDoc checkLevel) throws ConstraintException
42     {
43         if (CHECKLEVEL_NONE.equals(checkLevel))
44         {
45             return;
46         }
47         if (def.hasProperty(PropertyHelper.OJB_PROPERTY_PROXY_PREFETCHING_LIMIT))
48         {
49             if (!def.hasProperty(PropertyHelper.OJB_PROPERTY_PROXY))
50             {
51                 if (def instanceof ClassDescriptorDef)
52                 {
53                     LogHelper.warn(true,
54                                    ConstraintsBase.class,
55                                    "checkProxyPrefetchingLimit",
56                                    "The class "+def.getName()+" has a proxy-prefetching-limit property but no proxy property");
57                 }
58                 else
59                 {
60                     LogHelper.warn(true,
61                                    ConstraintsBase.class,
62                                    "checkProxyPrefetchingLimit",
63                                    "The feature "+def.getName()+" in class "+def.getOwner().getName()+" has a proxy-prefetching-limit property but no proxy property");
64                 }
65             }
66     
67             String JavaDoc propValue = def.getProperty(PropertyHelper.OJB_PROPERTY_PROXY_PREFETCHING_LIMIT);
68     
69             try
70             {
71                 int value = Integer.parseInt(propValue);
72     
73                 if (value < 0)
74                 {
75                     if (def instanceof ClassDescriptorDef)
76                     {
77                         throw new ConstraintException("The proxy-prefetching-limit value of class "+def.getName()+" must be a non-negative number");
78                     }
79                     else
80                     {
81                         throw new ConstraintException("The proxy-prefetching-limit value of the feature "+def.getName()+" in class "+def.getOwner().getName()+" must be a non-negative number");
82                     }
83                 }
84             }
85             catch (NumberFormatException JavaDoc ex)
86             {
87                 if (def instanceof ClassDescriptorDef)
88                 {
89                     throw new ConstraintException("The proxy-prefetching-limit value of the class "+def.getName()+" is not a number");
90                 }
91                 else
92                 {
93                     throw new ConstraintException("The proxy-prefetching-limit value of the feature "+def.getName()+" in class "+def.getOwner().getName()+" is not a number");
94                 }
95             }
96         }
97     }
98 }
99
Popular Tags