1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
32
package com.sun.grid.jgdi.configuration.reflect;
34
import java.lang.reflect.*;
39
public abstract class PropertyDescriptor {
41
private Class beanClass;
42
private String propertyName;
44
private int cullFieldName;
45
private String cullType;
47
private boolean readOnly;
49
private boolean browsable;
50
private boolean configurable;
51
private Method isSetMethod;
53
/** Some cull type are mapped to a primitive java class
54
* e.g HR_Type -> String
55
* For all these type the <code>hasCullWrapper</code> flag
56
* is set to <code>true</code>.
58
private boolean hasCullWrapper;
61
* If a cull type is mapped to a primitive java class the
62
* <code>cullContentField</code> specifies the cull attribute
63
* which contains the content.
65
private int cullContentField;
69
/** Creates a new instance of PropertyDescriptor */
70
protected PropertyDescriptor(Class beanClass, String propertyName,
71
Class propertyType, String cullType,
72
int cullFieldName, boolean readOnly,
73
boolean configurable) {
74
this.beanClass = beanClass;
75
this.propertyName = propertyName;
76
this.propertyType = propertyType;
77
this.cullType = cullType;
78
this.cullFieldName = cullFieldName;
79
this.readOnly = readOnly;
80
this.configurable = configurable;
81
this.hashCode = beanClass.hashCode() * 31 + propertyName.hashCode();
84
this.isSetMethod = findMethod("isSet", null);
85
} catch (IllegalArgumentException e) {
86
// ignore error if isSet* is not present for bean class -> webqmon
90
public boolean equals(Object obj) {
91
return obj instanceof PropertyDescriptor &&
92
beanClass.equals(((PropertyDescriptor)obj).beanClass) &&
93
propertyName.equals(((PropertyDescriptor)obj).propertyName);
97
public int hashCode() {
101
protected Method findMethod(String prefix, String suffix, Class [] argTypes) {
103
StringBuilder buf = new StringBuilder();
104
if (prefix != null) {
107
buf.append(Character.toUpperCase(propertyName.charAt(0)));
108
buf.append(propertyName.substring(1));
109
if (suffix != null) {
112
String methodName = buf.toString();
115
return beanClass.getMethod(methodName, argTypes);
116
} catch (NoSuchMethodException nse) {
117
StringBuilder buffer = new StringBuilder();
118
if (argTypes != null) {
119
for (int i=0; i<argTypes.length; i++) {
123
buffer.append(argTypes[i].getName());
128
IllegalArgumentException ilse = new IllegalArgumentException(
129
"Method " + methodName + "(" + buffer + ")"
130
+ " not found in class " + beanClass );
136
protected Method findMethod(String prefix, Class [] argTypes) {
137
return findMethod(prefix, null, argTypes);
140
protected Object invoke(Method method, Object bean, Object[] args) {
142
return method.invoke(bean, args);
143
} catch (IllegalAccessException iae) {
144
IllegalStateException ilse = new IllegalStateException( method.getName() + " of "
145
+ getBeanClass().getName() + "." + getPropertyName()
146
+ " is not accessible");
147
ilse.initCause( iae );
149
} catch( InvocationTargetException ite ) {
150
IllegalStateException ilse = new IllegalStateException(
151
"error in method " + method.getName() + " of "
152
+ getBeanClass().getName() + "." + getPropertyName() );
153
ilse.initCause( ite );
160
* Getter for property propertyType.
161
* @return Value of property propertyType.
163
public java.lang.Class getPropertyType() {
167
public String getCullType() {
171
public String getJNIPropertyType() {
173
String name = propertyType.getName();
174
if( !propertyType.isPrimitive() ) {
175
name = "L" + name.replace('.','/') + ";";
181
* Getter for property propertyName.
182
* @return Value of property propertyName.
184
public java.lang.String getPropertyName() {
188
public int getCullFieldName() {
189
return this.cullFieldName;
192
* Getter for property beanClass.
193
* @return Value of property beanClass.
195
public java.lang.Class getBeanClass() {
199
public abstract void clone( Object srcBean, Object targetBean );
201
public boolean isReadOnly() {
205
public void setReadOnly(boolean readOnly) {
206
this.readOnly = readOnly;
209
public boolean isConfigurable() {
213
public void setConfigurable(boolean configurable) {
214
this.configurable = configurable;
219
* Getter for property browsable.
220
* @return Value of property browsable.
222
public boolean isBrowsable() {
227
* Setter for property browsable.
228
* @param browsable New value of property browsable.
230
public void setBrowsable(boolean browsable) {
231
this.browsable = browsable;
234
public boolean hasCullWrapper() {
235
return hasCullWrapper;
238
public void setHasCullWrapper(boolean hasCullWrapper) {
239
this.hasCullWrapper = hasCullWrapper;
242
public int getCullContentField() {
243
return cullContentField;
246
public void setCullContentField(int cullContentField) {
247
this.cullContentField = cullContentField;
250
public boolean isSet(Object bean) {
251
return ((Boolean)invoke(isSetMethod, bean , null)).booleanValue();