Java Code Examples for java.beans.BeanInfo

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Arecibo, under directory /alert-data-support/src/main/java/com/ning/arecibo/alert/confdata/dao/.

Source file: LowerToCamelBeanMapper.java

  23 
vote

public LowerToCamelBeanMapper(final Class<T> type){
  this.type=type;
  try {
    final BeanInfo info=Introspector.getBeanInfo(type);
    for (    final PropertyDescriptor descriptor : info.getPropertyDescriptors()) {
      properties.put(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE,descriptor.getName()).toLowerCase(),descriptor);
    }
  }
 catch (  IntrospectionException e) {
    throw new IllegalArgumentException(e);
  }
}
 

Example 2

From project jdbi, under directory /src/main/java/org/skife/jdbi/v2/.

Source file: BeanMapper.java

  23 
vote

public BeanMapper(Class<T> type){
  this.type=type;
  try {
    BeanInfo info=Introspector.getBeanInfo(type);
    for (    PropertyDescriptor descriptor : info.getPropertyDescriptors()) {
      properties.put(descriptor.getName().toLowerCase(),descriptor);
    }
  }
 catch (  IntrospectionException e) {
    throw new IllegalArgumentException(e);
  }
}
 

Example 3

From project core_1, under directory /src/com/iCo6/util/org/apache/commons/dbutils/.

Source file: BeanProcessor.java

  22 
vote

/** 
 * Returns a PropertyDescriptor[] for the given Class.
 * @param c The Class to retrieve PropertyDescriptors for.
 * @return A PropertyDescriptor[] describing the Class.
 * @throws SQLException if introspection failed.
 */
private PropertyDescriptor[] propertyDescriptors(Class<?> c) throws SQLException {
  BeanInfo beanInfo=null;
  try {
    beanInfo=Introspector.getBeanInfo(c);
  }
 catch (  IntrospectionException e) {
    throw new SQLException("Bean introspection failed: " + e.getMessage());
  }
  return beanInfo.getPropertyDescriptors();
}
 

Example 4

From project des, under directory /daemon/lib/apache-log4j-1.2.16/src/main/java/org/apache/log4j/config/.

Source file: PropertySetter.java

  22 
vote

/** 
 * Uses JavaBeans  {@link Introspector} to computer setters of object to beconfigured.
 */
protected void introspect(){
  try {
    BeanInfo bi=Introspector.getBeanInfo(obj.getClass());
    props=bi.getPropertyDescriptors();
  }
 catch (  IntrospectionException ex) {
    LogLog.error("Failed to introspect " + obj + ": "+ ex.getMessage());
    props=new PropertyDescriptor[0];
  }
}
 

Example 5

From project fest-reflect, under directory /src/main/java/org/fest/reflect/beanproperty/.

Source file: Invoker.java

  22 
vote

private static PropertyDescriptor descriptorForProperty(String propertyName,Object target){
  BeanInfo beanInfo=null;
  Class<?> type=target.getClass();
  try {
    beanInfo=Introspector.getBeanInfo(type);
  }
 catch (  Exception e) {
    throw new ReflectionError(concat("Unable to get BeanInfo for type ",type.getName()),e);
  }
  for (  PropertyDescriptor d : beanInfo.getPropertyDescriptors())   if (propertyName.equals(d.getName()))   return d;
  throw new ReflectionError(concat("Unable to find property ",quote(propertyName)," in ",type.getName()));
}
 

Example 6

From project geronimo-xbean, under directory /xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/.

Source file: XBeanNamespaceHandler.java

  22 
vote

private void coerceNamespaceAwarePropertyValues(MutableBeanMetadata bd,Element element,ParserContext parserContext){
  BeanInfo beanInfo=getBeanInfo(getClass(bd.getClassName()));
  if (beanInfo != null) {
    PropertyDescriptor[] descriptors=beanInfo.getPropertyDescriptors();
    for (    PropertyDescriptor descriptor : descriptors) {
      QNameHelper.coerceNamespaceAwarePropertyValues(bd,element,descriptor,parserContext);
    }
  }
}
 

Example 7

From project jboss-el-api_spec, under directory /src/main/java/javax/el/.

Source file: BeanELResolver.java

  22 
vote

public BeanProperties(Class<?> baseClass){
  PropertyDescriptor[] descriptors;
  try {
    BeanInfo info=Introspector.getBeanInfo(baseClass);
    descriptors=info.getPropertyDescriptors();
  }
 catch (  IntrospectionException ie) {
    throw new ELException(ie);
  }
  for (  PropertyDescriptor pd : descriptors) {
    propertyMap.put(pd.getName(),new BeanProperty(baseClass,pd));
  }
}
 

Example 8

From project log4j, under directory /src/main/java/org/apache/log4j/config/.

Source file: PropertySetter.java

  22 
vote

/** 
 * Uses JavaBeans  {@link Introspector} to computer setters of object to beconfigured.
 */
protected void introspect(){
  try {
    BeanInfo bi=Introspector.getBeanInfo(obj.getClass());
    props=bi.getPropertyDescriptors();
  }
 catch (  IntrospectionException ex) {
    LogLog.error("Failed to introspect " + obj + ": "+ ex.getMessage());
    props=new PropertyDescriptor[0];
  }
}
 

Example 9

From project log4jna, under directory /thirdparty/log4j/src/main/java/org/apache/log4j/config/.

Source file: PropertySetter.java

  22 
vote

/** 
 * Uses JavaBeans  {@link Introspector} to computer setters of object to beconfigured.
 */
protected void introspect(){
  try {
    BeanInfo bi=Introspector.getBeanInfo(obj.getClass());
    props=bi.getPropertyDescriptors();
  }
 catch (  IntrospectionException ex) {
    LogLog.error("Failed to introspect " + obj + ": "+ ex.getMessage());
    props=new PropertyDescriptor[0];
  }
}
 

Example 10

From project logback, under directory /logback-core/src/main/java/ch/qos/logback/core/joran/util/.

Source file: PropertySetter.java

  22 
vote

/** 
 * Uses JavaBeans  {@link Introspector} to computer setters of object to beconfigured.
 */
protected void introspect(){
  try {
    BeanInfo bi=Introspector.getBeanInfo(obj.getClass());
    propertyDescriptors=bi.getPropertyDescriptors();
    methodDescriptors=bi.getMethodDescriptors();
  }
 catch (  IntrospectionException ex) {
    addError("Failed to introspect " + obj + ": "+ ex.getMessage());
    propertyDescriptors=new PropertyDescriptor[0];
    methodDescriptors=new MethodDescriptor[0];
  }
}
 

Example 11

From project MCStats3, under directory /src/com/ubempire/MCStats3/reporting/.

Source file: JSONEncoder.java

  22 
vote

public ObjectEncoder(final Class<?> type) throws IntrospectionException {
  final BeanInfo info=Introspector.getBeanInfo(type);
  final PropertyDescriptor[] descriptors=info.getPropertyDescriptors();
  final List<Property> props=new ArrayList<Property>(descriptors.length);
  for (int i=0; i < descriptors.length; i++) {
    final PropertyDescriptor d=descriptors[i];
    final Method read=d.getReadMethod();
    if (!read.getDeclaringClass().equals(Object.class)) {
      props.add(new Property(d.getName(),read));
    }
  }
  properties=props.toArray(new Property[props.size()]);
}
 

Example 12

From project niravCS2103, under directory /CS2103/lib/apache-log4j-1.2.16/src/main/java/org/apache/log4j/config/.

Source file: PropertySetter.java

  22 
vote

/** 
 * Uses JavaBeans  {@link Introspector} to computer setters of object to beconfigured.
 */
protected void introspect(){
  try {
    BeanInfo bi=Introspector.getBeanInfo(obj.getClass());
    props=bi.getPropertyDescriptors();
  }
 catch (  IntrospectionException ex) {
    LogLog.error("Failed to introspect " + obj + ": "+ ex.getMessage());
    props=new PropertyDescriptor[0];
  }
}
 

Example 13

From project OMS3, under directory /src/main/java/oms3/dsl/.

Source file: BeanBuilder.java

  22 
vote

protected void loadBean() throws IntrospectionException {
  propertyMap=new HashMap<String,PropertyDescriptor>();
  BeanInfo info=Introspector.getBeanInfo(beanClass);
  PropertyDescriptor[] properties=info.getPropertyDescriptors();
  for (int i=0; i < properties.length; i++) {
    propertyMap.put(properties[i].getName(),properties[i]);
  }
}
 

Example 14

From project openengsb-framework, under directory /components/util/src/main/java/org/openengsb/core/util/.

Source file: ModelUtils.java

  22 
vote

/** 
 * Returns all property descriptors for a given class.
 */
public static List<PropertyDescriptor> getPropertyDescriptorsForClass(Class<?> clasz){
  try {
    BeanInfo beanInfo=Introspector.getBeanInfo(clasz);
    return Arrays.asList(beanInfo.getPropertyDescriptors());
  }
 catch (  IntrospectionException e) {
    LOGGER.error("instantiation exception while trying to create instance of class {}",clasz.getName());
  }
  return Lists.newArrayList();
}
 

Example 15

From project org.openscada.atlantis, under directory /org.openscada.da.core.common/src/org/openscada/da/core/.

Source file: VariantBeanHelper.java

  22 
vote

/** 
 * Extract the property data as string/variant map
 * @param source the source object
 * @return the map with bean data
 * @throws IntrospectionException
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static Map<String,Variant> extract(final Object source) throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
  final Map<String,Variant> result=new HashMap<String,Variant>();
  final BeanInfo bi=Introspector.getBeanInfo(source.getClass());
  for (  final PropertyDescriptor pd : bi.getPropertyDescriptors()) {
    final Method m=pd.getReadMethod();
    if (m != null) {
      result.put(pd.getName(),Variant.valueOf(m.invoke(source)));
    }
  }
  return result;
}
 

Example 16

From project org.openscada.aurora, under directory /org.openscada.utils.filter/src/org/openscada/utils/filter/bean/.

Source file: BeanMatcher.java

  22 
vote

protected static PropertyDescriptor getProperyDescriptor(final Class<?> clazz,final String name) throws Exception {
  final BeanInfo bi=Introspector.getBeanInfo(clazz);
  for (  final PropertyDescriptor pd : bi.getPropertyDescriptors()) {
    if (pd.getName().equals(name)) {
      return pd;
    }
  }
  return null;
}
 

Example 17

From project org.ops4j.pax.logging, under directory /pax-logging-service/src/main/java/org/apache/log4j/config/.

Source file: PaxPropertySetter.java

  22 
vote

/** 
 * Uses JavaBeans  {@link Introspector} to computer setters of object to beconfigured.
 */
protected void introspect(){
  try {
    BeanInfo bi=Introspector.getBeanInfo(obj.getClass());
    props=bi.getPropertyDescriptors();
  }
 catch (  IntrospectionException ex) {
    LogLog.error("Failed to introspect " + obj + ": "+ ex.getMessage());
    props=new PropertyDescriptor[0];
  }
}
 

Example 18

From project processFlowProvision, under directory /pfpServices/adminConsole/src/main/java/org/jboss/processFlow/console/binding/.

Source file: AbstractDataBinder.java

  22 
vote

/** 
 * Get the bean properties as <code>java.uti.Map</code>
 * @param bean
 * @return
 * @throws IntrospectionException
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
protected Map getProperties(Object bean) throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
  Map<String,Object> properties=new HashMap<String,Object>();
  BeanInfo bi=Introspector.getBeanInfo(bean.getClass());
  PropertyDescriptor[] props=bi.getPropertyDescriptors();
  for (int i=0; i < props.length; i++) {
    Method getter=props[i].getReadMethod();
    if (getter == null)     continue;
    String name=props[i].getName();
    Object result=getter.invoke(bean,NULL_ARG);
    properties.put(name,result);
  }
  return properties;
}
 

Example 19

From project rapid, under directory /rapid-generator/rapid-generator/src/main/java/cn/org/rapid_framework/generator/provider/java/model/.

Source file: JavaClass.java

  22 
vote

public JavaProperty[] getProperties() throws Exception {
  List<JavaProperty> result=new ArrayList<JavaProperty>();
  BeanInfo beanInfo=Introspector.getBeanInfo(clazz);
  PropertyDescriptor[] pds=beanInfo.getPropertyDescriptors();
  for (  PropertyDescriptor pd : pds) {
    if (!"class".equalsIgnoreCase(pd.getName())) {
      result.add(new JavaProperty(pd,this));
    }
  }
  return (JavaProperty[])result.toArray(new JavaProperty[0]);
}
 

Example 20

From project recommenders, under directory /tests/org.eclipse.recommenders.tests.rcp/src/org/eclipse/recommenders/tests/rcp/models/.

Source file: MetadataTest.java

  22 
vote

@Test public void testGetters() throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
  BeanInfo info=Introspector.getBeanInfo(ModelArchiveMetadata.class);
  for (  PropertyDescriptor d : info.getPropertyDescriptors()) {
    Method m=d.getReadMethod();
    m.invoke(sut);
  }
}
 

Example 21

From project saiku-adhoc, under directory /saiku-adhoc-core/src/main/java/org/saiku/adhoc/utils/.

Source file: TemplateUtils.java

  22 
vote

public static void mergeElementFormats(SaikuElementFormat source,SaikuElementFormat target) throws Exception {
  BeanInfo beanInfo=Introspector.getBeanInfo(target.getClass());
  for (  PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) {
    if (descriptor.getWriteMethod() != null) {
      Object sourceValue=descriptor.getReadMethod().invoke(source);
      if (sourceValue != null) {
        descriptor.getWriteMethod().invoke(target,sourceValue);
      }
    }
  }
}
 

Example 22

From project SIARD-Val, under directory /SIARD-Val/external-sources/log4j-1.2.12/java/org/apache/log4j/config/.

Source file: PropertySetter.java

  22 
vote

/** 
 * Uses JavaBeans  {@link Introspector} to computer setters of object to beconfigured.
 */
protected void introspect(){
  try {
    BeanInfo bi=Introspector.getBeanInfo(obj.getClass());
    props=bi.getPropertyDescriptors();
  }
 catch (  IntrospectionException ex) {
    LogLog.error("Failed to introspect " + obj + ": "+ ex.getMessage());
    props=new PropertyDescriptor[0];
  }
}
 

Example 23

From project spring-data-commons, under directory /spring-data-commons-core/src/test/java/org/springframework/data/mapping/model/.

Source file: AbstractPersistentPropertyUnitTests.java

  22 
vote

private static PropertyDescriptor getPropertyDescriptor(Class<?> type,String propertyName){
  try {
    BeanInfo info=Introspector.getBeanInfo(type);
    for (    PropertyDescriptor descriptor : info.getPropertyDescriptors()) {
      if (descriptor.getName().equals(propertyName)) {
        return descriptor;
      }
    }
    return null;
  }
 catch (  IntrospectionException e) {
    return null;
  }
}
 

Example 24

From project SpringSecurityDemo, under directory /src/test/java/com/github/peholmst/springsecuritydemo/domain/.

Source file: AbstractEntityTest.java

  22 
vote

@Test public void testWritableProperties() throws Exception {
  System.out.println("testWritableProperties");
  BeanInfo info=Introspector.getBeanInfo(getEntity().getClass());
  for (  PropertyDescriptor pd : info.getPropertyDescriptors()) {
    if (pd.getWriteMethod() != null) {
      Object testData=createRandomValue(pd.getPropertyType());
      System.out.println("  Testing property " + pd.getName());
      pd.getWriteMethod().invoke(getEntity(),testData);
      assertEquals("Returned property value should be equal to the set property value",testData,pd.getReadMethod().invoke(getEntity()));
    }
  }
}
 

Example 25

From project summer, under directory /modules/core/src/main/java/com/asual/summer/core/faces/.

Source file: ComponentUtils.java

  22 
vote

static Object getConfig(Component component,String name){
  BeanInfo info=(BeanInfo)component.getAttributes().get(UIComponent.BEANINFO_KEY);
  if (info != null) {
    TagValueExpression ve=(TagValueExpression)info.getBeanDescriptor().getValue(name);
    if (ve != null) {
      return ve.getValue(FacesContext.getCurrentInstance().getELContext());
    }
  }
  return null;
}
 

Example 26

From project zen-project, under directory /zen-dataobject/src/main/java/com/nominanuda/dataobject/dataview/.

Source file: BeanPropertyReader.java

  22 
vote

private BeanInfo info(Object o){
  try {
    BeanInfo info=Introspector.getBeanInfo(o.getClass());
    return info;
  }
 catch (  IntrospectionException e) {
    throw new RuntimeException(e);
  }
}
 

Example 27

From project ajah, under directory /ajah-spring-jdbc/src/main/java/com/ajah/spring/jdbc/.

Source file: AbstractAjahDao.java

  21 
vote

private Object[] getInsertValues(final T entity){
  final Object[] values=new Object[getColumns().size()];
  try {
    final BeanInfo componentBeanInfo=Introspector.getBeanInfo(entity.getClass());
    final PropertyDescriptor[] props=componentBeanInfo.getPropertyDescriptors();
    for (int i=0; i < values.length; i++) {
      final Field field=this.colMap.get(this.columns.get(i));
      values[i]=ReflectionUtils.propGetSafeAuto(entity,field,getProp(field,props));
      if (log.isLoggable(Level.FINEST)) {
        log.finest(field.getName() + " set to " + values[i]);
      }
    }
  }
 catch (  final IntrospectionException e) {
    log.log(Level.SEVERE,entity.getClass().getName() + ": " + e.getMessage(),e);
  }
  return values;
}
 

Example 28

From project asterisk-java, under directory /src/main/java/org/asteriskjava/tools/.

Source file: HtmlEventTracer.java

  21 
vote

protected String getProperty(Object obj,String property){
  try {
    BeanInfo beanInfo=Introspector.getBeanInfo(obj.getClass());
    for (    PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) {
      if (!propertyDescriptor.getName().equals(property)) {
        continue;
      }
      return propertyDescriptor.getReadMethod().invoke(obj).toString();
    }
  }
 catch (  Exception e) {
    System.err.println("Unable to read property '" + property + "' from object "+ obj+ ": "+ e.getMessage());
    return null;
  }
  return null;
}
 

Example 29

From project BeeQueue, under directory /src/org/beequeue/util/.

Source file: BeanUtil.java

  21 
vote

private static MyProperty getMyProperty(Class<? extends Object> valueClass,String propName) throws Exception {
  MyProperty pd;
  int index=0;
  Matcher matcher=INDEXED_PROPERTY.matcher(propName);
  if (matcher.matches()) {
    propName=matcher.group(1);
    index=Integer.parseInt(matcher.group(2));
  }
  try {
    BeanInfo beanInfo=BeanProperty.getBeanInfo(valueClass);
    pd=new BeanProperty(BeanProperty.findProperty(beanInfo,propName),index);
  }
 catch (  Exception e) {
    Field declaredField=valueClass.getField(propName);
    if (declaredField != null && (declaredField.getModifiers() & Modifier.PUBLIC) > 0) {
      pd=new FieldProperty(declaredField,index);
    }
 else {
      throw e;
    }
  }
  return pd;
}
 

Example 30

From project c3p0, under directory /src/java/com/mchange/v2/c3p0/management/.

Source file: DynamicPooledDataSourceManagerMBean.java

  21 
vote

private static Map extractAttributeInfos(Object bean){
  if (bean != null) {
    try {
      Map out=new HashMap();
      BeanInfo beanInfo=Introspector.getBeanInfo(bean.getClass(),Object.class);
      PropertyDescriptor[] pds=beanInfo.getPropertyDescriptors();
      for (int i=0, len=pds.length; i < len; ++i) {
        PropertyDescriptor pd=pds[i];
        String name;
        String desc;
        Method getter;
        Method setter;
        name=pd.getName();
        if (HIDE_PROPS.contains(name))         continue;
        desc=getDescription(name);
        getter=pd.getReadMethod();
        setter=pd.getWriteMethod();
        if (FORCE_READ_ONLY_PROPS.contains(name))         setter=null;
        try {
          out.put(name,new MBeanAttributeInfo(name,desc,getter,setter));
        }
 catch (        javax.management.IntrospectionException e) {
          if (logger.isLoggable(MLevel.WARNING))           logger.log(MLevel.WARNING,"IntrospectionException while setting up MBean attribute '" + name + "'",e);
        }
      }
      return Collections.synchronizedMap(out);
    }
 catch (    java.beans.IntrospectionException e) {
      if (logger.isLoggable(MLevel.WARNING))       logger.log(MLevel.WARNING,"IntrospectionException while setting up MBean attributes for " + bean,e);
      return Collections.EMPTY_MAP;
    }
  }
 else   return Collections.EMPTY_MAP;
}
 

Example 31

From project cdk, under directory /generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/.

Source file: TypesFactoryImpl.java

  21 
vote

/** 
 * <p> Retrieve the property descriptors for the specified class, introspecting and caching them the first time a particular bean class is encountered. </p> <p> <strong>FIXME</strong> - Does not work with DynaBeans. </p>
 * @param beanClass Bean class for which property descriptors are requested
 * @return the property descriptors
 * @throws ParsingException if error occured.
 * @exception IllegalArgumentException if <code>beanClass</code> is null
 */
private static PropertyDescriptor[] getPropertyDescriptors(Class<?> beanClass) throws ParsingException {
  if (beanClass == null) {
    throw new IllegalArgumentException("No bean class specified");
  }
  PropertyDescriptor[] descriptors=null;
  BeanInfo beanInfo=null;
  try {
    beanInfo=Introspector.getBeanInfo(beanClass);
    descriptors=beanInfo.getPropertyDescriptors();
  }
 catch (  IntrospectionException e) {
    return EMPTY_PROPERTY_DESCRIPTORS;
  }
  if (descriptors == null) {
    descriptors=EMPTY_PROPERTY_DESCRIPTORS;
  }
  return descriptors;
}
 

Example 32

From project Cinch, under directory /src/com/palantir/ptoss/cinch/core/.

Source file: BindingContext.java

  21 
vote

private Map<String,ObjectFieldMethod> indexBindableProperties(Function<PropertyDescriptor,Method> methodFn) throws IntrospectionException {
  final Map<ObjectFieldMethod,String> getterOfms=Maps.newHashMap();
  for (  Field field : Sets.newHashSet(bindableModels.values())) {
    BeanInfo beanInfo=Introspector.getBeanInfo(field.getType());
    PropertyDescriptor[] props=beanInfo.getPropertyDescriptors();
    for (    PropertyDescriptor descriptor : props) {
      Method method=methodFn.apply(descriptor);
      if (method == null) {
        continue;
      }
      BindableModel model=getFieldObject(field,BindableModel.class);
      getterOfms.put(new ObjectFieldMethod(model,field,method),descriptor.getName());
    }
  }
  return dotIndex(getterOfms.keySet(),ObjectFieldMethod.TO_FIELD_NAME,Functions.forMap(getterOfms));
}
 

Example 33

From project codjo-standalone-common, under directory /src/main/java/net/codjo/persistent/sql/.

Source file: SimpleHomeMapping.java

  21 
vote

/** 
 * Initialisation.
 * @param objectClass La classe de l'objet
 * @param initMask Le masque d'initialisation
 * @exception IntrospectionException Recherche des accesseurs impossible
 * @exception NoSuchMethodException Methode accesseur introuvable
 */
private void initAccessors(Class objectClass,int initMask) throws IntrospectionException, NoSuchMethodException {
  if ((initMask & MASK) == INIT_GETTER) {
    getterMethods=new Method[dbColumnNames.size()];
  }
  if ((initMask & MASK) == INIT_SETTER) {
    setterMethods=new Method[dbColumnNames.size()];
  }
  BeanInfo info=Introspector.getBeanInfo(objectClass);
  PropertyDescriptor[] desc=info.getPropertyDescriptors();
  for (int i=0; i < desc.length; i++) {
    int idx=propertyNames.indexOf(desc[i].getName());
    if (idx != -1 && (initMask & MASK) == INIT_GETTER) {
      getterMethods[idx]=desc[i].getReadMethod();
    }
    if (idx != -1 && (initMask & MASK) == INIT_SETTER) {
      setterMethods[idx]=desc[i].getWriteMethod();
    }
  }
  if ((initMask & MASK) == INIT_GETTER) {
    for (int i=0; i < getterMethods.length; i++) {
      if (getterMethods[i] == null) {
        throw new NoSuchMethodException("Manque getter pour " + propertyNames.get(i));
      }
    }
  }
  if ((initMask & MASK) == INIT_SETTER) {
    for (int i=0; i < setterMethods.length; i++) {
      if (setterMethods[i] == null) {
        throw new NoSuchMethodException("Manque setter pour " + propertyNames.get(i));
      }
    }
  }
}
 

Example 34

From project collections-generic, under directory /src/java/org/apache/commons/collections15/.

Source file: BeanMap.java

  21 
vote

private void initialise(){
  if (getBean() == null)   return;
  Class beanClass=getBean().getClass();
  try {
    BeanInfo beanInfo=Introspector.getBeanInfo(beanClass);
    PropertyDescriptor[] propertyDescriptors=beanInfo.getPropertyDescriptors();
    if (propertyDescriptors != null) {
      for (int i=0; i < propertyDescriptors.length; i++) {
        PropertyDescriptor propertyDescriptor=propertyDescriptors[i];
        if (propertyDescriptor != null) {
          String name=propertyDescriptor.getName();
          Method readMethod=propertyDescriptor.getReadMethod();
          Method writeMethod=propertyDescriptor.getWriteMethod();
          Class aType=propertyDescriptor.getPropertyType();
          if (readMethod != null) {
            readMethods.put(name,readMethod);
          }
          if (writeMethods != null) {
            writeMethods.put(name,writeMethod);
          }
          types.put(name,aType);
        }
      }
    }
  }
 catch (  IntrospectionException e) {
    logWarn(e);
  }
}
 

Example 35

From project components-ness-jdbi, under directory /src/main/java/com/nesscomputing/jdbi/binding/.

Source file: BindDefineBeanFactory.java

  21 
vote

@Override public Binder build(Annotation annotation){
  return new Binder<BindDefineBean,Object>(){
    @Override public void bind(    SQLStatement q,    BindDefineBean bind,    Object arg){
      final String prefix;
      if ("___jdbi_bare___".equals(bind.value())) {
        prefix="";
      }
 else {
        prefix=bind.value() + ".";
      }
      try {
        BeanInfo infos=Introspector.getBeanInfo(arg.getClass());
        PropertyDescriptor[] props=infos.getPropertyDescriptors();
        for (        PropertyDescriptor prop : props) {
          String key=prefix + prop.getName();
          Object value=prop.getReadMethod().invoke(arg);
          q.bind(key,value);
          q.define(key,value);
        }
      }
 catch (      Exception e) {
        throw new IllegalStateException("unable to bind bean properties",e);
      }
    }
  }
;
}
 

Example 36

From project core_4, under directory /api/src/main/java/org/ajax4jsf/javascript/.

Source file: PropertyUtils.java

  21 
vote

public static PropertyDescriptor[] getPropertyDescriptors(Object bean){
  if (bean == null) {
    throw new IllegalArgumentException("argument is null");
  }
  PropertyDescriptor[] descriptors=null;
  try {
    BeanInfo beanInfo=Introspector.getBeanInfo(bean.getClass());
    descriptors=beanInfo.getPropertyDescriptors();
  }
 catch (  IntrospectionException e) {
    LOGGER.error(e.getMessage(),e);
  }
  if (descriptors == null) {
    descriptors=EMPTY_DESCRIPTORS_ARRAY;
  }
  return descriptors;
}
 

Example 37

From project dawn-isencia, under directory /com.isencia.passerelle.commons/src/main/java/com/isencia/util/swing/calendar/.

Source file: JCalendarBeanInfo.java

  21 
vote

/** 
 * This method returns an array of PropertyDescriptors describing the editable properties supported by this bean.
 */
public PropertyDescriptor[] getPropertyDescriptors(){
  try {
    if (PropertyEditorManager.findEditor(Locale.class) == null) {
      BeanInfo beanInfo=Introspector.getBeanInfo(JPanel.class);
      PropertyDescriptor[] p=beanInfo.getPropertyDescriptors();
      int length=p.length;
      PropertyDescriptor[] propertyDescriptors=new PropertyDescriptor[length + 1];
      for (int i=0; i < length; i++)       propertyDescriptors[i + 1]=p[i];
      propertyDescriptors[0]=new PropertyDescriptor("locale",JCalendar.class);
      propertyDescriptors[0].setBound(true);
      propertyDescriptors[0].setConstrained(false);
      propertyDescriptors[0].setPropertyEditorClass(LocaleEditor.class);
      return propertyDescriptors;
    }
  }
 catch (  IntrospectionException e) {
    e.printStackTrace();
  }
  return null;
}
 

Example 38

From project elasticsearch-osem, under directory /src/main/java/org/elasticsearch/osem/annotations/impl/.

Source file: AttributeSourceImpl.java

  21 
vote

private static Collection<PropertyDescriptor> getPropertyDescriptors(Class<?> clazz){
  Collection<PropertyDescriptor> descriptors=new HashSet<PropertyDescriptor>();
  try {
    BeanInfo bean;
    bean=Introspector.getBeanInfo(clazz);
    descriptors.addAll(Arrays.asList(bean.getPropertyDescriptors()));
  }
 catch (  IntrospectionException e) {
    throw new ObjectContextException("Unable to introspect class '" + clazz.getName() + "'",e);
  }
  for (  Class<?> i : clazz.getInterfaces()) {
    descriptors.addAll(getPropertyDescriptors(i));
  }
  if (clazz.getSuperclass() != null) {
    descriptors.addAll(getPropertyDescriptors(clazz.getSuperclass()));
  }
  return descriptors;
}
 

Example 39

From project entando-core-engine, under directory /src/main/java/com/agiletec/apsadmin/tags/.

Source file: AbstractObjectInfoTag.java

  21 
vote

protected Object getPropertyValue(Object masterObject,String propertyValue){
  try {
    BeanInfo beanInfo=Introspector.getBeanInfo(masterObject.getClass());
    PropertyDescriptor[] descriptors=beanInfo.getPropertyDescriptors();
    for (int i=0; i < descriptors.length; i++) {
      PropertyDescriptor descriptor=descriptors[i];
      if (!descriptor.getName().equals(propertyValue)) {
        continue;
      }
      Method method=descriptor.getReadMethod();
      Object[] args=null;
      return method.invoke(masterObject,args);
    }
    if (ApsSystemUtils.getLogger().isLoggable(Level.FINEST)) {
      ApsSystemUtils.getLogger().finest("Invalid required object property : Master Object '" + masterObject.getClass().getName() + "' - property '"+ propertyValue+ "'");
    }
  }
 catch (  Throwable t) {
    ApsSystemUtils.logThrowable(t,this,"getPropertyValue","Error extracting property value : Master Object '" + masterObject.getClass().getName() + "' - property '"+ propertyValue+ "'");
  }
  return null;
}
 

Example 40

From project jAPS2, under directory /src/com/agiletec/apsadmin/tags/.

Source file: AbstractObjectInfoTag.java

  21 
vote

protected Object getPropertyValue(Object masterObject,String propertyValue){
  try {
    BeanInfo beanInfo=Introspector.getBeanInfo(masterObject.getClass());
    PropertyDescriptor[] descriptors=beanInfo.getPropertyDescriptors();
    for (int i=0; i < descriptors.length; i++) {
      PropertyDescriptor descriptor=descriptors[i];
      if (!descriptor.getName().equals(propertyValue)) {
        continue;
      }
      Method method=descriptor.getReadMethod();
      Object[] args=null;
      return method.invoke(masterObject,args);
    }
    if (ApsSystemUtils.getLogger().isLoggable(Level.FINEST)) {
      ApsSystemUtils.getLogger().finest("Invalid required object property : Master Object '" + masterObject.getClass().getName() + "' - property '"+ propertyValue+ "'");
    }
  }
 catch (  Throwable t) {
    ApsSystemUtils.logThrowable(t,this,"getPropertyValue","Error extracting property value : Master Object '" + masterObject.getClass().getName() + "' - property '"+ propertyValue+ "'");
  }
  return null;
}
 

Example 41

From project java-cas-client, under directory /cas-client-core/src/main/java/org/jasig/cas/client/jaas/.

Source file: CasLoginModule.java

  21 
vote

/** 
 * Creates a  {@link TicketValidator} instance from a class name and map of property name/value pairs.
 * @param className Fully-qualified name of {@link TicketValidator} concrete class.
 * @param propertyMap Map of property name/value pairs to set on validator instance.
 * @return Ticket validator with properties set.
 */
private TicketValidator createTicketValidator(final String className,final Map<String,?> propertyMap){
  CommonUtils.assertTrue(propertyMap.containsKey("casServerUrlPrefix"),"Required property casServerUrlPrefix not found.");
  final Class<TicketValidator> validatorClass=ReflectUtils.loadClass(className);
  final TicketValidator validator=ReflectUtils.newInstance(validatorClass,propertyMap.get("casServerUrlPrefix"));
  try {
    final BeanInfo info=Introspector.getBeanInfo(validatorClass);
    for (    final String property : propertyMap.keySet()) {
      if (!"casServerUrlPrefix".equals(property)) {
        log.debug("Attempting to set TicketValidator property " + property);
        final String value=(String)propertyMap.get(property);
        final PropertyDescriptor pd=ReflectUtils.getPropertyDescriptor(info,property);
        if (pd != null) {
          ReflectUtils.setProperty(property,convertIfNecessary(pd,value),validator,info);
          log.debug("Set " + property + "="+ value);
        }
 else {
          log.warn("Cannot find property " + property + " on "+ className);
        }
      }
    }
  }
 catch (  final IntrospectionException e) {
    throw new RuntimeException("Error getting bean info for " + validatorClass,e);
  }
  return validator;
}
 

Example 42

From project jdonframework, under directory /JdonAccessory/src/com/jdon/model/factory/.

Source file: ModelHandlerClassFactoryXmlImp.java

  21 
vote

private Class getKeyClassType(Class beanClasses,String propertyName){
  try {
    BeanInfo beanInfo=Introspector.getBeanInfo(beanClasses);
    PropertyDescriptor[] pds=beanInfo.getPropertyDescriptors();
    for (int i=0; i < pds.length; i++) {
      PropertyDescriptor pd=pds[i];
      if (pd.getName().equalsIgnoreCase(propertyName)) {
        Debug.logVerbose("[JdonFramework]found the key Class Type==" + pd.getPropertyType().getName(),module);
        return pd.getPropertyType();
      }
    }
  }
 catch (  Exception e) {
    Debug.logError(e);
  }
  Debug.logVerbose("[JdonFramework]not found the key Class Type, propertyName=" + propertyName,module);
  return Object.class;
}
 

Example 43

From project jibu, under directory /jibu-core/src/main/java/org/gaixie/jibu/utils/.

Source file: BeanConverter.java

  21 
vote

/** 
 * ??? Map ??avabean ???????????? <p> Map ???????????? key/value ???? map ??? key ? javabean ??????????????????????????????????<p> Map ??? value ?????????????????????? request.getParameterValues() ???? value?<p>
 * @param cls ???? bean ? Class
 * @param map ? bean ????? key ? Map
 * @return ??????????????? Bean
 * @exception JibuException ??????????
 */
public static <T>T mapToBean(Class<T> cls,Map map) throws JibuException {
  try {
    T bean=cls.newInstance();
    BeanInfo beanInfo=Introspector.getBeanInfo(cls);
    PropertyDescriptor[] pds=beanInfo.getPropertyDescriptors();
    for (    PropertyDescriptor pd : pds) {
      Object obj=map.get(pd.getName());
      if (null != obj) {
        Class type=pd.getPropertyType();
        Object value=getBeanValue(type,obj);
        if (null != value) {
          pd.getWriteMethod().invoke(bean,value);
        }
      }
    }
    return bean;
  }
 catch (  Exception e) {
    throw new JibuException(e.getMessage());
  }
}
 

Example 44

From project jPOS, under directory /jpos/src/main/java/org/jpos/q2/.

Source file: QBeanSupport.java

  21 
vote

protected Element createElement(String name,Class mbeanClass){
  Element e=new Element(name);
  Element classPath=persist != null ? persist.getChild("classpath") : null;
  if (classPath != null)   e.addContent(classPath);
  e.setAttribute("class",getClass().getName());
  if (!e.getName().equals(getName()))   e.setAttribute("name",getName());
  String loggerName=getLogger();
  if (loggerName != null)   e.setAttribute("logger",loggerName);
  try {
    BeanInfo info=Introspector.getBeanInfo(mbeanClass);
    PropertyDescriptor[] desc=info.getPropertyDescriptors();
    for (    PropertyDescriptor aDesc : desc) {
      if (aDesc.getWriteMethod() != null) {
        Method read=aDesc.getReadMethod();
        Object obj=read.invoke(this,new Object[]{});
        String type=read.getReturnType().getName();
        if ("java.lang.String".equals(type))         type=null;
        addAttr(e,aDesc.getName(),obj,type);
      }
    }
  }
 catch (  Exception ex) {
    log.warn("get-persist",ex);
  }
  return e;
}
 

Example 45

From project jsecurity, under directory /web/src/main/java/org/apache/ki/web/tags/.

Source file: PrincipalTag.java

  21 
vote

private String getPrincipalProperty(Object principal,String property) throws JspTagException {
  String strValue=null;
  try {
    BeanInfo bi=Introspector.getBeanInfo(principal.getClass());
    boolean foundProperty=false;
    for (    PropertyDescriptor pd : bi.getPropertyDescriptors()) {
      if (pd.getName().equals(property)) {
        Object value=pd.getReadMethod().invoke(principal,(Object[])null);
        strValue=String.valueOf(value);
        foundProperty=true;
        break;
      }
    }
    if (!foundProperty) {
      final String message="Property [" + property + "] not found in principal of type ["+ principal.getClass().getName()+ "]";
      if (log.isErrorEnabled()) {
        log.error(message);
      }
      throw new JspTagException(message);
    }
  }
 catch (  Exception e) {
    final String message="Error reading property [" + property + "] from principal of type ["+ principal.getClass().getName()+ "]";
    if (log.isErrorEnabled()) {
      log.error(message,e);
    }
    throw new JspTagException(message,e);
  }
  return strValue;
}
 

Example 46

From project jsfunit, under directory /jboss-jsfunit-analysis/src/main/java/org/jboss/jsfunit/analysis/el/.

Source file: JSFUnitELResolver.java

  21 
vote

@Override public Object getValue(final ELContext context,final Object base,final Object property){
  if (context == null) {
    throw new NullPointerException("context is null");
  }
  if (base instanceof Class<?>) {
    final BeanInfo beanInfo;
    try {
      beanInfo=Introspector.getBeanInfo((Class<?>)base);
    }
 catch (    final IntrospectionException e) {
      throw new ELException(e);
    }
    for (    final PropertyDescriptor pDes : beanInfo.getPropertyDescriptors()) {
      if (pDes.getName().equals(property)) {
        context.setPropertyResolved(true);
        return pDes.getReadMethod();
      }
    }
    for (    final MethodDescriptor mDes : beanInfo.getMethodDescriptors()) {
      if (mDes.getName().equals(property)) {
        context.setPropertyResolved(true);
        return mDes.getMethod();
      }
    }
    throw new PropertyNotFoundException("Could not resolve property " + property + " for base "+ base);
  }
 else   if (base instanceof Method) {
    final Class<?> baseClass=((Method)base).getReturnType();
    return getValue(context,baseClass,property);
  }
 else {
    return null;
  }
}
 

Example 47

From project mob, under directory /com.netappsid.mob/src/com/netappsid/mob/ejb3/tools/.

Source file: JPAHelper.java

  21 
vote

/** 
 * @param toInspect
 * @param entitiesClass
 * @throws IntrospectionException
 */
private static void visitProperties(Class<?> toInspect,Set<Class<?>> entitiesClass) throws IntrospectionException {
  BeanInfo beanInfo=Introspector.getBeanInfo(toInspect);
  PropertyDescriptor[] propertyDescriptors=beanInfo.getPropertyDescriptors();
  for (  PropertyDescriptor propertyDescriptor : propertyDescriptors) {
    Method readMethod=propertyDescriptor.getReadMethod();
    if (readMethod == null) {
      continue;
    }
    if (readMethod.isAnnotationPresent(OneToMany.class) || readMethod.isAnnotationPresent(OneToOne.class) || readMethod.isAnnotationPresent(ManyToMany.class)|| readMethod.isAnnotationPresent(ManyToOne.class)) {
      Class<?> propertyType=propertyDescriptor.getPropertyType();
      if (propertyType.isAnnotationPresent(Entity.class) && !entitiesClass.contains(propertyType)) {
        entitiesClass.add(propertyType);
        recurseSuperClass(propertyType,entitiesClass);
        visitProperties(propertyType,entitiesClass);
      }
 else       if (Collection.class.isAssignableFrom(propertyType)) {
        Class<?> entity=(Class<?>)((ParameterizedType)propertyDescriptor.getReadMethod().getGenericReturnType()).getActualTypeArguments()[0];
        if (entity.isAnnotationPresent(Entity.class) && !entitiesClass.contains(entity)) {
          entitiesClass.add(entity);
          recurseSuperClass(entity,entitiesClass);
          visitProperties(entity,entitiesClass);
        }
      }
 else       if (Map.class.isAssignableFrom(propertyType)) {
        Class<?> entity=(Class<?>)((ParameterizedType)propertyDescriptor.getReadMethod().getGenericReturnType()).getActualTypeArguments()[1];
        if (entity.isAnnotationPresent(Entity.class) && !entitiesClass.contains(entity)) {
          entitiesClass.add(entity);
          recurseSuperClass(entity,entitiesClass);
          visitProperties(entity,entitiesClass);
        }
      }
    }
  }
}
 

Example 48

From project mvel, under directory /src/test/java/org/mvel2/marshalling/.

Source file: MarshallingTest.java

  21 
vote

private ObjectConverter generateConverter(Class cls){
  BeanInfo beanInfo=null;
  try {
    beanInfo=Introspector.getBeanInfo(cls);
  }
 catch (  IntrospectionException e) {
    throw new RuntimeException(e);
  }
  PropertyDescriptor[] props=beanInfo.getPropertyDescriptors();
  List<ObjectConverterEntry> list=new ArrayList<ObjectConverterEntry>();
  for (int i=0, length=props.length; i < length; i++) {
    PropertyDescriptor prop=props[i];
    if ("class".equals(prop.getName())) {
      continue;
    }
    list.add(new ObjectConverterEntry(prop.getName(),prop.getReadMethod(),getType(prop.getPropertyType())));
  }
  return new ObjectConverter(cls,list.toArray(new ObjectConverterEntry[list.size()]));
}
 

Example 49

From project nuxeo-tycho-osgi, under directory /nuxeo-runtime/nuxeo-runtime-management/src/main/java/org/nuxeo/runtime/management/inspector/.

Source file: ModelMBeanIntrospector.java

  21 
vote

ModelMBeanInfo introspect(){
  if (managementInfo != null) {
    return managementInfo;
  }
  List<Class> ifaces=new ArrayList<Class>(1);
  if (clazz.isInterface()) {
    ifaces.add(clazz);
  }
 else {
    doCollectIfaces(ifaces,clazz);
  }
  for (  Class iface : ifaces) {
    BeanInfo beanInfo;
    try {
      beanInfo=Introspector.getBeanInfo(iface);
    }
 catch (    java.beans.IntrospectionException e) {
      throw ManagementRuntimeException.wrap("Cannot introspect " + iface,e);
    }
    doCollectAttributes(iface,beanInfo);
    doCollectConstructors(iface,beanInfo);
    doCollectOperations(iface,beanInfo);
    doCollectNotifications(iface,beanInfo);
  }
  managementInfo=new ModelMBeanInfoSupport(clazz.getCanonicalName(),"",attributesInfo.values().toArray(new ModelMBeanAttributeInfo[attributesInfo.size()]),constructorsInfo.values().toArray(new ModelMBeanConstructorInfo[constructorsInfo.size()]),operationsInfo.values().toArray(new ModelMBeanOperationInfo[operationsInfo.size()]),notificationsInfo.values().toArray(new ModelMBeanNotificationInfo[notificationsInfo.size()]));
  return managementInfo;
}
 

Example 50

From project openengsb-connector-promreport, under directory /src/main/java/org/openengsb/connector/promreport/internal/.

Source file: DefaultEventTransformator.java

  21 
vote

private List<Data.Attribute> getData(Event event){
  List<Data.Attribute> data=new ArrayList<Data.Attribute>();
  BeanInfo beanInfo;
  try {
    beanInfo=Introspector.getBeanInfo(event.getClass());
    PropertyDescriptor[] propertyDescriptors=beanInfo.getPropertyDescriptors();
    for (    PropertyDescriptor p : propertyDescriptors) {
      if (!p.getName().equals("processId") && !p.getName().equals("name") && !p.getName().equals("type")) {
        try {
          Data.Attribute att=new Data.Attribute();
          att.setName(p.getName());
          Method readMethod=p.getReadMethod();
          if (readMethod != null) {
            att.setValue(String.valueOf(readMethod.invoke(event)));
          }
          data.add(att);
        }
 catch (        IllegalAccessException e) {
          LOGGER.warn("An attribute couldn't be read",e);
        }
catch (        InvocationTargetException e) {
          LOGGER.warn("Underlying Method throws an exception.",e);
        }
      }
    }
  }
 catch (  IntrospectionException e) {
    LOGGER.warn("An exception occurs during introspection. No attribute was set.",e);
  }
  return data;
}
 

Example 51

From project plugin-WoT-staging, under directory /src/plugins/WebOfTrust/introduction/captcha/kaptcha/jhlabs/image/.

Source file: TransitionFilter.java

  21 
vote

/** 
 * Construct a TransitionFilter.
 * @param filter the filter to use
 * @param property the filter property which is changed over the transition
 * @param minValue the start value for the filter property
 * @param maxValue the end value for the filter property
 */
public TransitionFilter(BufferedImageOp filter,String property,float minValue,float maxValue){
  this.filter=filter;
  this.property=property;
  this.minValue=minValue;
  this.maxValue=maxValue;
  try {
    BeanInfo info=Introspector.getBeanInfo(filter.getClass());
    PropertyDescriptor[] pds=info.getPropertyDescriptors();
    for (int i=0; i < pds.length; i++) {
      PropertyDescriptor pd=pds[i];
      if (property.equals(pd.getName())) {
        method=pd.getWriteMethod();
        break;
      }
    }
    if (method == null)     throw new IllegalArgumentException("No such property in object: " + property);
  }
 catch (  IntrospectionException e) {
    throw new IllegalArgumentException(e.toString());
  }
}
 

Example 52

From project Possom, under directory /generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/.

Source file: JsonDataModelDirective.java

  21 
vote

private Object getDataModelInclude(final DataModel datamodel,final String include) throws IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  Object dataObject=datamodel;
  for (int firstDot=0; -1 != firstDot; firstDot=include.indexOf('.',firstDot + 1)) {
    final int secondDot=include.indexOf('.',firstDot + 1);
    final String beanName=include.substring(firstDot,-1 != secondDot ? secondDot : include.length());
    final BeanInfo beanInfo=Introspector.getBeanInfo(dataObject.getClass());
    for (    PropertyDescriptor prop : beanInfo.getPropertyDescriptors()) {
      if (beanName.equals(prop.getName())) {
        dataObject=prop.getReadMethod().invoke(dataObject);
        break;
      }
    }
  }
  return dataObject;
}
 

Example 53

From project querydsl, under directory /querydsl-core/src/main/java/com/mysema/util/.

Source file: BeanMap.java

  21 
vote

private void initialise(){
  if (getBean() == null) {
    return;
  }
  Class<?> beanClass=getBean().getClass();
  try {
    BeanInfo beanInfo=Introspector.getBeanInfo(beanClass);
    PropertyDescriptor[] propertyDescriptors=beanInfo.getPropertyDescriptors();
    if (propertyDescriptors != null) {
      for (int i=0; i < propertyDescriptors.length; i++) {
        PropertyDescriptor propertyDescriptor=propertyDescriptors[i];
        if (propertyDescriptor != null) {
          String name=propertyDescriptor.getName();
          Method readMethod=propertyDescriptor.getReadMethod();
          Method writeMethod=propertyDescriptor.getWriteMethod();
          Class<?> aType=propertyDescriptor.getPropertyType();
          if (readMethod != null) {
            readMethods.put(name,readMethod);
          }
          if (writeMethods != null) {
            writeMethods.put(name,writeMethod);
          }
          types.put(name,aType);
        }
      }
    }
  }
 catch (  IntrospectionException e) {
  }
}
 

Example 54

From project rabbitmq-java-client, under directory /src/com/rabbitmq/tools/json/.

Source file: JSONUtil.java

  21 
vote

/** 
 * Uses reflection to fill public fields and optionally Bean properties of the target object from the source Map.
 */
public static Object fill(Object target,Map<String,Object> source,boolean useProperties) throws IntrospectionException, IllegalAccessException, InvocationTargetException {
  if (useProperties) {
    BeanInfo info=Introspector.getBeanInfo(target.getClass());
    PropertyDescriptor[] props=info.getPropertyDescriptors();
    for (int i=0; i < props.length; ++i) {
      PropertyDescriptor prop=props[i];
      String name=prop.getName();
      Method setter=prop.getWriteMethod();
      if (setter != null && !Modifier.isStatic(setter.getModifiers())) {
        setter.invoke(target,new Object[]{source.get(name)});
      }
    }
  }
  Field[] ff=target.getClass().getDeclaredFields();
  for (int i=0; i < ff.length; ++i) {
    Field field=ff[i];
    int fieldMod=field.getModifiers();
    if (Modifier.isPublic(fieldMod) && !(Modifier.isFinal(fieldMod) || Modifier.isStatic(fieldMod))) {
      try {
        field.set(target,source.get(field.getName()));
      }
 catch (      IllegalArgumentException iae) {
      }
    }
  }
  return target;
}
 

Example 55

From project shiro, under directory /support/faces/src/main/java/org/apache/shiro/web/faces/tags/.

Source file: PrincipalTag.java

  21 
vote

private String getPrincipalProperty(Object principal,String property) throws IOException {
  String strValue=null;
  try {
    BeanInfo bi=Introspector.getBeanInfo(principal.getClass());
    boolean foundProperty=false;
    for (    PropertyDescriptor pd : bi.getPropertyDescriptors()) {
      if (pd.getName().equals(property) && (Modifier.isPublic(pd.getReadMethod().getModifiers()))) {
        Object value=null;
        try {
          pd.getReadMethod().setAccessible(true);
          value=pd.getReadMethod().invoke(principal,(Object[])null);
        }
  finally {
          pd.getReadMethod().setAccessible(false);
        }
        strValue=String.valueOf(value);
        foundProperty=true;
        break;
      }
    }
    if (!foundProperty) {
      final String message="Property [" + property + "] not found in principal of type ["+ principal.getClass().getName()+ "]";
      if (log.isErrorEnabled()) {
        log.error(message);
      }
      throw new IOException(message);
    }
  }
 catch (  Exception e) {
    final String message="Error reading property [" + property + "] from principal of type ["+ principal.getClass().getName()+ "]";
    if (log.isErrorEnabled()) {
      log.error(message,e);
    }
    throw new IOException(message);
  }
  return strValue;
}
 

Example 56

From project socialpm, under directory /gwt/src/main/java/com/ocpsoft/socialpm/gwt/server/util/.

Source file: HibernateDetachUtility.java

  21 
vote

private static void nullOutFieldsByAccessors(Object value,Map<Integer,Object> checkedObjects,Map<Integer,List<Object>> checkedObjectCollisionMap,int depth,SerializationType serializationType) throws Exception {
  BeanInfo bi=Introspector.getBeanInfo(value.getClass(),Object.class);
  PropertyDescriptor[] pds=bi.getPropertyDescriptors();
  for (  PropertyDescriptor pd : pds) {
    Object propertyValue=null;
    try {
      propertyValue=pd.getReadMethod().invoke(value);
    }
 catch (    Throwable lie) {
      if (log.isDebugEnabled()) {
        log.debug("Couldn't load: " + pd.getName() + " off of "+ value.getClass().getSimpleName(),lie);
      }
    }
    if (!Hibernate.isInitialized(propertyValue)) {
      try {
        if (log.isDebugEnabled()) {
          log.debug("Nulling out: " + pd.getName() + " off of "+ value.getClass().getSimpleName());
        }
        Method writeMethod=pd.getWriteMethod();
        if ((writeMethod != null) && (writeMethod.getAnnotation(XmlTransient.class) == null)) {
          pd.getWriteMethod().invoke(value,new Object[]{null});
        }
 else {
          nullOutField(value,pd.getName());
        }
      }
 catch (      Exception lie) {
        log.debug("Couldn't null out: " + pd.getName() + " off of "+ value.getClass().getSimpleName()+ " trying field access",lie);
        nullOutField(value,pd.getName());
      }
    }
 else {
      if ((propertyValue instanceof Collection) || ((propertyValue != null) && validType(propertyValue))) {
        nullOutUninitializedFields(propertyValue,checkedObjects,checkedObjectCollisionMap,depth + 1,serializationType);
      }
    }
  }
}
 

Example 57

From project tiles-request, under directory /tiles-request-api/src/main/java/org/apache/tiles/request/reflect/.

Source file: ClassUtil.java

  21 
vote

/** 
 * Collects bean infos from a class and filling a list.
 * @param clazz The class to be inspected.
 * @param name2descriptor The map in the form: name of the property ->descriptor.
 */
public static void collectBeanInfo(Class<?> clazz,Map<String,PropertyDescriptor> name2descriptor){
  Logger log=LoggerFactory.getLogger(ClassUtil.class);
  BeanInfo info=null;
  try {
    info=Introspector.getBeanInfo(clazz);
  }
 catch (  Exception ex) {
    if (log.isDebugEnabled()) {
      log.debug("Cannot inspect class " + clazz,ex);
    }
  }
  if (info == null) {
    return;
  }
  for (  PropertyDescriptor pd : info.getPropertyDescriptors()) {
    pd.setValue("type",pd.getPropertyType());
    pd.setValue("resolvableAtDesignTime",Boolean.TRUE);
    name2descriptor.put(pd.getName(),pd);
  }
}
 

Example 58

From project vaadin-lazyquerycontainer, under directory /vaadin-lazyquerycontainer/src/main/java/org/vaadin/addons/lazyquerycontainer/.

Source file: AbstractBeanQuery.java

  21 
vote

/** 
 * Constructs new item based on QueryDefinition.
 * @return new item.
 */
public final Item constructItem(){
  try {
    T bean=constructBean();
    BeanInfo info=Introspector.getBeanInfo(bean.getClass());
    for (    PropertyDescriptor pd : info.getPropertyDescriptors()) {
      for (      Object propertyId : queryDefinition.getPropertyIds()) {
        if (pd.getName().equals(propertyId)) {
          pd.getWriteMethod().invoke(bean,queryDefinition.getPropertyDefaultValue(propertyId));
        }
      }
    }
    return toItem(bean);
  }
 catch (  Exception e) {
    throw new RuntimeException("Error in bean construction or property population with default values.",e);
  }
}
 

Example 59

From project Weave, under directory /WeaveServices/src/weave/utils/.

Source file: RUtils.java

  21 
vote

/** 
 * Convert from R expression to Java Bean. No real checking. 
 */
private static Object asBean(REXP rexp,Class<?> type){
  try {
    BeanInfo beanInfo=Introspector.getBeanInfo(type);
    PropertyDescriptor[] props=beanInfo.getPropertyDescriptors();
    Map<String,PropertyDescriptor> map=new HashMap<String,PropertyDescriptor>(props.length * 2);
    for (    PropertyDescriptor prop : props) {
      map.put(prop.getName(),prop);
    }
    RList rlist=rexp.asList();
    Object obj=type.newInstance();
    if (rlist.isNamed()) {
      for (int i=0; i < rlist.size(); ++i) {
        String name=rlist.names.get(i).toString();
        PropertyDescriptor prop=map.get(name);
        Method method=prop.getWriteMethod();
        REXP value=(REXP)rlist.get(i);
        Object val=rexp2jobj(value,prop.getPropertyType());
        method.invoke(obj,val);
      }
    }
    return obj;
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 60

From project xwiki-commons, under directory /xwiki-commons-core/xwiki-commons-properties/src/main/java/org/xwiki/properties/internal/.

Source file: DefaultBeanDescriptor.java

  21 
vote

/** 
 * Extract informations form the bean.
 */
protected void extractBeanDescriptor(){
  Object defaultInstance=null;
  try {
    defaultInstance=getBeanClass().newInstance();
  }
 catch (  Exception e) {
    LOGGER.error("Failed to create a new default instance for class " + this.beanClass + ". The BeanDescriptor will not contains any default value information.",e);
  }
  try {
    for (Class<?> currentClass=this.beanClass; currentClass != null; currentClass=currentClass.getSuperclass()) {
      Field[] fields=currentClass.getFields();
      for (      Field field : fields) {
        extractPropertyDescriptor(field,defaultInstance);
      }
    }
    BeanInfo beanInfo=Introspector.getBeanInfo(this.beanClass);
    java.beans.PropertyDescriptor[] propertyDescriptors=beanInfo.getPropertyDescriptors();
    if (propertyDescriptors != null) {
      for (      java.beans.PropertyDescriptor propertyDescriptor : propertyDescriptors) {
        if (propertyDescriptor != null) {
          extractPropertyDescriptor(propertyDescriptor,defaultInstance);
        }
      }
    }
  }
 catch (  Exception e) {
    LOGGER.error("Failed to load bean descriptor for class " + this.beanClass,e);
  }
}
 

Example 61

From project jCAE, under directory /jcae/mesh-algos/src/org/jcae/netbeans/.

Source file: Utilities.java

  19 
vote

public static <T>boolean showEditBeanDialog(T bean){
  try {
    BeanNode<T> bn=new BeanNode<T>(bean){
      @Override protected void createProperties(      T bean,      BeanInfo info){
        super.createProperties(bean,info);
        getSheet().get(Sheet.PROPERTIES).remove("class");
      }
    }
;
    PropertySheet ps=new PropertySheet();
    ps.setNodes(new Node[]{bn});
    String title=Introspector.getBeanInfo(bean.getClass()).getBeanDescriptor().getDisplayName();
    DialogDescriptor dd=new DialogDescriptor(ps,title);
    DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
    return dd.getValue() == NotifyDescriptor.OK_OPTION;
  }
 catch (  IntrospectionException e) {
    org.openide.ErrorManager.getDefault().notify(e);
    return false;
  }
}
 

Example 62

From project jo4neo, under directory /tags/jo4neo-0.2/main/java/jo4neo/.

Source file: TypeWrapper.java

  19 
vote

protected static BeanInfo beanInfo(Class<?> c){
  try {
    return Introspector.getBeanInfo(c);
  }
 catch (  IntrospectionException e1) {
    e1.printStackTrace();
  }
  return null;
}