001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Maxim V. Berkultsev
020: * @version $Revision: 1.3.6.3 $
021: */package org.apache.harmony.beans.tests.support;
022:
023: import java.util.Iterator;
024: import java.util.TooManyListenersException;
025: import java.util.Vector;
026:
027: /**
028: * @author Maxim V. Berkultsev
029: * @version $Revision: 1.3.6.3 $
030: */
031:
032: public class SampleBean {
033:
034: private String text = null;
035:
036: private String otherText = null;
037:
038: private SampleBean bean = null;
039:
040: private int x = 0;
041:
042: private double[] smth;
043:
044: private Object[] smthObjs;
045:
046: private Vector<SampleListener> listeners;
047:
048: public SampleBean() {
049: this .text = null;
050: }
051:
052: public SampleBean(String text) {
053: this .text = text;
054: this .otherText = "Constructor with args";
055: }
056:
057: protected SampleBean(String text, SampleBean bean) {
058: this .text = text;
059: this .bean = bean;
060: }
061:
062: public String getText() {
063: return text;
064: }
065:
066: public void setText(String text) {
067: this .text = text;
068: }
069:
070: public SampleBean getObject() {
071: return bean;
072: }
073:
074: public void setObject(SampleBean bean) {
075: this .bean = bean;
076: }
077:
078: public String getOtherText() {
079: return otherText;
080: }
081:
082: public void setOtherText(String value) {
083: this .otherText = value;
084: }
085:
086: public int getX() {
087: return x;
088: }
089:
090: public void setX(int value) {
091: this .x = value;
092: }
093:
094: public double getSmthByIdx(int i) {
095: return smth[i];
096: }
097:
098: public void setSmthByIdx(int i, double value) {
099: smth[i] = value;
100: }
101:
102: public double[] getSmth() {
103: return this .smth;
104: }
105:
106: public void setSmth(double[] value) {
107: this .smth = value;
108: }
109:
110: public Object getObjectByIdx(int i) {
111: return smthObjs[i];
112: }
113:
114: public void setObjectByIdx(int i, Object value) {
115: this .smthObjs[i] = value;
116: }
117:
118: public Object[] getObjects() {
119: return smthObjs;
120: }
121:
122: public void setObjects(Object[] value) {
123: this .smthObjs = value;
124: }
125:
126: @Override
127: public boolean equals(Object other) {
128: if (other instanceof SampleBean) {
129: SampleBean sb = (SampleBean) other;
130: if ((sb.bean == null) && (bean == null)) {
131: return true;
132: } else if ((sb.bean != null) && (bean != null)) {
133: return true;
134: } else {
135: return false;
136: }
137: }
138: return false;
139: }
140:
141: public static SampleBean create(String text, SampleBean bean) {
142: return new SampleBean(text, bean);
143: }
144:
145: public void addSampleListener(SampleListener listener)
146: throws TooManyListenersException {
147: if (listeners == null) {
148: listeners = new Vector<SampleListener>();
149: }
150:
151: if (listeners.size() >= 100) {
152: throw new TooManyListenersException(
153: "Number of listeners could not exceed 100");
154: }
155: listeners.add(listener);
156: }
157:
158: public void removeSampleListener(SampleListener listener) {
159: if (listeners != null) {
160: listeners.remove(listener);
161: }
162: }
163:
164: public SampleListener[] getSampleListeners() {
165: if (listeners != null) {
166: SampleListener[] result = new SampleListener[listeners
167: .size()];
168:
169: Iterator<SampleListener> i = listeners.iterator();
170:
171: int idx = 0;
172: while (i.hasNext()) {
173: result[idx++] = i.next();
174: }
175:
176: return result;
177: }
178: return new SampleListener[] {};
179: }
180: }
|