001: package xdoclet.modules.ojb.constraints;
002:
003: /* Copyright 2004-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import xdoclet.modules.ojb.LogHelper;
019: import xdoclet.modules.ojb.model.ClassDescriptorDef;
020: import xdoclet.modules.ojb.model.DefBase;
021: import xdoclet.modules.ojb.model.PropertyHelper;
022:
023: /**
024: * Base class for constraints providing some common functionality.
025: *
026: * @author <a href="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
027: */
028: public abstract class ConstraintsBase {
029: /** The checking levels */
030: public static final String CHECKLEVEL_NONE = "none";
031: public static final String CHECKLEVEL_BASIC = "basic";
032: public static final String CHECKLEVEL_STRICT = "strict";
033:
034: /**
035: * Constraint that ensures that the proxy-prefetching-limit has a valid value.
036: *
037: * @param def The descriptor (class, reference, collection)
038: * @param checkLevel The current check level (this constraint is checked in basic and strict)
039: */
040: protected void checkProxyPrefetchingLimit(DefBase def,
041: String checkLevel) throws ConstraintException {
042: if (CHECKLEVEL_NONE.equals(checkLevel)) {
043: return;
044: }
045: if (def
046: .hasProperty(PropertyHelper.OJB_PROPERTY_PROXY_PREFETCHING_LIMIT)) {
047: if (!def.hasProperty(PropertyHelper.OJB_PROPERTY_PROXY)) {
048: if (def instanceof ClassDescriptorDef) {
049: LogHelper
050: .warn(
051: true,
052: ConstraintsBase.class,
053: "checkProxyPrefetchingLimit",
054: "The class "
055: + def.getName()
056: + " has a proxy-prefetching-limit property but no proxy property");
057: } else {
058: LogHelper
059: .warn(
060: true,
061: ConstraintsBase.class,
062: "checkProxyPrefetchingLimit",
063: "The feature "
064: + def.getName()
065: + " in class "
066: + def.getOwner().getName()
067: + " has a proxy-prefetching-limit property but no proxy property");
068: }
069: }
070:
071: String propValue = def
072: .getProperty(PropertyHelper.OJB_PROPERTY_PROXY_PREFETCHING_LIMIT);
073:
074: try {
075: int value = Integer.parseInt(propValue);
076:
077: if (value < 0) {
078: if (def instanceof ClassDescriptorDef) {
079: throw new ConstraintException(
080: "The proxy-prefetching-limit value of class "
081: + def.getName()
082: + " must be a non-negative number");
083: } else {
084: throw new ConstraintException(
085: "The proxy-prefetching-limit value of the feature "
086: + def.getName()
087: + " in class "
088: + def.getOwner().getName()
089: + " must be a non-negative number");
090: }
091: }
092: } catch (NumberFormatException ex) {
093: if (def instanceof ClassDescriptorDef) {
094: throw new ConstraintException(
095: "The proxy-prefetching-limit value of the class "
096: + def.getName()
097: + " is not a number");
098: } else {
099: throw new ConstraintException(
100: "The proxy-prefetching-limit value of the feature "
101: + def.getName() + " in class "
102: + def.getOwner().getName()
103: + " is not a number");
104: }
105: }
106: }
107: }
108: }
|