KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > sunresources > beans > FieldHelper


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  * FieldHelper.java
21  *
22  * Created on October 5, 2002, 6:20 PM
23  */

24 package org.netbeans.modules.j2ee.sun.sunresources.beans;
25
26 import java.util.Vector JavaDoc;
27
28
29 /**
30  *
31  * @author shirleyc
32  */

33 public class FieldHelper {
34
35     public static String JavaDoc[] getFieldNames(Wizard wiz) {
36         FieldGroup[] groups = wiz.getFieldGroup();
37         Vector JavaDoc vec = new Vector JavaDoc();
38         for (int i = 0; i < groups.length; i++) {
39             Field[] fields = groups[i].getField();
40             for (int j = 0; j < fields.length; j++) {
41                 vec.add(fields[j].getName());
42             }
43         }
44         String JavaDoc[] result = new String JavaDoc[vec.size()];
45         return (String JavaDoc[])vec.toArray(result);
46     }
47     
48     public static Field getField(FieldGroup group, String JavaDoc fieldName) {
49         Field[] fields = group.getField();
50         for (int i = 0; i < fields.length; i++) {
51             if (fields[i].getName().equals(fieldName)){
52                 return fields[i];
53             }
54         }
55         return null;
56     }
57         
58     public static String JavaDoc getFieldType(Field fld) {
59         return fld.getAttributeValue("field-type"); //NOI18N
60
}
61     
62     public static boolean isList(Field fld) {
63         return fld.getAttributeValue("field-type").equals("list"); //NOI18N
64
}
65     
66     public static boolean isInt(Field fld) {
67         return fld.getAttributeValue("field-type").equals("int"); //NOI18N
68
}
69     
70     public static boolean isTextArea(Field fld) {
71         return fld.getAttributeValue("field-type").equals("textarea"); //NOI18N
72
}
73     
74     public static String JavaDoc[] getTags(Field fld) {
75         return fld.getTag().getTagItem();
76     }
77     
78     public static String JavaDoc getDefaultValue(Field fld) {
79         return fld.getFieldValue().getDefaultFieldValue();
80     }
81         
82     public static String JavaDoc getConditionalFieldValue(Field fld, String JavaDoc optionName) {
83         OptionValuePair[] pairs = fld.getFieldValue().getOptionValuePair();
84         for (int i = 0; i < pairs.length; i++) {
85             if (pairs[i].getOptionName().equals(optionName)) {
86                 return pairs[i].getConditionalValue();
87             }
88         }
89         return fld.getFieldValue().getDefaultFieldValue();
90     }
91     
92     public static String JavaDoc getOptionNameFromValue(Field urlField, String JavaDoc connUrl) {
93         String JavaDoc vendorName = ""; //NOI18N
94
OptionValuePair[] options = urlField.getFieldValue().getOptionValuePair();
95         for (int i = 0; i < options.length; i++) {
96             String JavaDoc condUrl = options[i].getConditionalValue();
97             if(connUrl.indexOf(condUrl) != -1){
98                 return options[i].getOptionName();
99             }
100         }
101         return vendorName;
102     }
103     
104     public static String JavaDoc getReplacedConditionalFieldValue(Field fld, String JavaDoc optionName) {
105         return getConditionalFieldValue(fld, optionName).replace('#', '<').replace('$', '>'); //NOI18N
106
}
107     
108     public static String JavaDoc toUrl(String JavaDoc str) {
109         return str.replace('#', '<').replace('$', '>'); //NOI18N
110
}
111         
112     /*
113      * return all the fields in group whose name are not in fieldNames
114      */

115     public static String JavaDoc[] getRemainingFieldNames(FieldGroup group, Vector JavaDoc fieldNames) {
116         Field[] allFields = group.getField();
117         Vector JavaDoc vec = new Vector JavaDoc();
118         for (int i = 0; i < allFields.length; i++) {
119 // Reporter.info(allFields[i].getName());
120
if (!fieldNames.contains(allFields[i].getName())) {
121 // Reporter.info("contained"); //NOI18N
122
vec.add(allFields[i].getName());
123             }
124         }
125         String JavaDoc[] remainingFields = new String JavaDoc[vec.size()];
126         return (String JavaDoc[])vec.toArray(remainingFields);
127     }
128 }
129
Popular Tags