use of java.beans.IndexedPropertyDescriptor in project spring-framework by spring-projects.
the class SimplePropertyDescriptorTests method indexedEquality.
@Test
public void indexedEquality() throws IntrospectionException, SecurityException, NoSuchMethodException {
Object pd1 = new ExtendedBeanInfo.SimpleIndexedPropertyDescriptor("foo", null, null, null, null);
assertThat(pd1, equalTo(pd1));
Object pd2 = new ExtendedBeanInfo.SimpleIndexedPropertyDescriptor("foo", null, null, null, null);
assertThat(pd1, equalTo(pd2));
assertThat(pd2, equalTo(pd1));
@SuppressWarnings("unused")
class C {
public Object setFoo(int i, String foo) {
return null;
}
public String getFoo(int i) {
return null;
}
}
Method wm1 = C.class.getMethod("setFoo", int.class, String.class);
Object pd3 = new ExtendedBeanInfo.SimpleIndexedPropertyDescriptor("foo", null, null, null, wm1);
assertThat(pd1, not(equalTo(pd3)));
assertThat(pd3, not(equalTo(pd1)));
Method rm1 = C.class.getMethod("getFoo", int.class);
Object pd4 = new ExtendedBeanInfo.SimpleIndexedPropertyDescriptor("foo", null, null, rm1, null);
assertThat(pd1, not(equalTo(pd4)));
assertThat(pd4, not(equalTo(pd1)));
Object pd5 = new IndexedPropertyDescriptor("foo", null, null, null, null);
assertThat(pd1, equalTo(pd5));
assertThat(pd5, equalTo(pd1));
Object pd6 = "not a PD";
assertThat(pd1, not(equalTo(pd6)));
assertThat(pd6, not(equalTo(pd1)));
Object pd7 = null;
assertThat(pd1, not(equalTo(pd7)));
assertThat(pd7, not(equalTo(pd1)));
}
use of java.beans.IndexedPropertyDescriptor in project tomcat by apache.
the class ConnectorStoreAppender method getPropertyKeys.
/**
* Get all properties from Connector and current ProtocolHandler.
*
* @param bean The connector
* @return List of Connector property names
* @throws IntrospectionException Error introspecting connector
*/
protected List<String> getPropertyKeys(Connector bean) throws IntrospectionException {
ArrayList<String> propertyKeys = new ArrayList<>();
// Acquire the list of properties for this bean
ProtocolHandler protocolHandler = bean.getProtocolHandler();
// Acquire the list of properties for this bean
PropertyDescriptor[] descriptors = Introspector.getBeanInfo(bean.getClass()).getPropertyDescriptors();
if (descriptors == null) {
descriptors = new PropertyDescriptor[0];
}
for (PropertyDescriptor descriptor : descriptors) {
if (descriptor instanceof IndexedPropertyDescriptor) {
// Indexed properties are not persisted
continue;
}
if (!isPersistable(descriptor.getPropertyType()) || (descriptor.getReadMethod() == null) || (descriptor.getWriteMethod() == null)) {
// Must be a read-write primitive or String
continue;
}
if ("protocol".equals(descriptor.getName()) || "protocolHandlerClassName".equals(descriptor.getName()))
continue;
propertyKeys.add(descriptor.getName());
}
// Add the properties of the protocol handler
descriptors = Introspector.getBeanInfo(protocolHandler.getClass()).getPropertyDescriptors();
if (descriptors == null) {
descriptors = new PropertyDescriptor[0];
}
for (PropertyDescriptor descriptor : descriptors) {
if (descriptor instanceof IndexedPropertyDescriptor) {
// Indexed properties are not persisted
continue;
}
if (!isPersistable(descriptor.getPropertyType()) || (descriptor.getReadMethod() == null) || (descriptor.getWriteMethod() == null)) {
// Must be a read-write primitive or String
continue;
}
String key = descriptor.getName();
if (!Connector.INTERNAL_EXECUTOR_NAME.equals(bean.getExecutorName()) && internalExecutorAttributes.contains(key)) {
continue;
}
if (replacements.get(key) != null) {
key = replacements.get(key);
}
if (!propertyKeys.contains(key)) {
propertyKeys.add(key);
}
}
// Add the properties for the socket
final String socketName = "socket.";
descriptors = Introspector.getBeanInfo(SocketProperties.class).getPropertyDescriptors();
if (descriptors == null) {
descriptors = new PropertyDescriptor[0];
}
for (PropertyDescriptor descriptor : descriptors) {
if (descriptor instanceof IndexedPropertyDescriptor) {
// Indexed properties are not persisted
continue;
}
if (!isPersistable(descriptor.getPropertyType()) || (descriptor.getReadMethod() == null) || (descriptor.getWriteMethod() == null)) {
// Must be a read-write primitive or String
continue;
}
String key = descriptor.getName();
if (replacements.get(key) != null) {
key = replacements.get(key);
}
if (!propertyKeys.contains(key)) {
// Add socket.[original name] if this is not a property
// that could be set elsewhere
propertyKeys.add(socketName + descriptor.getName());
}
}
return propertyKeys;
}
use of java.beans.IndexedPropertyDescriptor in project tomcat by apache.
the class StoreAppender method printAttributes.
/**
* Store the relevant attributes of the specified JavaBean.
*
* @param writer PrintWriter to which we are storing
* @param indent Indentation level
* @param include
* Should we include a <code>className</code> attribute?
* @param bean
* Bean whose properties are to be rendered as attributes,
* @param desc
* RegistryDescriptor from this bean
*
* @exception Exception
* if an exception occurs while storing
*/
public void printAttributes(PrintWriter writer, int indent, boolean include, Object bean, StoreDescription desc) throws Exception {
// Render a className attribute if requested
if (include && desc != null && !desc.isStandard()) {
writer.print(" className=\"");
writer.print(bean.getClass().getName());
writer.print("\"");
}
// Acquire the list of properties for this bean
PropertyDescriptor[] descriptors = Introspector.getBeanInfo(bean.getClass()).getPropertyDescriptors();
if (descriptors == null) {
descriptors = new PropertyDescriptor[0];
}
// Create blank instance
Object bean2 = defaultInstance(bean);
for (int i = 0; i < descriptors.length; i++) {
if (descriptors[i] instanceof IndexedPropertyDescriptor) {
// Indexed properties are not persisted
continue;
}
if (!isPersistable(descriptors[i].getPropertyType()) || (descriptors[i].getReadMethod() == null) || (descriptors[i].getWriteMethod() == null)) {
// Must be a read-write primitive or String
continue;
}
if (desc.isTransientAttribute(descriptors[i].getName())) {
// Skip the specified exceptions
continue;
}
Object value = IntrospectionUtils.getProperty(bean, descriptors[i].getName());
if (value == null) {
// Null values are not persisted
continue;
}
Object value2 = IntrospectionUtils.getProperty(bean2, descriptors[i].getName());
if (value.equals(value2)) {
// The property has its default value
continue;
}
printAttribute(writer, indent, bean, desc, descriptors[i].getName(), bean2, value);
}
if (bean instanceof ResourceBase) {
ResourceBase resource = (ResourceBase) bean;
for (Iterator<String> iter = resource.listProperties(); iter.hasNext(); ) {
String name = iter.next();
Object value = resource.getProperty(name);
if (!isPersistable(value.getClass())) {
continue;
}
if (desc.isTransientAttribute(name)) {
// Skip the specified exceptions
continue;
}
printValue(writer, indent, name, value);
}
}
}
use of java.beans.IndexedPropertyDescriptor in project ACS by ACS-Community.
the class BeanNode method computeProperties.
/**
* Computes a descriptor for properties from a bean info.
* @param bean bean to create properties for
* @param info about the bean
* @param ignoreHiddenProperties true if hidden property should be ignored completely
* @param propertyInfo extra information of some properties (possibly null)
* @return three property lists
*/
private static Descriptor computeProperties(Object bean, BeanInfo info, boolean ignoreHiddenProperties, Boolean nodePropertiesCacheable, PropertyInfo[] propertyInfo) {
java.util.List property = null;
java.util.List expert = null;
java.util.List hidden = null;
PropertyDescriptor[] propertyDescriptor = info.getPropertyDescriptors();
int k = propertyDescriptor.length;
for (int i = 0; i < k; i++) {
if (propertyDescriptor[i].getPropertyType() == null)
continue;
String propName = propertyDescriptor[i].getName();
// we first update the PropertyDescriptor with the PropertyInfo
// that update may make non hidden a property that was hidden
PropertyInfo propInfo = findPropertyInfoByName(propertyInfo, propName);
if (propInfo != null)
propInfo.updatePropertyDescriptor(propertyDescriptor[i]);
// after the update we can test whether the property is hidden or not
if (ignoreHiddenProperties && propertyDescriptor[i].isHidden()) {
continue;
}
CachingStrategy strategy = createCachingStrategy(nodePropertiesCacheable, BeanTagger.isCacheable(propertyDescriptor[i]));
Node.Property prop;
if (propertyDescriptor[i] instanceof IndexedPropertyDescriptor) {
prop = createIndexedNodeProperty(bean, (IndexedPropertyDescriptor) propertyDescriptor[i], strategy);
} else {
prop = createNodeProperty(bean, propertyDescriptor[i], strategy);
}
if (prop == null)
continue;
if (propertyDescriptor[i].isHidden()) {
if (hidden == null)
hidden = new java.util.ArrayList();
hidden.add(prop);
} else if (propertyDescriptor[i].isExpert()) {
if (expert == null)
expert = new java.util.ArrayList();
expert.add(prop);
} else {
if (property == null)
property = new java.util.ArrayList();
property.add(prop);
}
}
// for
return new Descriptor(property, expert, hidden);
}
use of java.beans.IndexedPropertyDescriptor in project jdk8u_jdk by JetBrains.
the class Test7172865 method main.
public static void main(String[] args) throws Exception {
int errors = 0;
MethodDescriptor md = new MethodDescriptor(Test7172865.class.getMethod("getGood"));
errors += test(PropertyDescriptor.class, "good", true);
PropertyDescriptor pdGoodString = new PropertyDescriptor("good", Test7172865.class, "getGood", "setGood");
PropertyDescriptor pdGoodMethod = new PropertyDescriptor("good", Test7172865.class.getMethod("getGood"), Test7172865.class.getMethod("setGood", args.getClass()));
errors += test(PropertyDescriptor.class, "bad", false);
PropertyDescriptor pdBadString = new PropertyDescriptor("bad", Test7172865.class, "getBad", null);
PropertyDescriptor pdBadMethod = new PropertyDescriptor("bad", Test7172865.class.getMethod("getBad"), Test7172865.class.getMethod("setBad", args.getClass()));
errors += test(IndexedPropertyDescriptor.class, "good", true);
IndexedPropertyDescriptor ipdGoodString = new IndexedPropertyDescriptor("good", Test7172865.class, "getGood", "setGood", "getGood", "setGood");
IndexedPropertyDescriptor ipdGoodMethod = new IndexedPropertyDescriptor("good", Test7172865.class.getMethod("getGood"), Test7172865.class.getMethod("setGood", args.getClass()), Test7172865.class.getMethod("getGood", Integer.TYPE), Test7172865.class.getMethod("setGood", Integer.TYPE, String.class));
errors += test(IndexedPropertyDescriptor.class, "bad", false);
IndexedPropertyDescriptor ipdBadString = new IndexedPropertyDescriptor("bad", Test7172865.class, "getBad", null, "getBad", null);
IndexedPropertyDescriptor ipdBadMethod = new IndexedPropertyDescriptor("bad", Test7172865.class.getMethod("getBad"), Test7172865.class.getMethod("setBad", args.getClass()), Test7172865.class.getMethod("getBad", Integer.TYPE), Test7172865.class.getMethod("setBad", Integer.TYPE, String.class));
for (int i = 1; i <= 2; i++) {
System.out.println("STEP: " + i);
errors += test("md", null != md.getMethod());
errors += test("pdGoodString", pdGoodString, true, true);
errors += test("pdGoodMethod", pdGoodMethod, true, true);
errors += test("pdBadString", pdBadString, true, false);
errors += test("pdBadMethod", pdBadMethod, true, true);
errors += test("ipdGoodString", ipdGoodString, true, true, true, true);
errors += test("ipdGoodMethod", ipdGoodMethod, true, true, true, true);
errors += test("ipdBadString", ipdBadString, true, false, true, false);
errors += test("ipdBadMethod", ipdBadMethod, true, true, true, true);
try {
int[] array = new int[1024];
while (true) {
array = new int[array.length << 1];
}
} catch (OutOfMemoryError error) {
System.gc();
}
}
if (errors > 0) {
throw new Error("found " + errors + " errors");
}
}
Aggregations