001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.visualweb.dataconnectivity.designtime;
043:
044: import com.sun.rave.designtime.Constants;
045: import com.sun.rave.designtime.base.CategoryDescriptors;
046: import com.sun.sql.rowset.CachedRowSetXImpl;
047: import com.sun.sql.rowset.CachedRowSetXImpl5;
048: import org.netbeans.modules.visualweb.faces.dt.data.*;
049: import java.awt.Image;
050: import java.beans.BeanDescriptor;
051: import java.beans.BeanInfo;
052: import java.beans.EventSetDescriptor;
053: import java.beans.IntrospectionException;
054: import java.beans.MethodDescriptor;
055: import java.beans.PropertyDescriptor;
056: import java.beans.SimpleBeanInfo;
057: import java.sql.Connection;
058: import java.sql.ResultSet;
059: import java.sql.Savepoint;
060: import javax.sql.RowSetListener;
061: import org.openide.util.Exceptions;
062:
063: public class CachedRowSetXImplBeanInfo extends SimpleBeanInfo {
064:
065: public CachedRowSetXImplBeanInfo() throws NoSuchMethodException {
066: }
067:
068: protected BeanDescriptor beanDescriptor;
069:
070: public BeanDescriptor getBeanDescriptor() {
071: if (beanDescriptor == null) {
072: beanDescriptor = new BeanDescriptor(
073: CachedRowSetXImpl.class, null);
074: /*
075: beanDescriptor.setValue(
076: ConstantsExt.BeanDescriptor.INSTANCE_INITIALIZATION_PERSISTENCE_MODE,
077: ConstantsExt.BeanDescriptor.INSTANCE_INITIALIZATION_PERSISTENCE_MODES.INITIALIZATION_STATEMENT);
078:
079: beanDescriptor.setValue(
080: ConstantsExt.BeanDescriptor.INITIALIZATION_STATEMENT_FACTORY,
081: new InstanceInitializationFactory());
082: */
083:
084: //beanDescriptor.setValue(Constants.BeanDescriptor.TRAY_COMPONENT, Boolean.TRUE);
085: //beanDescriptor.setValue(Constants.BeanDescriptor.CLEANUP_METHOD, "close");
086: }
087: return beanDescriptor;
088: }
089:
090: //public int getDefaultEventIndex() {}
091:
092: public int getDefaultPropertyIndex() {
093: return 0;
094: }
095:
096: public EventSetDescriptor[] getEventSetDescriptors() {
097:
098: Class rowsetClass = null;
099: try {
100: CachedRowSetXImpl.class.getMethod("absolute",
101: new Class[] { int.class });
102: rowsetClass = CachedRowSetXImpl.class;
103: } catch (NoClassDefFoundError ncdfe) {
104: rowsetClass = CachedRowSetXImpl5.class;
105: } catch (NoSuchMethodException nsme) {
106: }
107:
108: try {
109: EventSetDescriptor[] eventSetDescriptors = new EventSetDescriptor[] { new EventSetDescriptor(
110: rowsetClass, "rowSet", //NOI18N
111: RowSetListener.class, new String[] {
112: //!JK "cursorMoved", "rowChanged", "rowSetChanged, rowSetPopulated"
113: "cursorMoved", "rowChanged",
114: "rowSetChanged" }, //NOI18N
115: "addRowSetListener", //NOI18N
116: "removeRowSetListener") //NOI18N
117: };
118:
119: return eventSetDescriptors;
120: } catch (IntrospectionException e) {
121: return null;
122: }
123: }
124:
125: public Image getIcon(int iconKind) {
126: switch (iconKind) {
127: case BeanInfo.ICON_COLOR_16x16:
128: return loadImage("CachedRowSetXImplIconColor16.png"); //NOI18N
129: case BeanInfo.ICON_COLOR_32x32:
130: return loadImage("CachedRowSetXImplIconColor32.gif"); //NOI18N
131: case BeanInfo.ICON_MONO_16x16:
132: return loadImage("CachedRowSetXImplIconMono16.gif"); //NOI18N
133: case BeanInfo.ICON_MONO_32x32:
134: return loadImage("CachedRowSetXImplIconMono32.gif"); //NOI18N
135: }
136: return null;
137: }
138:
139: public synchronized MethodDescriptor[] getMethodDescriptors() {
140:
141: Class rowsetClass = null;
142: try {
143: CachedRowSetXImpl.class.getMethod("absolute",
144: new Class[] { int.class });
145: rowsetClass = CachedRowSetXImpl.class;
146: } catch (NoClassDefFoundError ncdfe) {
147: rowsetClass = CachedRowSetXImpl5.class;
148: } catch (NoSuchMethodException nsme) {
149: }
150:
151: try {
152: MethodDescriptor[] methodDescriptors = new MethodDescriptor[] {
153: new MethodDescriptor(rowsetClass.getMethod(
154: "absolute", //NOI18N
155: new Class[] { int.class })),
156: new MethodDescriptor(rowsetClass.getMethod(
157: "acceptChanges", null)), //NOI18N
158: new MethodDescriptor(rowsetClass.getMethod(
159: "acceptChanges", //NOI18N
160: new Class[] { Connection.class })),
161: new MethodDescriptor(rowsetClass.getMethod(
162: "afterLast", null)), //NOI18N
163: new MethodDescriptor(rowsetClass.getMethod(
164: "beforeFirst", null)), //NOI18N
165: new MethodDescriptor(rowsetClass.getMethod(
166: "cancelRowUpdates", null)), //NOI18N
167: new MethodDescriptor(rowsetClass.getMethod(
168: "clearParameters", null)), //NOI18N
169: new MethodDescriptor(rowsetClass.getMethod(
170: "clearWarnings", null)), //NOI18N
171: new MethodDescriptor(rowsetClass.getMethod("close",
172: null)), //NOI18N
173: new MethodDescriptor(rowsetClass.getMethod(
174: "columnUpdated", //NOI18N
175: new Class[] { int.class })),
176: new MethodDescriptor(rowsetClass.getMethod(
177: "columnUpdated", //NOI18N
178: new Class[] { String.class })),
179: new MethodDescriptor(rowsetClass.getMethod(
180: "commit", null)), //NOI18N
181: new MethodDescriptor(rowsetClass.getMethod(
182: "createCopy", null)), //NOI18N
183: new MethodDescriptor(rowsetClass.getMethod(
184: "createCopyNoConstraints", null)), //NOI18N
185: new MethodDescriptor(rowsetClass.getMethod(
186: "createCopySchema", null)), //NOI18N
187: new MethodDescriptor(rowsetClass.getMethod(
188: "createShared", null)), //NOI18N
189: new MethodDescriptor(rowsetClass.getMethod(
190: "deleteRow", null)), //NOI18N
191: new MethodDescriptor(rowsetClass.getMethod(
192: "execute", null)), //NOI18N
193: new MethodDescriptor(rowsetClass.getMethod(
194: "findColumn", //NOI18N
195: new Class[] { String.class })),
196: new MethodDescriptor(rowsetClass.getMethod("first",
197: null)), //NOI18N
198: new MethodDescriptor(rowsetClass.getMethod(
199: "getMetaData", null)), //NOI18N
200: new MethodDescriptor(rowsetClass.getMethod(
201: "getKeyColumns", null)), //NOI18N
202: new MethodDescriptor(rowsetClass.getMethod(
203: "getOriginal", null)), //NOI18N
204: new MethodDescriptor(rowsetClass.getMethod(
205: "getOriginalRow", null)), //NOI18N
206: new MethodDescriptor(rowsetClass.getMethod(
207: "getRow", null)), //NOI18N
208: new MethodDescriptor(rowsetClass.getMethod(
209: "getStatement", null)), //NOI18N
210: new MethodDescriptor(rowsetClass.getMethod(
211: "getWarnings", null)), //NOI18N
212: new MethodDescriptor(rowsetClass.getMethod(
213: "insertRow", null)), //NOI18N
214: new MethodDescriptor(rowsetClass.getMethod(
215: "isAfterLast", null)), //NOI18N
216: new MethodDescriptor(rowsetClass.getMethod(
217: "isBeforeFirst", null)), //NOI18N
218: new MethodDescriptor(rowsetClass.getMethod(
219: "isFirst", null)), //NOI18N
220: new MethodDescriptor(rowsetClass.getMethod(
221: "isLast", null)), //NOI18N
222: new MethodDescriptor(rowsetClass.getMethod("last",
223: null)), //NOI18N
224: new MethodDescriptor(rowsetClass.getMethod(
225: "moveToCurrentRow", null)), //NOI18N
226: new MethodDescriptor(rowsetClass.getMethod(
227: "moveToInsertRow", null)), //NOI18N
228: new MethodDescriptor(rowsetClass.getMethod("next",
229: null)), //NOI18N
230: new MethodDescriptor(rowsetClass.getMethod(
231: "nextPage", null)), //NOI18N
232: new MethodDescriptor(rowsetClass.getMethod(
233: "populate", //NOI18N
234: new Class[] { ResultSet.class })),
235: new MethodDescriptor(rowsetClass.getMethod(
236: "previous", null)), //NOI18N
237: new MethodDescriptor(rowsetClass.getMethod(
238: "previousPage", null)), //NOI18N
239: new MethodDescriptor(rowsetClass.getMethod(
240: "refreshRow", null)), //NOI18N
241: new MethodDescriptor(rowsetClass.getMethod(
242: "relative", //NOI18N
243: new Class[] { int.class })),
244:
245: new MethodDescriptor(rowsetClass.getMethod(
246: "release", null)), //NOI18N
247: new MethodDescriptor(rowsetClass.getMethod(
248: "restoreOriginal", null)), //NOI18N
249: new MethodDescriptor(rowsetClass.getMethod(
250: "rollback", null)), //NOI18N
251: new MethodDescriptor(rowsetClass.getMethod(
252: "rollback", //NOI18N
253: new Class[] { Savepoint.class })),
254: new MethodDescriptor(rowsetClass.getMethod(
255: "rowDeleted", null)), //NOI18N
256: new MethodDescriptor(rowsetClass.getMethod(
257: "rowInserted", null)), //NOI18N
258: new MethodDescriptor(rowsetClass.getMethod(
259: "rowUpdated", null)), //NOI18N
260: new MethodDescriptor(rowsetClass.getMethod(
261: "setKeyColumns", //NOI18N
262: new Class[] { int[].class })),
263: new MethodDescriptor(rowsetClass.getMethod(
264: "setOriginalRow", null)), //NOI18N
265: new MethodDescriptor(rowsetClass.getMethod(
266: "toCollection", null)),//NOI18N
267: new MethodDescriptor(rowsetClass.getMethod(
268: "toCollection", //NOI18N
269: new Class[] { int.class })),
270: new MethodDescriptor(rowsetClass.getMethod(
271: "toCollection", //NOI18N
272: new Class[] { String.class })),
273: new MethodDescriptor(rowsetClass.getMethod(
274: "undoDelete", null)), //NOI18N
275: new MethodDescriptor(rowsetClass.getMethod(
276: "undoInsert", null)), //NOI18N
277: new MethodDescriptor(rowsetClass.getMethod(
278: "undoUpdate", null)), //NOI18N
279: new MethodDescriptor(rowsetClass.getMethod(
280: "wasNull", null)) //NOI18N
281:
282: };
283:
284: return methodDescriptors;
285: } catch (NoSuchMethodException e) {
286: Exceptions.printStackTrace(e);
287: return null;
288: }
289: }
290:
291: public synchronized PropertyDescriptor[] getPropertyDescriptors() {
292:
293: Class rowsetClass = null;
294: try {
295: CachedRowSetXImpl.class.getMethod("absolute",
296: new Class[] { int.class });
297: rowsetClass = CachedRowSetXImpl.class;
298: } catch (NoClassDefFoundError ncdfe) {
299: rowsetClass = CachedRowSetXImpl5.class;
300: } catch (NoSuchMethodException nsme) {
301: }
302:
303: try {
304: PropertyDescriptor[] propertyDescriptors;
305: // command
306: PropertyDescriptor command = new PropertyDescriptor(
307: "command", rowsetClass); //NOI18N
308: command.setBound(true);
309: // concurrency
310: PropertyDescriptor concurrency = new PropertyDescriptor(
311: "concurrency", rowsetClass); //NOI18N
312: concurrency.setBound(true);
313: concurrency
314: .setPropertyEditorClass(ConcurrencyPropertyEditor.class);
315: //dataSourceName
316: PropertyDescriptor dataSourceName = new PropertyDescriptor(
317: "dataSourceName", rowsetClass); //NOI18N
318: dataSourceName.setBound(true);
319: // EAT: The original prop editor
320: dataSourceName
321: .setPropertyEditorClass(DataSourceNamePropertyEditor.class);
322: // EAT: new one, once it works :(
323: // dataSourceName.setPropertyEditorClass(
324: // com.sun.jsfcl.std.property.SingleChoiceReferenceDataPropertyEditor.class);
325: // dataSourceName.setValue(
326: // Constants.PropertyDescriptor.REFERENCE_DATA_NAME,
327: // com.sun.jsfcl.std.reference.DataSourceNameReferenceData.NAME);
328: // maxRows
329: PropertyDescriptor maxRows = new PropertyDescriptor(
330: "maxRows", rowsetClass); //NOI18N
331: maxRows.setBound(true);
332: // pageSize
333: PropertyDescriptor pageSize = new PropertyDescriptor(
334: "pageSize", rowsetClass); //NOI18N
335: // password
336: PropertyDescriptor password = new PropertyDescriptor(
337: "password", rowsetClass); //NOI18N
338: password.setBound(true);
339: // showDeleted
340: PropertyDescriptor showDeleted = new PropertyDescriptor(
341: "showDeleted", rowsetClass); //NOI18N
342: // transactionIsolation
343: PropertyDescriptor transactionIsolation = new PropertyDescriptor(
344: "transactionIsolation", rowsetClass); //NOI18N
345: transactionIsolation.setBound(true);
346: transactionIsolation
347: .setPropertyEditorClass(TransactionIsolationPropertyEditor.class);
348: // tableName
349: PropertyDescriptor tableName = new PropertyDescriptor(
350: "tableName", rowsetClass); //NOI18N
351: // type
352: PropertyDescriptor type = new PropertyDescriptor("type",
353: rowsetClass); //NOI18N
354: type.setBound(true);
355: type.setPropertyEditorClass(TypePropertyEditor.class);
356: // url
357: PropertyDescriptor url = new PropertyDescriptor("url",
358: rowsetClass); //NOI18N
359: url.setBound(true);
360: // username
361: PropertyDescriptor username = new PropertyDescriptor(
362: "username", rowsetClass); //NOI18N
363: username.setBound(true);
364: // catalogName
365: PropertyDescriptor catalogName = new PropertyDescriptor(
366: "catalogName", rowsetClass); //NOI18N
367: catalogName.setValue(Constants.PropertyDescriptor.CATEGORY,
368: CategoryDescriptors.ADVANCED);
369: // columnCatalogNames
370: PropertyDescriptor columnCatalogNames = new PropertyDescriptor(
371: "columnCatalogNames", rowsetClass); // NOI18N
372: columnCatalogNames.setValue(
373: Constants.PropertyDescriptor.CATEGORY,
374: CategoryDescriptors.ADVANCED);
375: columnCatalogNames.setValue(
376: Constants.PropertyDescriptor.CATEGORY,
377: CategoryDescriptors.ADVANCED);
378: // columnSchemaNames
379: PropertyDescriptor columnSchemaNames = new PropertyDescriptor(
380: "columnSchemaNames", rowsetClass); //NOI18N
381: columnSchemaNames.setValue(
382: Constants.PropertyDescriptor.CATEGORY,
383: CategoryDescriptors.ADVANCED);
384: // columnTableNames
385: PropertyDescriptor columnTableNames = new PropertyDescriptor(
386: "columnTableNames", rowsetClass); //NOI18N
387: columnTableNames.setValue(
388: Constants.PropertyDescriptor.CATEGORY,
389: CategoryDescriptors.ADVANCED);
390: // columnNames
391: PropertyDescriptor columnNames = new PropertyDescriptor(
392: "columnNames", rowsetClass); //NOI18N
393: columnNames.setValue(Constants.PropertyDescriptor.CATEGORY,
394: CategoryDescriptors.ADVANCED);
395: // insertableColumns
396: PropertyDescriptor insertableColumns = new PropertyDescriptor(
397: "insertableColumns", rowsetClass); //NOI18N
398: insertableColumns.setValue(
399: Constants.PropertyDescriptor.CATEGORY,
400: CategoryDescriptors.ADVANCED);
401: // updatableColumns
402: PropertyDescriptor updatableColumns = new PropertyDescriptor(
403: "updatableColumns", rowsetClass); //NOI18N
404: updatableColumns.setValue(
405: Constants.PropertyDescriptor.CATEGORY,
406: CategoryDescriptors.ADVANCED);
407: // printStatements
408: PropertyDescriptor printStatements = new PropertyDescriptor(
409: "printStatements", rowsetClass); //NOI18N
410: printStatements.setValue(
411: Constants.PropertyDescriptor.CATEGORY,
412: CategoryDescriptors.ADVANCED);
413: // schemaName
414: PropertyDescriptor schemaName = new PropertyDescriptor(
415: "schemaName", rowsetClass); //NOI18N
416: schemaName.setValue(Constants.PropertyDescriptor.CATEGORY,
417: CategoryDescriptors.ADVANCED);
418:
419: // size
420: PropertyDescriptor size = new PropertyDescriptor("size",
421: rowsetClass, "size", null); //NOI18N
422:
423: propertyDescriptors = new PropertyDescriptor[] {
424: command,
425: concurrency,
426: dataSourceName,
427: new PropertyDescriptor("fetchSize", rowsetClass), //NOI18N
428: maxRows, pageSize, password, showDeleted,
429: transactionIsolation, type, tableName, url,
430: username, columnCatalogNames, columnSchemaNames,
431: columnTableNames, columnNames, insertableColumns,
432: updatableColumns, printStatements, schemaName, size };
433:
434: return propertyDescriptors;
435: } catch (IntrospectionException e) {
436: throw new RuntimeException(e);
437: }
438: }
439: }
|