01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.beans.tests.support.mock;
19:
20: import java.beans.BeanDescriptor;
21: import java.beans.IntrospectionException;
22: import java.beans.MethodDescriptor;
23: import java.beans.PropertyDescriptor;
24: import java.beans.SimpleBeanInfo;
25: import java.lang.reflect.Method;
26:
27: /**
28: * The series of FakeFox classes are used to test
29: * Introspector.getBeanInfo(Class, int)
30: */
31: public class FakeFox01BeanInfo extends SimpleBeanInfo {
32:
33: Class<FakeFox01> clazz = FakeFox01.class;
34:
35: String suffix = "." + clazz.getName();
36:
37: @Override
38: public BeanDescriptor getBeanDescriptor() {
39: BeanDescriptor beanDesc = new BeanDescriptor(clazz);
40: beanDesc.setDisplayName(beanDesc.getDisplayName() + suffix);
41: return beanDesc;
42: }
43:
44: @Override
45: public MethodDescriptor[] getMethodDescriptors() {
46: Method get = null;
47: Method set = null;
48: try {
49: get = clazz.getMethod("getFox01", (Class[]) null);
50: set = clazz.getMethod("setFox01",
51: new Class[] { String.class });
52: } catch (SecurityException e) {
53: e.printStackTrace();
54: } catch (NoSuchMethodException e) {
55: e.printStackTrace();
56: }
57:
58: MethodDescriptor getDesc = new MethodDescriptor(get);
59: getDesc.setDisplayName(getDesc.getDisplayName() + suffix);
60: MethodDescriptor setDesc = new MethodDescriptor(set);
61: setDesc.setDisplayName(setDesc.getDisplayName() + suffix);
62: return new MethodDescriptor[] { setDesc, getDesc };
63: }
64:
65: @Override
66: public PropertyDescriptor[] getPropertyDescriptors() {
67: PropertyDescriptor propertyDesc = null;
68: try {
69: propertyDesc = new PropertyDescriptor("fox01", clazz);
70: propertyDesc.setDisplayName(propertyDesc.getDisplayName()
71: + suffix);
72: } catch (IntrospectionException e) {
73: e.printStackTrace();
74: }
75: return new PropertyDescriptor[] { propertyDesc };
76: }
77:
78: /*
79: * (non-Javadoc)
80: *
81: * @see java.beans.BeanInfo#getDefaultEventIndex()
82: */
83: @Override
84: public int getDefaultEventIndex() {
85: return -1;
86: }
87:
88: /*
89: * (non-Javadoc)
90: *
91: * @see java.beans.BeanInfo#getDefaultPropertyIndex()
92: */
93: @Override
94: public int getDefaultPropertyIndex() {
95: // TODO Auto-generated method stub
96: return 0;
97: }
98: }
|