KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > project > validator > ProcedureValidator


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

19
20 package org.apache.cayenne.project.validator;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.apache.cayenne.map.DataMap;
26 import org.apache.cayenne.map.Procedure;
27 import org.apache.cayenne.project.ProjectPath;
28 import org.apache.cayenne.util.Util;
29
30 /**
31  * Validator for stored procedures.
32  *
33  * @author Andrus Adamchik
34  */

35 public class ProcedureValidator extends TreeNodeValidator {
36
37     public void validateObject(ProjectPath treeNodePath, Validator validator) {
38         Procedure procedure = (Procedure) treeNodePath.getObject();
39         validateName(procedure, treeNodePath, validator);
40
41         // check that return value is present
42
if (procedure.isReturningValue()) {
43             List JavaDoc parameters = procedure.getCallParameters();
44             if (parameters.size() == 0) {
45                 validator.registerWarning(
46                     "Procedure returns a value, but has no parameters.",
47                     treeNodePath);
48             }
49         }
50     }
51
52     protected void validateName(
53         Procedure procedure,
54         ProjectPath path,
55         Validator validator) {
56         String JavaDoc name = procedure.getName();
57
58         // Must have name
59
if (Util.isEmptyString(name)) {
60             validator.registerError("Unnamed Procedure.", path);
61             return;
62         }
63
64         DataMap map = (DataMap) path.getObjectParent();
65         if (map == null) {
66             return;
67         }
68
69         // check for duplicate names in the parent context
70
Iterator JavaDoc it = map.getProcedures().iterator();
71         while (it.hasNext()) {
72             Procedure otherProcedure = (Procedure) it.next();
73             if (otherProcedure == procedure) {
74                 continue;
75             }
76
77             if (name.equals(otherProcedure.getName())) {
78                 validator.registerError("Duplicate Procedure name: " + name + ".", path);
79                 break;
80             }
81         }
82     }
83
84 }
85
Popular Tags