KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.cayenne.access.DataDomain;
23 import org.apache.cayenne.access.DataNode;
24 import org.apache.cayenne.map.DataMap;
25 import org.apache.cayenne.map.DbAttribute;
26 import org.apache.cayenne.map.DbEntity;
27 import org.apache.cayenne.map.DbRelationship;
28 import org.apache.cayenne.map.ObjAttribute;
29 import org.apache.cayenne.map.ObjEntity;
30 import org.apache.cayenne.map.ObjRelationship;
31 import org.apache.cayenne.map.Procedure;
32 import org.apache.cayenne.map.ProcedureParameter;
33 import org.apache.cayenne.project.ProjectPath;
34 import org.apache.cayenne.query.ProcedureQuery;
35 import org.apache.cayenne.query.SQLTemplate;
36 import org.apache.cayenne.query.SelectQuery;
37
38 /**
39  * Validator of a single node in a project object tree. <i>Do not confuse with
40  * org.apache.cayenne.access.DataNode. </i>
41  *
42  * @author Andrus Adamchik
43  */

44 public abstract class TreeNodeValidator {
45
46     // initialize singleton validators
47
protected static final DomainValidator domainValidator = new DomainValidator();
48     protected static final DataNodeValidator nodeValidator = new DataNodeValidator();
49     protected static final DataMapValidator mapValidator = new DataMapValidator();
50     protected static final ObjEntityValidator objEntityValidator = new ObjEntityValidator();
51     protected static final ObjAttributeValidator objAttrValidator = new ObjAttributeValidator();
52     protected static final ObjRelationshipValidator objRelValidator = new ObjRelationshipValidator();
53     protected static final DbEntityValidator dbEntityValidator = new DbEntityValidator();
54     protected static final DbAttributeValidator dbAttrValidator = new DbAttributeValidator();
55     protected static final DbRelationshipValidator dbRelValidator = new DbRelationshipValidator();
56
57     protected static final ProcedureValidator procedureValidator = new ProcedureValidator();
58
59     protected static final ProcedureParameterValidator procedureParameterValidator = new ProcedureParameterValidator();
60     protected static final SelectQueryValidator selectQueryValidator = new SelectQueryValidator();
61
62     protected static final ProcedureQueryValidator procedureQueryValidator = new ProcedureQueryValidator();
63
64     protected static final SQLTemplateValidator sqlTemplateValidator = new SQLTemplateValidator();
65
66     /**
67      * Validates an object, appending any validation messages to the validator provided.
68      */

69     public static void validate(ProjectPath path, Validator validator) {
70         Object JavaDoc validatedObj = path.getObject();
71         TreeNodeValidator validatorObj = null;
72         if (validatedObj instanceof ObjAttribute) {
73             validatorObj = objAttrValidator;
74         }
75         else if (validatedObj instanceof ObjRelationship) {
76             validatorObj = objRelValidator;
77         }
78         else if (validatedObj instanceof ObjEntity) {
79             validatorObj = objEntityValidator;
80         }
81         else if (validatedObj instanceof DbAttribute) {
82             validatorObj = dbAttrValidator;
83         }
84         else if (validatedObj instanceof DbRelationship) {
85             validatorObj = dbRelValidator;
86         }
87         else if (validatedObj instanceof DbEntity) {
88             validatorObj = dbEntityValidator;
89         }
90         else if (validatedObj instanceof DataNode) {
91             validatorObj = nodeValidator;
92         }
93         else if (validatedObj instanceof DataMap) {
94             validatorObj = mapValidator;
95         }
96         else if (validatedObj instanceof DataDomain) {
97             validatorObj = domainValidator;
98         }
99         else if (validatedObj instanceof Procedure) {
100             validatorObj = procedureValidator;
101         }
102         else if (validatedObj instanceof ProcedureParameter) {
103             validatorObj = procedureParameterValidator;
104         }
105         else if (validatedObj instanceof SelectQuery) {
106             validatorObj = selectQueryValidator;
107         }
108         else if (validatedObj instanceof SQLTemplate) {
109             validatorObj = sqlTemplateValidator;
110         }
111         else if (validatedObj instanceof ProcedureQuery) {
112             validatorObj = procedureQueryValidator;
113         }
114         else {
115             // ignore unknown nodes
116
return;
117         }
118
119         validatorObj.validateObject(path, validator);
120     }
121
122     /**
123      * Constructor for TreeNodeValidator.
124      */

125     public TreeNodeValidator() {
126         super();
127     }
128
129     /**
130      * Validates an object, appending any warnings or errors to the validator. Object to
131      * be validated is the last object in a <code>treeNodePath</code> array argument.
132      * Concrete implementations would expect an object of a specific type. Otherwise,
133      * ClassCastException will be thrown.
134      */

135     public abstract void validateObject(ProjectPath treeNodePath, Validator validator);
136 }
137
Popular Tags