KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > validation > impl > ValidateeImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.validation.impl;
21
22 import java.lang.reflect.Method JavaDoc;
23 import java.text.MessageFormat JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Collection JavaDoc;
26
27
28 import org.netbeans.modules.schema2beans.BaseBean;
29 import org.netbeans.modules.schema2beans.BaseProperty;
30
31 import org.netbeans.modules.j2ee.sun.validation.Constants;
32 import org.netbeans.modules.j2ee.sun.validation.util.BundleReader;
33 import org.netbeans.modules.j2ee.sun.validation.util.Utils;
34 import org.netbeans.modules.j2ee.sun.validation.Validatee;
35
36 /**
37  *
38  * @author Rajeshwar Patil
39  * @version %I%, %G%
40  */

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

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