com.squeakysand.commons.beans.RemoteBeanInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of squeakysand-commons Show documentation
Show all versions of squeakysand-commons Show documentation
Classes, interfaces and enums that assist with everyday Java development tasks.
The newest version!
/*
* Copyright 2010-2012 Craig S. Dickson (http://craigsdickson.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squeakysand.commons.beans;
import java.beans.BeanInfo;
import java.beans.PropertyDescriptor;
import java.io.Serializable;
/**
* Class that represents the Java Bean related information about a remote bean. This class mimics
* the {@link java.beans.BeanInfo} interface, but is Serializable. This class is especially useful
* when the BeanInfo of a class that only exists on the server is needed for the client.
*
* @author Craig S. Dickson
*/
public class RemoteBeanInfo implements Serializable {
private static final long serialVersionUID = -5793530602259777646L;
/** The bean descriptor. */
private RemoteBeanDescriptor beanDescriptor;
/** The properties of the bean. */
private RemotePropertyDescriptor[] properties;
/**
* Constructor for RemoteBeanInfo.
*
* @param bi The {@link java.beans.BeanInfo} class that this object should be based on.
*/
public RemoteBeanInfo(BeanInfo bi) {
super();
beanDescriptor = new RemoteBeanDescriptor(bi.getBeanDescriptor());
generateRemotePropertyDescriptors(bi.getPropertyDescriptors());
}
/**
* toString.
*
* @see java.lang.Object#toString()
* @return a {@link java.lang.String} object.
*/
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(beanDescriptor.getBeanClass() + '[');
for (int i = 0; i < properties.length; i++) {
sb.append(properties[i].getName() + ':' + properties[i].getPropertyType() + ", ");
}
sb.append(']');
return sb.toString();
}
/**
* Utility method to parse the standard property descriptors and turn them into remote ones.
*
* @param localProperties the standard properties to operate on
*/
private void generateRemotePropertyDescriptors(PropertyDescriptor[] localProperties) {
properties = new RemotePropertyDescriptor[localProperties.length];
PropertyDescriptor current = null;
for (int i = 0; i < properties.length; i++) {
current = localProperties[i];
properties[i] = new RemotePropertyDescriptor(current.getName(), current.getDisplayName(), current.getPropertyType(),
current.getPropertyEditorClass(), current.getShortDescription());
}
}
/**
* Accessor to the BeanDescriptor.
*
* @return the BeanDescriptor.
*/
public RemoteBeanDescriptor getBeanDescriptor() {
return beanDescriptor;
}
/**
* Accesor method for the properties of the bean.
*
* @return the remote properties of the bean.
*/
public RemotePropertyDescriptor[] getRemotePropertyDescriptors() {
return properties;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy