KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > ejbmodule > OneOneFinderModel


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  * OneOneFinderModel.java November 3, 2003, 12:14 PM
21  *
22  */

23
24 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule;
25
26 import java.util.ResourceBundle JavaDoc;
27
28 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Finder;
29 import org.netbeans.modules.j2ee.sun.share.configbean.CmpEntityEjb;
30 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.BeanTableModel;
31 import org.netbeans.modules.j2ee.sun.share.configbean.StorageBeanFactory;
32
33
34 /**
35  *
36  * @author Rajeshwar Patil
37  * @version %I%, %G%
38  */

39 public class OneOneFinderModel extends BeanTableModel {
40     /* A class implementation comment can go here. */
41
42     static final ResourceBundle JavaDoc bundle =
43         ResourceBundle.getBundle(
44             "org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule.Bundle"); //NOI18N
45

46
47     private static final String JavaDoc[] columnNames = {
48         bundle.getString("LBL_Method_Name"), //NOI18N
49
bundle.getString("LBL_Query_Params"), //NOI18N
50
bundle.getString("LBL_Query_Filter"), //NOI18N
51
bundle.getString("LBL_Query_Variables"), //NOI18N
52
bundle.getString("LBL_Query_Ordering")}; //NOI18N
53

54
55     protected String JavaDoc[] getColumnNames() {
56         return columnNames;
57     }
58
59
60     public Object JavaDoc getValueAt(int row, int column){
61         Object JavaDoc retValue = null;
62         Finder param = (Finder)getChildren().get(row);
63         if(param != null){
64             switch(column){
65                 case 0: {
66                     retValue = param.getMethodName();
67                 }
68                 break;
69                 case 1: {
70                     retValue = param.getQueryParams();
71                 }
72                 break;
73                 case 2: {
74                     retValue = param.getQueryFilter();
75                 }
76                 break;
77                 case 3: {
78                     retValue = param.getQueryVariables();
79                 }
80                 break;
81                 case 4: {
82                     retValue = param.getQueryOrdering();
83                 }
84                 break;
85                 default: {
86                     //control should never reach here
87
assert(false);
88                 }
89                 break;
90             }
91         }
92         return retValue;
93     }
94
95
96     //BeanTableModel Methods
97
public Object JavaDoc addRow(Object JavaDoc[] values){
98         StorageBeanFactory storageFactory = ((CmpEntityEjb) getParent()).getConfig().getStorageFactory();
99         Finder param = storageFactory.createFinder();
100         param.setMethodName((String JavaDoc)values[0]);
101         param.setQueryParams((String JavaDoc)values[1]);
102         param.setQueryFilter((String JavaDoc)values[2]);
103         param.setQueryVariables((String JavaDoc)values[3]);
104         param.setQueryOrdering((String JavaDoc)values[4]);
105
106         ((CmpEntityEjb)getParent()).addFinder(param);
107         getChildren().add(param);
108         fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
109         return param;
110     }
111
112
113     public void editRow(int row, Object JavaDoc[] values){
114         Finder param = (Finder)getChildren().get(row);
115         if(param != null){
116             param.setMethodName((String JavaDoc)values[0]);
117             param.setQueryParams((String JavaDoc)values[1]);
118             param.setQueryFilter((String JavaDoc)values[2]);
119             param.setQueryVariables((String JavaDoc)values[3]);
120             param.setQueryOrdering((String JavaDoc)values[4]);
121             fireTableDataChanged();
122         }
123     }
124
125
126     public void removeRow(int row){
127         ((CmpEntityEjb)getParent()).removeFinder(
128             (Finder)getChildren().get(row));
129         getChildren().remove(row);
130         fireTableRowsDeleted(row, row);
131     }
132
133
134     public Object JavaDoc[] getValues(int row){
135         Object JavaDoc[] values = new Object JavaDoc[5];
136         Finder finder =
137             (Finder)getChildren().get(row);
138         if(finder != null){
139             values[0] = (Object JavaDoc)finder.getMethodName();
140             values[1] = (Object JavaDoc)finder.getQueryParams();
141             values[2] = (Object JavaDoc)finder.getQueryFilter();
142             values[3] = (Object JavaDoc)finder.getQueryVariables();
143             values[4] = (Object JavaDoc)finder.getQueryOrdering();
144         }
145         return values;
146     }
147
148
149     //check whether the given object already exists.
150
public boolean alreadyExists(Object JavaDoc[] values){
151         boolean exists = false;
152
153         if(values != null){
154             String JavaDoc methodName = (String JavaDoc)values[0];
155             if(methodName != null){
156                 int count = getRowCount();
157                 Finder finder;
158                 for(int i=0; i<count; i++){
159                     finder = (Finder)getChildren().get(i);
160                     if(finder != null){
161                         if(methodName.equals(
162                                 finder.getMethodName())){
163                             exists = true;
164                             break;
165                         }
166                     }
167                 }
168             }
169         }
170         return exists;
171     }
172 }
173
Popular Tags