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.dataprovider.designtime;
043:
044: import com.sun.data.provider.DataListener;
045: import com.sun.data.provider.DataProvider;
046: import com.sun.data.provider.FieldKey;
047: import com.sun.data.provider.RefreshableDataListener;
048: import com.sun.data.provider.RefreshableDataProvider;
049: import com.sun.data.provider.RowKey;
050: import com.sun.data.provider.TableCursorListener;
051: import com.sun.data.provider.TableDataListener;
052: import com.sun.data.provider.TableDataProvider;
053: import com.sun.data.provider.TransactionalDataListener;
054: import com.sun.data.provider.TransactionalDataProvider;
055: import java.beans.EventSetDescriptor;
056: import java.beans.IntrospectionException;
057: import java.lang.reflect.Method;
058: import java.util.ArrayList;
059: import java.util.List;
060:
061: /**
062: * <p>Static utility methods for <code>BeanInfo</code> implementations.</p>
063: */
064: public class BeanInfoSupport {
065:
066: // ---------------------------------------------------------- Static Methods
067:
068: /**
069: * <p>Return a <code>List</code> of <code>EventSetDescriptor</code>s
070: * for the events fired by a <code>DataProvider</code>.</p>
071: *
072: * @param source Source class firing the events
073: *
074: * @exception IntrospectionException if an exception occurs
075: * during introspection
076: */
077: public static List getDataProviderEventSetDescriptors(Class source) {
078:
079: List results = new ArrayList();
080: try {
081:
082: results
083: .add(new EventSetDescriptor(
084: "dataListener",
085: DataListener.class,
086: new Method[] {
087: DataListener.class
088: .getMethod(
089: "providerChanged",
090: new Class[] { DataProvider.class }),
091: DataListener.class.getMethod(
092: "valueChanged",
093: new Class[] {
094: DataProvider.class,
095: FieldKey.class,
096: Object.class,
097: Object.class }), },
098: source.getMethod("addDataListener",
099: new Class[] { DataListener.class }),
100: source.getMethod("removeDataListener",
101: new Class[] { DataListener.class }),
102: source.getMethod("getDataListeners",
103: new Class[0])));
104:
105: } catch (IntrospectionException e) {
106: e.printStackTrace();
107: } catch (NoSuchMethodException e) {
108: e.printStackTrace();
109: }
110: return results;
111:
112: }
113:
114: /**
115: * <p>Return a <code>List</code> of <code>EventSetDescriptor</code>s
116: * for events fired by a <code>RefreshableDataProvider</code>. This
117: * list includes <strong>ONLY</strong> events described by this interface,
118: * not by any superinterfaces.</p>
119: *
120: * @param source Source class firing the events
121: *
122: * @exception IntrospectionException if an exception occurs
123: * during introspection
124: */
125: public static List getRefreshableDataProviderEventSetDescriptors(
126: Class source) {
127:
128: List results = new ArrayList();
129: try {
130:
131: results
132: .add(new EventSetDescriptor(
133: "refreshableDataListener",
134: RefreshableDataListener.class,
135: new Method[] { RefreshableDataListener.class
136: .getMethod(
137: "refreshed",
138: new Class[] { RefreshableDataProvider.class }), },
139: source
140: .getMethod(
141: "addRefreshableDataListener",
142: new Class[] { RefreshableDataListener.class }),
143: source
144: .getMethod(
145: "removeRefreshableDataListener",
146: new Class[] { RefreshableDataListener.class }),
147: source.getMethod(
148: "getRefreshableDataListeners",
149: new Class[0])));
150:
151: } catch (IntrospectionException e) {
152: e.printStackTrace();
153: } catch (NoSuchMethodException e) {
154: e.printStackTrace();
155: }
156: return results;
157:
158: }
159:
160: /**
161: * <p>Return a <code>List</code> of <code>EventSetDescriptor</code>s
162: * for events fired by a <code>TableDataProvider</code>. This
163: * list includes <strong>ONLY</strong> events described by this interface,
164: * not by any superinterfaces.</p>
165: *
166: * @param source Source class firing the events
167: *
168: * @exception IntrospectionException if an exception occurs
169: * during introspection
170: */
171: public static List getTableDataProviderEventSetDescriptors(
172: Class source) {
173:
174: List results = new ArrayList();
175: try {
176:
177: results
178: .add(new EventSetDescriptor(
179: "tableCursorListener",
180: TableCursorListener.class,
181: new Method[] {
182: TableCursorListener.class
183: .getMethod(
184: "cursorChanged",
185: new Class[] {
186: TableDataProvider.class,
187: RowKey.class,
188: RowKey.class }),
189: TableCursorListener.class
190: .getMethod(
191: "cursorChanging",
192: new Class[] {
193: TableDataProvider.class,
194: RowKey.class,
195: RowKey.class }), },
196: source
197: .getMethod(
198: "addTableCursorListener",
199: new Class[] { TableCursorListener.class }),
200: source
201: .getMethod(
202: "removeTableCursorListener",
203: new Class[] { TableCursorListener.class }),
204: source.getMethod("getTableCursorListeners",
205: new Class[0])));
206:
207: results.add(new EventSetDescriptor("tableDataListener",
208: TableDataListener.class, new Method[] {
209: TableDataListener.class.getMethod(
210: "rowAdded", new Class[] {
211: TableDataProvider.class,
212: RowKey.class }),
213: TableDataListener.class.getMethod(
214: "rowRemoved", new Class[] {
215: TableDataProvider.class,
216: RowKey.class }),
217: TableDataListener.class.getMethod(
218: "valueChanged", new Class[] {
219: TableDataProvider.class,
220: FieldKey.class,
221: RowKey.class, Object.class,
222: Object.class }), },
223: source.getMethod("addTableDataListener",
224: new Class[] { TableDataListener.class }),
225: source.getMethod("removeTableDataListener",
226: new Class[] { TableDataListener.class }),
227: source.getMethod("getTableDataListeners",
228: new Class[0])));
229:
230: } catch (IntrospectionException e) {
231: e.printStackTrace();
232: } catch (NoSuchMethodException e) {
233: e.printStackTrace();
234: }
235: return results;
236:
237: }
238:
239: /**
240: * <p>Return a <code>List</code> of <code>EventSetDescriptor</code>s
241: * for events fired by a <code>TransactionalDataProvider</code>. This
242: * list includes <strong>ONLY</strong> events described by this interface,
243: * not by any superinterfaces.</p>
244: *
245: * @param source Source class firing the events
246: *
247: * @exception IntrospectionException if an exception occurs
248: * during introspection
249: */
250: public static List getTransactionalDataProviderEventSetDescriptors(
251: Class source) {
252:
253: List results = new ArrayList();
254: try {
255:
256: results
257: .add(new EventSetDescriptor(
258: "transactionalDataListener",
259: TransactionalDataListener.class,
260: new Method[] {
261: TransactionalDataListener.class
262: .getMethod(
263: "changesCommitted",
264: new Class[] { TransactionalDataProvider.class }),
265: TransactionalDataListener.class
266: .getMethod(
267: "changesReverted",
268: new Class[] { TransactionalDataProvider.class }), },
269: source
270: .getMethod(
271: "addTransactionalDataListener",
272: new Class[] { TransactionalDataListener.class }),
273: source
274: .getMethod(
275: "removeTransactionalDataListener",
276: new Class[] { TransactionalDataListener.class }),
277: source.getMethod(
278: "getTransactionalDataListeners",
279: new Class[0])));
280:
281: } catch (IntrospectionException e) {
282: e.printStackTrace();
283: } catch (NoSuchMethodException e) {
284: e.printStackTrace();
285: }
286: return results;
287:
288: }
289:
290: }
|