KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > validation > impl > ValidateeImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * ValidateeImpl.java August 18, 2003, 4:58 PM
26  */

27
28 package com.sun.enterprise.tools.common.validation.impl;
29
30 import java.lang.reflect.Method JavaDoc;
31 import java.text.MessageFormat JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.Collection JavaDoc;
34
35
36 import org.netbeans.modules.schema2beans.BaseBean;
37 import org.netbeans.modules.schema2beans.BaseProperty;
38
39 import com.sun.enterprise.tools.common.validation.Constants;
40 import com.sun.enterprise.tools.common.validation.util.BundleReader;
41 import com.sun.enterprise.tools.common.validation.util.Utils;
42 import com.sun.enterprise.tools.common.validation.Validatee;
43
44 /**
45  *
46  * @author Rajeshwar Patil
47  * @version %I%, %G%
48  */

49
50 public class ValidateeImpl implements Validatee {
51     /* A class implementation comment can go here. */
52     private BaseBean baseBean = null;
53     
54     private Utils utils = null;
55     
56     /** Creates a new instance of ValidateeImpl */
57     public ValidateeImpl(Object JavaDoc baseBean){
58         this.baseBean = (BaseBean)baseBean;
59         utils = new Utils();
60     }
61
62
63     public ArrayList JavaDoc getElementNames(){
64         ArrayList JavaDoc elements = new ArrayList JavaDoc();
65         BaseProperty[] baseProperty = baseBean.listProperties();
66         int size = baseProperty.length;
67         for(int i=0; i<size; i++){
68             elements.add(baseProperty[i].getName());
69             ///String format =
70
/// BundleReader.getValue("Name_Value_Pair_Format"); //NOI18N
71
///Object[] arguments = new Object[]{"Name", //NOI18N
72
/// baseProperty[i].getName()};
73
///System.out.println(MessageFormat.format(format, arguments));
74
///arguments =
75
/// new Object[]{"FullName", baseProperty[i].getFullName()};//NOI18N
76
///System.out.println(MessageFormat.format(format, arguments));
77
}
78         return elements;
79     }
80
81
82     public ArrayList JavaDoc getElementDtdNames(){
83         ArrayList JavaDoc elements = new ArrayList JavaDoc();
84         BaseProperty[] baseProperty = baseBean.listProperties();
85         int size = baseProperty.length;
86         for(int i=0; i<size; i++){
87             elements.add(baseProperty[i].getDtdName());
88             ///String format =
89
/// BundleReader.getValue("Name_Value_Pair_Format"); //NOI18N
90
///Object[] arguments = new Object[]{"Dtd Name", //NOI18N
91
/// baseProperty[i].getDtdName()};
92
///System.out.println(MessageFormat.format(format, arguments));
93
}
94         return elements;
95     }
96
97
98     public boolean isIndexed(String JavaDoc elementName){
99         BaseProperty baseProperty = baseBean.getProperty(elementName);
100         boolean returnValue = false;
101         if(null != baseProperty) {
102             returnValue = baseProperty.isIndexed();
103         } else {
104             String JavaDoc format =
105                 BundleReader.getValue("Error_does_not_exists"); //NOI18N
106
Object JavaDoc[] arguments =
107                 new Object JavaDoc[]{"Property", elementName}; //NOI18N
108
String JavaDoc message = MessageFormat.format(format, arguments);
109             assert false : message;
110         }
111         return returnValue;
112     }
113
114
115     public int getElementCardinal(String JavaDoc elementName){
116         BaseProperty baseProperty = baseBean.getProperty(elementName);
117         int returnValue = -1;
118         if(null != baseProperty) {
119             returnValue = baseProperty.getInstanceType();
120         } else {
121             String JavaDoc format =
122                 BundleReader.getValue("Error_does_not_exists"); //NOI18N
123
Object JavaDoc[] arguments =
124                 new Object JavaDoc[]{"Property", elementName}; //NOI18N
125
String JavaDoc message = MessageFormat.format(format, arguments);
126             assert false : message;
127         }
128         return returnValue;
129     }
130
131
132     public int getCardinal(){
133         String JavaDoc name = baseBean.name();
134         BaseBean parent = baseBean.parent();
135         BaseProperty baseProperty = parent.getProperty(name);
136         return baseProperty.getInstanceType();
137     }
138
139
140     public boolean isBeanElement(String JavaDoc elementName){
141         BaseProperty baseProperty = baseBean.getProperty(elementName);
142         boolean returnValue = false;
143         if(null != baseProperty) {
144             returnValue = baseProperty.isBean();
145         } else {
146             String JavaDoc format =
147                 BundleReader.getValue("Error_does_not_exists"); //NOI18N
148
Object JavaDoc[] arguments =
149                 new Object JavaDoc[]{"Property", elementName}; //NOI18N
150
String JavaDoc message = MessageFormat.format(format, arguments);
151             assert false : message;
152         }
153         return returnValue;
154     }
155
156
157     public String JavaDoc getXPath(){
158         ///String format = BundleReader.getValue("Name_Value_Pair_Format");//NOI18N
159
///Object[] arguments = new Object[]{"Name", baseBean.name()}; //NOI18N
160
///System.out.println(MessageFormat.format(format, arguments));
161
///arguments = new Object[]{"FullName", baseBean.fullName()}; //NOI18N
162
///System.out.println(MessageFormat.format(format, arguments));
163

164         BaseBean bean = baseBean;
165         BaseBean parentBean = null;
166         String JavaDoc xpath = bean.dtdName();
167         ///boolean root = bean.isRoot();
168
boolean root = isRootElement(bean);
169         parentBean = bean.parent();
170         while(!root){
171             xpath = parentBean.dtdName() + Constants.XPATH_DELIMITER + xpath;
172             bean = parentBean;
173             parentBean = bean.parent();
174             ///root = bean.isRoot();
175
root = isRootElement(bean);
176         }
177         xpath = Constants.XPATH_DELIMITER + xpath;
178         return xpath;
179     }
180
181
182     public String JavaDoc getIndexedXPath() {
183         BaseBean bean = baseBean;
184         BaseBean parentBean = null;
185         String JavaDoc xpath = bean.dtdName();
186         int index = getIndex(baseBean);
187         if(index != -1){
188             xpath = utils.getIndexedName(xpath, index);
189         }
190
191         boolean root = isRootElement(bean);
192         parentBean = bean.parent();
193
194         String JavaDoc name = null;
195         while(!root){
196             name = parentBean.dtdName();
197             index = getIndex(parentBean);
198             if(index != -1) {
199                 name = utils.getIndexedName(name, index);
200             }
201             xpath = name + Constants.XPATH_DELIMITER + xpath;
202             bean = parentBean;
203             parentBean = bean.parent();
204             root = isRootElement(bean);
205         }
206         xpath = Constants.XPATH_DELIMITER + xpath;
207         return xpath;
208     }
209
210
211     boolean isRootElement(BaseBean bean){
212         BaseBean parent = bean.parent();
213         boolean root;
214         if(parent.name().equals(bean.name())){
215             root = true;
216         } else {
217             root = false;
218         }
219         return root;
220     }
221
222
223     int getIndex(BaseBean baseBean){
224         int index = -1;
225         boolean root = isRootElement(baseBean);
226         if(!root){
227             String JavaDoc name = baseBean.name();
228             BaseBean parent = baseBean.parent();
229             if(parent != null) {
230                 index = parent.indexOf(name, baseBean);
231             }
232         }
233         return index;
234     }
235     
236     
237     public Object JavaDoc getElement(String JavaDoc elementName, int index) {
238             return utils.getElement(elementName, index, baseBean);
239     }
240     
241     public Object JavaDoc getElement(String JavaDoc elementName) {
242         return utils.getElement(elementName, baseBean);
243     }
244
245     public Object JavaDoc[] getElements(String JavaDoc elementName) {
246         return utils.getElements(elementName, baseBean);
247     }
248     
249     public Method JavaDoc getMethod(String JavaDoc methodName) {
250         return utils.getMethod(utils.getClass(baseBean), methodName);
251     }
252
253     public Object JavaDoc invoke(Method JavaDoc method) {
254         return utils.invoke(baseBean, method);
255     }
256 }
257
Popular Tags