| career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

// $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testbeans/,v 1.4 2004/02/11 14:40:51 jsalvata Exp $
 * Copyright 2004 The Apache Software Foundation.
 * 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
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package org.apache.jmeter.testbeans;

import java.awt.Image;
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.EventSetDescriptor;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.MethodDescriptor;
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

 * Support class for test bean beanInfo objects. It will help using the
 * introspector to get most of the information, to then modify it at will.

* To use, subclass it, create a subclass with a parameter-less constructor * that: *

  1. Calls super(beanClass) *
  2. Modifies the property descriptors, bean descriptor, etc. at will. *

* Even before any such modifications, a resource bundle named xxxResources * (where xxx is the fully qualified bean class name) will be obtained if * available and used to localize the following: *

  • Bean's display name -- from property displayName. *
  • Properties' display names -- from properties * propertyName.displayName. *
  • Properties' short descriptions -- from properties * propertyName.shortDescription. *

* The resource bundle will be stored as the bean descriptor's "resourceBundle" * attribute, so that it can be used for further localization. TestBeanGUI, for * example, uses it to obtain the group's display names from properties * groupName.displayName. * * @author Jordi Salvat i Alabart * @version $Revision: 1.4 $ updated on $Date: 2004/02/11 14:40:51 $ */ public abstract class BeanInfoSupport extends SimpleBeanInfo { private static transient Logger log = LoggingManager.getLoggerForClass(); // Some known attribute names, just for convenience: public static final String TAGS= GenericTestBeanCustomizer.TAGS; public static final String NOT_UNDEFINED= GenericTestBeanCustomizer.NOT_UNDEFINED; public static final String NOT_EXPRESSION= GenericTestBeanCustomizer.NOT_EXPRESSION; public static final String NOT_OTHER= GenericTestBeanCustomizer.NOT_OTHER; public static final String DEFAULT= GenericTestBeanCustomizer.DEFAULT; public static final String RESOURCE_BUNDLE= GenericTestBeanCustomizer.RESOURCE_BUNDLE; /** The class for which we're providing the bean info. */ private Class beanClass; /** The BeanInfo for our class as obtained by the introspector. */ private BeanInfo rootBeanInfo; /** The icons for this bean. */ private Image[] icons= new Image[5]; /** * Construct a BeanInfo for the given class. */ protected BeanInfoSupport(Class beanClass) { this.beanClass= beanClass; try { rootBeanInfo= Introspector.getBeanInfo( beanClass, Introspector.IGNORE_IMMEDIATE_BEANINFO); } catch (IntrospectionException e) { log.error("Can't introspect.", e); throw new Error(e.toString()); // Programming error: bail out. } try{ ResourceBundle resourceBundle= ResourceBundle.getBundle( beanClass.getName()+"Resources", JMeterUtils.getLocale()); // Store the resource bundle as an attribute of the BeanDescriptor: getBeanDescriptor().setValue(RESOURCE_BUNDLE, resourceBundle); // Localize the bean name try { getBeanDescriptor().setDisplayName( resourceBundle.getString("displayName")); } catch (MissingResourceException e) { log.debug( "Localized display name not available for bean " +beanClass.getName()); } // Localize the property names and descriptions: PropertyDescriptor[] properties= getPropertyDescriptors(); for (int i=0; i * It will assing the given group name to each of the named properties, * and set their order attribute so that they are shown in the given order. *

* The created groups will get order 1, 2, 3,... in the order in which they * are created. * * @param group name of the group * @param names property names in the desired order */ protected void createPropertyGroup(String group, String[] names) { for (int i=0; i

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.