001: /*
002: * Copyright (c) 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.binding.tests.beans;
032:
033: import java.util.ArrayList;
034: import java.util.Arrays;
035: import java.util.Collections;
036: import java.util.List;
037:
038: /**
039: * Consists of a bunch of Java Bean classes and Bean-like classes
040: * that are used by the PropertyAdapter unit tests.
041: *
042: * @author Karsten Lentzsch
043: * @version $Revision: 1.11 $
044: */
045: public final class BeanClasses {
046:
047: private static final Class<?>[] OBSERVABLE_CLASSES = {
048: ObservableBean.class,
049: ObservableBeanWithNamedPCLSupport.class };
050:
051: private static final Class<?>[] UNOBSERVABLE_CLASSES = {
052: UnobservableBean.class, BeanWithPCLAdder.class,
053: BeanWithPCLRemover.class,
054: UnobservableBeanWithNamedPCLSupport.class };
055:
056: private BeanClasses() {
057: // Override default constructor; prevents instantiation.
058: }
059:
060: // Accessing Bean Classes ************************************************
061:
062: /**
063: * Returns a list of bean classes that are observable,
064: * i.e. that provide support for bound properties.
065: *
066: * @return an unmodifiable list of observable bean classes
067: */
068: public static List<Class<?>> getObservableClasses() {
069: return Collections.unmodifiableList(Arrays
070: .asList(OBSERVABLE_CLASSES));
071: }
072:
073: /**
074: * Returns a list of bean classes that are not observable,
075: * i.e. that do not provide support for bound properties.
076: *
077: * @return an unmodifiable list of unobservable bean classes
078: */
079: public static List<Class<?>> getUnobservableClasses() {
080: return Collections.unmodifiableList(Arrays
081: .asList(UNOBSERVABLE_CLASSES));
082: }
083:
084: // Accessing Bean Instance ***********************************************
085:
086: /**
087: * Returns a bean that provides support for bound properties.
088: *
089: * @return an observable bean
090: */
091: public static Object getObservable() {
092: return new ObservableBean();
093: }
094:
095: /**
096: * Returns an array of bean instances that provide support
097: * for bound properties.
098: *
099: * @return an array of observable beans instances
100: */
101: public static List<Object> getObservableBeans() {
102: List<Object> beans = new ArrayList<Object>();
103: for (Class<?> beanClass : OBSERVABLE_CLASSES) {
104: try {
105: beans.add(beanClass.newInstance());
106: } catch (Exception e) {
107: // Should not happen in this context
108: }
109: }
110: return beans;
111: }
112:
113: /**
114: * Returns a bean that provides no support for bound properties.
115: *
116: * @return an unobservable bean
117: */
118: public static Object getUnobservable() {
119: return new UnobservableBean();
120: }
121:
122: /**
123: * Returns an array of bean instances that provide no support
124: * for bound properties.
125: *
126: * @return an array of unobservable beans instances
127: */
128: public static List<Object> getUnobservableBeans() {
129: List<Object> beans = new ArrayList<Object>();
130: for (Class<?> beanClass : UNOBSERVABLE_CLASSES) {
131: try {
132: beans.add(beanClass.newInstance());
133: } catch (Exception e) {
134: // Should not happen in this context
135: }
136: }
137: return beans;
138: }
139:
140: /**
141: * Returns an array of bean instances where some provide
142: * support for bound properties, and others do not.
143: *
144: * @return an array of beans instances
145: */
146: public static List<Object> getBeans() {
147: List<Object> beans = new ArrayList<Object>();
148: for (Class<?> beanClass : OBSERVABLE_CLASSES) {
149: try {
150: beans.add(beanClass.newInstance());
151: } catch (Exception e) {
152: // Should not happen in this context
153: }
154: }
155: for (Class<?> beanClass : UNOBSERVABLE_CLASSES) {
156: try {
157: beans.add(beanClass.newInstance());
158: } catch (Exception e) {
159: // Should not happen in this context
160: }
161: }
162: return beans;
163: }
164:
165: }
|