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;
35
import com.sun.grid.jgdi.configuration.GEObject;
36
import com.sun.grid.jgdi.configuration.Util;
40
* Abstract Base class for <code>ClassDescriptor</code> subclasses
43
public abstract class AbstractClassDescriptor implements ClassDescriptor {
45
private ArrayList<PropertyDescriptor> propertyList = new ArrayList<PropertyDescriptor>();
46
private Map<String, PropertyDescriptor> propertyMap = new HashMap<String, PropertyDescriptor>();
47
private Class beanClass;
48
private Class implClass;
49
private String cullName;
51
protected AbstractClassDescriptor(Class beanClass, String cullName) {
52
this.beanClass = beanClass;
53
this.cullName = cullName;
56
public List getProperties() {
57
return Collections.unmodifiableList(propertyList);
60
protected void add(PropertyDescriptor property) {
61
propertyList.add(property);
62
propertyMap.put(property.getPropertyName(), property);
65
protected SimplePropertyDescriptor addSimple(String name, Class type, String cullType, int cullFieldName, boolean required, boolean readOnly, boolean configurable) {
66
SimplePropertyDescriptor prop = new SimplePropertyDescriptor(beanClass, name, type, cullType, cullFieldName, required, readOnly, configurable);
71
protected ListPropertyDescriptor addList(String name, Class type, String cullType, int cullFieldName, boolean browsable, boolean readOnly, boolean configurable) {
72
ListPropertyDescriptor prop = new DefaultListPropertyDescriptor(beanClass, name, type, cullType, cullFieldName, browsable, readOnly, configurable);
77
protected MapPropertyDescriptor addMap(String name, Class type, String cullType, Class keyType, int cullFieldName, int keyCullFieldName, int valueCullFieldName, Object defaultKey, boolean readOnly, boolean configurable) {
78
MapPropertyDescriptor prop = new DefaultMapPropertyDescriptor(beanClass, name, type, cullType, keyType, cullFieldName, keyCullFieldName, valueCullFieldName, defaultKey, readOnly, configurable);
83
protected MapListPropertyDescriptor addMapList(String name, Class type, String cullType, Class keyType, String cullListType, int cullFieldName, int keyCullFieldName, int valueCullFieldName, Object defaultKey, boolean readOnly, boolean configurable) {
84
MapListPropertyDescriptor prop = new DefaultMapListPropertyDescriptor(beanClass, name, type, cullType, keyType, cullListType, cullFieldName, keyCullFieldName, valueCullFieldName, defaultKey, readOnly, configurable);
89
public PropertyDescriptor getProperty(String name) {
90
return propertyMap.get(name);
93
public String[] getPropertyNames() {
94
String[] ret = new String[propertyMap.size()];
95
propertyMap.keySet().toArray(ret);
99
public int getPropertyCount() {
100
return propertyList.size();
103
public PropertyDescriptor getProperty(int index) {
104
return propertyList.get(index);
107
public PropertyDescriptor getPropertyByCullFieldName(int cullFieldName) {
108
for(PropertyDescriptor pd: propertyList) {
109
if (pd.getCullFieldName() == cullFieldName) {
116
public Class getBeanClass() {
120
public Object newInstance() {
122
if (implClass != null) {
123
return implClass.newInstance();
125
return beanClass.newInstance();
127
} catch (IllegalAccessException ile) {
128
IllegalStateException ilse = new IllegalStateException("Constructor" + beanClass.getName() + " is not accessible");
131
} catch (InstantiationException iae) {
132
IllegalStateException ilse = new IllegalStateException("Can\'t create instanceof of " + beanClass.getName());
138
public Object clone(Object bean) {
140
ClassDescriptor classDescr = Util.getDescriptor(bean.getClass());
141
Object ret = classDescr.newInstance();
142
PropertyDescriptor propDescr = null;
144
for (int i = 0; i < classDescr.getPropertyCount(); i++) {
145
propDescr = classDescr.getProperty(i);
146
if (propDescr.getPropertyName().equals("parent")) {
147
SimplePropertyDescriptor parentPropDescr = (SimplePropertyDescriptor) propDescr;
148
parentPropDescr.setValue(ret, parentPropDescr.getValue(bean));
150
propDescr.clone(bean, ret);
157
public void registryObjects(Object root) {
159
ClassDescriptor cd = Util.getDescriptor(root.getClass());
160
int count = cd.getPropertyCount();
161
PropertyDescriptor pd = null;
163
for (int i = 0; i < count; i++) {
164
pd = cd.getProperty(i);
165
if (!pd.getPropertyName().equals("parent") && GEObject.class.isAssignableFrom(pd.getPropertyType())) {
166
GEObject value = null;
167
if (pd instanceof SimplePropertyDescriptor) {
168
value = (GEObject) ((SimplePropertyDescriptor)pd).getValue(root);
169
} else if (pd instanceof ListPropertyDescriptor) {
170
ListPropertyDescriptor lpd = (ListPropertyDescriptor) pd;
171
int valueCount = lpd.getCount(root);
172
for (int ii = 0; ii < valueCount; ii++) {
173
value = (GEObject) lpd.get(root, ii);
180
public String getCullName() {
184
public String toString(Object bean) {
185
return bean.toString();
188
public Class getImplClass() {
192
public void setImplClass(Class implClass) {
193
this.implClass = implClass;