Java Examples for java.beans.IntrospectionException

The following java examples will help you to understand the usage of java.beans.IntrospectionException. These source code samples are taken from different open source projects.

Example 1
Project: openmap-master  File: SimpleBeanContainerBeanInfo.java View source code
public PropertyDescriptor[] getPropertyDescriptors() {
    ArrayList<PropertyDescriptor> list = new ArrayList<PropertyDescriptor>(8);
    PropertyDescriptor[] pds = super.getPropertyDescriptors();
    list.addAll(Arrays.asList(pds));
    try {
        list.add(new PropertyDescriptor("widthInNM", SimpleBeanContainer.class));
        list.add(new PropertyDescriptor("heightInNM", SimpleBeanContainer.class));
        PropertyDescriptor pd = new PropertyDescriptor("layoutClass", SimpleBeanContainer.class);
        pd.setPropertyEditorClass(LayoutClassEditor.class);
        list.add(pd);
        pd = new PropertyDescriptor("layoutManager", SimpleBeanContainer.class, "getLayout", "setLayout");
        // since layoutManager property is itself a bean
        // (of type BeanLayoutManager), use the
        // general purpose BeanLayoutEditor class provided in the
        // tools.beanbox
        // package as the editor class of this bean property.
        pd.setPropertyEditorClass(BeanLayoutEditor.class);
        list.add(pd);
    } catch (IntrospectionException e) {
        e.printStackTrace();
    }
    return list.toArray(new PropertyDescriptor[list.size()]);
}
Example 2
Project: sitebricks-master  File: ConcurrentPropertyCache.java View source code
public boolean exists(String property, Class<?> anObjectClass) {
    Map<String, String> properties = cache.get(anObjectClass);
    //cache bean properties if needed
    if (null == properties) {
        PropertyDescriptor[] propertyDescriptors;
        try {
            propertyDescriptors = Introspector.getBeanInfo(anObjectClass).getPropertyDescriptors();
        } catch (IntrospectionException e) {
            throw new IllegalArgumentException();
        }
        properties = new LinkedHashMap<String, String>();
        for (PropertyDescriptor descriptor : propertyDescriptors) {
            //apply labels here as needed
            properties.put(descriptor.getName(), descriptor.getName());
        }
        cache.putIfAbsent(anObjectClass, properties);
    }
    return properties.containsKey(property);
}
Example 3
Project: jeboorker-master  File: ExtendedPropertyDescriptor.java View source code
public static ExtendedPropertyDescriptor newPropertyDescriptor(String propertyName, Class beanClass) throws IntrospectionException {
    // the same initialization phase as in the PropertyDescriptor
    Method readMethod = BeanUtils.getReadMethod(beanClass, propertyName);
    Method writeMethod = null;
    if (readMethod == null) {
        throw new IntrospectionException("No getter for property " + propertyName + " in class " + beanClass.getName());
    }
    writeMethod = BeanUtils.getWriteMethod(beanClass, propertyName, readMethod.getReturnType());
    return new ExtendedPropertyDescriptor(propertyName, readMethod, writeMethod);
}
Example 4
Project: bigtable-sql-master  File: SquirrelPreferencesBeanInfo.java View source code
/**
	 * See http://tinyurl.com/63no6t for discussion of the proper thread-safe way to implement
	 * getPropertyDescriptors().
	 * 
	 * @see java.beans.SimpleBeanInfo#getPropertyDescriptors()
	 */
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
    try {
        PropertyDescriptor[] result = new PropertyDescriptor[] { new PropertyDescriptor(SESSION_PROPERTIES, SquirrelPreferences.class, "getSessionProperties", "setSessionProperties"), new PropertyDescriptor(MAIN_FRAME_STATE, SquirrelPreferences.class, "getMainFrameWindowState", "setMainFrameWindowState"), new PropertyDescriptor(SHOW_CONTENTS_WHEN_DRAGGING, SquirrelPreferences.class, "getShowContentsWhenDragging", "setShowContentsWhenDragging"), new PropertyDescriptor(TABBED_STYLE, SquirrelPreferences.class, "getTabbedStyle", "setTabbedStyle"), new PropertyDescriptor(USE_SCROLLABLE_TABBED_PANES_FOR_SESSION_TABS, SquirrelPreferences.class, "getUseScrollableTabbedPanesForSessionTabs", "setUseScrollableTabbedPanesForSessionTabs"), new PropertyDescriptor(SHOW_TABBED_STYLE_HINT, SquirrelPreferences.class, "getShowTabbedStyleHint", "setShowTabbedStyleHint"), new PropertyDescriptor(LOGIN_TIMEOUT, SquirrelPreferences.class, "getLoginTimeout", "setLoginTimeout"), new PropertyDescriptor(LARGE_SCRIPT_STMT_COUNT, SquirrelPreferences.class, "getLargeScriptStmtCount", "setLargeScriptStmtCount"), new PropertyDescriptor(JDBC_DEBUG_TYPE, SquirrelPreferences.class, "getJdbcDebugType", "setJdbcDebugType"), new PropertyDescriptor(SHOW_MAIN_STATUS_BAR, SquirrelPreferences.class, "getShowMainStatusBar", "setShowMainStatusBar"), new PropertyDescriptor(SHOW_MAIN_TOOL_BAR, SquirrelPreferences.class, "getShowMainToolBar", "setShowMainToolBar"), new PropertyDescriptor(SHOW_ALIASES_TOOL_BAR, SquirrelPreferences.class, "getShowAliasesToolBar", "setShowAliasesToolBar"), new PropertyDescriptor(SHOW_DRIVERS_TOOL_BAR, SquirrelPreferences.class, "getShowDriversToolBar", "setShowDriversToolBar"), new PropertyDescriptor(SHOW_TOOLTIPS, SquirrelPreferences.class, "getShowToolTips", "setShowToolTips"), new PropertyDescriptor(SCROLLABLE_TABBED_PANES, SquirrelPreferences.class, "getUseScrollableTabbedPanes", "setUseScrollableTabbedPanes"), new IndexedPropertyDescriptor(ACTION_KEYS, SquirrelPreferences.class, "getActionKeys", "setActionKeys", "getActionKeys", "setActionKeys"), new PropertyDescriptor(PROXY, SquirrelPreferences.class, "getProxySettings", "setProxySettings"), new PropertyDescriptor(UPDATE, SquirrelPreferences.class, "getUpdateSettings", "setUpdateSettings"), new PropertyDescriptor(SHOW_LOADED_DRIVERS_ONLY, SquirrelPreferences.class, "getShowLoadedDriversOnly", "setShowLoadedDriversOnly"), new PropertyDescriptor(MAXIMIMIZE_SESSION_SHEET_ON_OPEN, SquirrelPreferences.class, "getMaximizeSessionSheetOnOpen", "setMaximizeSessionSheetOnOpen"), new PropertyDescriptor(SHOW_COLOR_ICONS_IN_TOOLBAR, SquirrelPreferences.class, "getShowColoriconsInToolbar", "setShowColoriconsInToolbar"), new PropertyDescriptor(FIRST_RUN, SquirrelPreferences.class, "isFirstRun", "setFirstRun"), new PropertyDescriptor(CONFIRM_SESSION_CLOSE, SquirrelPreferences.class, "getConfirmSessionClose", "setConfirmSessionClose"), new IndexedPropertyDescriptor(PLUGIN_STATUSES, SquirrelPreferences.class, "getPluginStatuses", "setPluginStatuses", "getPluginStatus", "setPluginStatus"), new PropertyDescriptor(NEW_SESSION_VIEW, SquirrelPreferences.class, "getNewSessionView", "setNewSessionView"), new PropertyDescriptor(FILE_OPEN_IN_PREVIOUS_DIR, SquirrelPreferences.class, "isFileOpenInPreviousDir", "setFileOpenInPreviousDir"), new PropertyDescriptor(FILE_OPEN_IN_SPECIFIED_DIR, SquirrelPreferences.class, "isFileOpenInSpecifiedDir", "setFileOpenInSpecifiedDir"), new PropertyDescriptor(FILE_SPECIFIED_DIR, SquirrelPreferences.class, "getFileSpecifiedDir", "setFileSpecifiedDir"), new PropertyDescriptor(FILE_PREVIOUS_DIR, SquirrelPreferences.class, "getFilePreviousDir", "setFilePreviousDir"), new PropertyDescriptor(SHOW_PLUGIN_FILES_IN_SPLASH_SCREEN, SquirrelPreferences.class, "getShowPluginFilesInSplashScreen", "setShowPluginFilesInSplashScreen"), new PropertyDescriptor(WARN_JRE_JDBC_MISMATCH, SquirrelPreferences.class, "getWarnJreJdbcMismatch", "setWarnJreJdbcMismatch"), new PropertyDescriptor(WARN_FOR_UNSAVED_FILE_EDITS, SquirrelPreferences.class, "getWarnForUnsavedFileEdits", "setWarnForUnsavedFileEdits"), new PropertyDescriptor(WARN_FOR_UNSAVED_BUFFER_EDITS, SquirrelPreferences.class, "getWarnForUnsavedBufferEdits", "setWarnForUnsavedBufferEdits"), new PropertyDescriptor(SHOW_SESSION_STARTUP_TIME_HINT, SquirrelPreferences.class, "getShowSessionStartupTimeHint", "setShowSessionStartupTimeHint"), new PropertyDescriptor(SHOW_DEBUG_LOG_MESSAGES, SquirrelPreferences.class, "getShowDebugLogMessage", "setShowDebugLogMessages"), new PropertyDescriptor(SHOW_INFO_LOG_MESSAGES, SquirrelPreferences.class, "getShowInfoLogMessages", "setShowInfoLogMessages"), new PropertyDescriptor(SHOW_ERROR_LOG_MESSAGES, SquirrelPreferences.class, "getShowErrorLogMessages", "setShowErrorLogMessages"), new PropertyDescriptor(SAVE_PREFERENCES_IMMEDIATELY, SquirrelPreferences.class, "getSavePreferencesImmediately", "setSavePreferencesImmediately"), new PropertyDescriptor(SELECT_ON_RIGHT_MOUSE_CLICK, SquirrelPreferences.class, "getSelectOnRightMouseClick", "setSelectOnRightMouseClick"), new PropertyDescriptor(SHOW_PLEASE_WAIT_DIALOG, SquirrelPreferences.class, "getShowPleaseWaitDialog", "setShowPleaseWaitDialog"), new PropertyDescriptor(PREFERRED_LOCALE, SquirrelPreferences.class, "getPreferredLocale", "setPreferredLocale") };
        return result;
    } catch (IntrospectionException e) {
        throw new Error(e);
    }
}
Example 5
Project: alien4cloud-master  File: ElasticSearchMapper.java View source code
public static ElasticSearchMapper getInstance() {
    ElasticSearchMapper elasticSearchMapper = new ElasticSearchMapper();
    SimpleModule module = new SimpleModule("PropDeser", new Version(1, 0, 0, null, null, null));
    try {
        module.addDeserializer(PropertyConstraint.class, new PropertyConstraintDeserializer());
    } catch (ClassNotFoundExceptionIOException | IntrospectionException |  e) {
        log.warn("The property constraint deserialialisation failed");
    }
    elasticSearchMapper.registerModule(module);
    return elasticSearchMapper;
}
Example 6
Project: geotools-old-master  File: LinePointAbstractValidationBeanInfo.java View source code
/**
     * Implementation of getPropertyDescriptors.
     *
     *
     * @see java.beans.BeanInfo#getPropertyDescriptors()
     */
public PropertyDescriptor[] getPropertyDescriptors() {
    PropertyDescriptor[] pd2 = super.getPropertyDescriptors();
    ResourceBundle resourceBundle = getResourceBundle(LinePointAbstractValidation.class);
    if (pd2 == null) {
        pd2 = new PropertyDescriptor[0];
    }
    PropertyDescriptor[] pd = new PropertyDescriptor[pd2.length + 2];
    int i = 0;
    for (; i < pd2.length; i++) pd[i] = pd2[i];
    try {
        pd[i] = createPropertyDescriptor("lineTypeRef", LinePointAbstractValidation.class, resourceBundle);
        pd[i].setExpert(false);
        pd[i + 1] = createPropertyDescriptor("restrictedPointTypeRef", LinePointAbstractValidation.class, resourceBundle);
        pd[i + 1].setExpert(false);
    } catch (IntrospectionException e) {
        pd = pd2;
        e.printStackTrace();
    }
    return pd;
}
Example 7
Project: visuwall-master  File: ELSizeTagBeanInfo.java View source code
public PropertyDescriptor[] getPropertyDescriptors() {
    ArrayList proplist = new ArrayList();
    try {
        proplist.add(new PropertyDescriptor("collection", ELSizeTag.class, null, "setCollectionExpr"));
    } catch (IntrospectionException ex) {
    }
    try {
        proplist.add(new PropertyDescriptor("id", ELSizeTag.class, null, "setIdExpr"));
    } catch (IntrospectionException ex) {
    }
    try {
        proplist.add(new PropertyDescriptor("name", ELSizeTag.class, null, "setNameExpr"));
    } catch (IntrospectionException ex) {
    }
    try {
        proplist.add(new PropertyDescriptor("property", ELSizeTag.class, null, "setPropertyExpr"));
    } catch (IntrospectionException ex) {
    }
    try {
        proplist.add(new PropertyDescriptor("scope", ELSizeTag.class, null, "setScopeExpr"));
    } catch (IntrospectionException ex) {
    }
    PropertyDescriptor[] result = new PropertyDescriptor[proplist.size()];
    return ((PropertyDescriptor[]) proplist.toArray(result));
}
Example 8
Project: violetumleditor-master  File: PropertyEditorWidget.java View source code
private void populateWidget() {
    WContainerWidget container = new WContainerWidget();
    WVBoxLayout vbox = new WVBoxLayout();
    try {
        Introspector.flushFromCaches(bean.getClass());
        BeanInfo info = Introspector.getBeanInfo(bean.getClass());
        PropertyDescriptor[] descriptors = (PropertyDescriptor[]) info.getPropertyDescriptors().clone();
        Arrays.sort(descriptors, new Comparator<PropertyDescriptor>() {

            public int compare(PropertyDescriptor d1, PropertyDescriptor d2) {
                Integer p1 = (Integer) d1.getValue("priority");
                Integer p2 = (Integer) d2.getValue("priority");
                if (p1 == null && p2 == null)
                    return 0;
                if (p1 == null)
                    return 1;
                if (p2 == null)
                    return -1;
                return p1.intValue() - p2.intValue();
            }
        });
        ResourceBundle rs = ResourceBundle.getBundle(ResourceBundleConstant.NODE_AND_EDGE_STRINGS, Locale.getDefault());
        for (int i = 0; i < descriptors.length; i++) {
            AbstractPropertyEditorWidget<?> editor = getEditorWidget(bean, descriptors[i]);
            if (editor != null) {
                vbox.addWidget(editor);
                this.isSomethingToEdit = true;
            }
        }
    } catch (IntrospectionException exception) {
        exception.printStackTrace();
    }
    container.setLayout(vbox);
    setImplementation(container);
}
Example 9
Project: openjdk8-jdk-master  File: Test5102804.java View source code
private static Reference getReference() {
    try {
        ClassLoader loader = new Loader();
        Class type = Class.forName(BEAN_NAME, true, loader);
        if (!type.getClassLoader().equals(loader)) {
            throw new Error("Wrong class loader");
        }
        BeanInfo info = Introspector.getBeanInfo(type);
        if (0 != info.getDefaultPropertyIndex()) {
            throw new Error("Wrong bean info found");
        }
        return new WeakReference<Class>(type);
    } catch (IntrospectionException exception) {
        throw new Error("Introspection Error", exception);
    } catch (ClassNotFoundException exception) {
        throw new Error("Class Not Found", exception);
    }
}
Example 10
Project: openjdk-master  File: Test5102804.java View source code
private static Reference getReference() {
    try {
        ClassLoader loader = new Loader();
        Class type = Class.forName(BEAN_NAME, true, loader);
        if (!type.getClassLoader().equals(loader)) {
            throw new Error("Wrong class loader");
        }
        BeanInfo info = Introspector.getBeanInfo(type);
        if (0 != info.getDefaultPropertyIndex()) {
            throw new Error("Wrong bean info found");
        }
        return new WeakReference<Class>(type);
    } catch (IntrospectionException exception) {
        throw new Error("Introspection Error", exception);
    } catch (ClassNotFoundException exception) {
        throw new Error("Class Not Found", exception);
    }
}
Example 11
Project: jdk7u-jdk-master  File: Test5102804.java View source code
private static Reference getReference() {
    try {
        ClassLoader loader = new Loader();
        Class type = Class.forName(BEAN_NAME, true, loader);
        if (!type.getClassLoader().equals(loader)) {
            throw new Error("Wrong class loader");
        }
        BeanInfo info = Introspector.getBeanInfo(type);
        if (0 != info.getDefaultPropertyIndex()) {
            throw new Error("Wrong bean info found");
        }
        return new WeakReference<Class>(type);
    } catch (IntrospectionException exception) {
        throw new Error("Introspection Error", exception);
    } catch (ClassNotFoundException exception) {
        throw new Error("Class Not Found", exception);
    }
}
Example 12
Project: tapestry-model-master  File: TynamoDecorator.java View source code
void decorateFromReadMethod(final TynamoPropertyDescriptor tynamoPropertyDescriptor) {
    try {
        PropertyDescriptor[] descriptors = Introspector.getBeanInfo(tynamoPropertyDescriptor.getBeanType()).getPropertyDescriptors();
        PropertyDescriptor beanPropDescriptor = F.flow(descriptors).filter(new Predicate<PropertyDescriptor>() {

            public boolean accept(PropertyDescriptor descriptor) {
                return descriptor.getName().equals(tynamoPropertyDescriptor.getName());
            }
        }).first();
        Method readMethod = beanPropDescriptor.getReadMethod();
        if (readMethod != null) {
            decorateFromAnnotations(tynamoPropertyDescriptor, readMethod.getAnnotations());
        } else {
            LOGGER.error("There is no readMethod for: " + tynamoPropertyDescriptor.getBeanType().getSimpleName() + "." + tynamoPropertyDescriptor.getName());
        }
    } catch (IntrospectionException ex) {
        LOGGER.error("Could not decorate from readMethod: " + tynamoPropertyDescriptor.getBeanType().getSimpleName() + "." + tynamoPropertyDescriptor.getName());
    }
}
Example 13
Project: dk-master  File: BeanMapUtils.java View source code
/**
	 * @Description: 将对象转为Map
	 * @Author Yang Cheng
	 * @Date: Feb 9, 2012 1:56:20 AM
	 * @param <T>
	 * @param bean
	 * @return
	 * @return Map<String,String>
	 */
public static <T> Map<String, String> beanToMap(T bean) {
    Class<? extends Object> type = bean.getClass();
    Map<String, String> returnMap = new HashMap<String, String>();
    try {
        BeanInfo beanInfo = Introspector.getBeanInfo(type);
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor descriptor : propertyDescriptors) {
            String propertyName = descriptor.getName();
            if (!propertyName.equals("class")) {
                Method readMethod = descriptor.getReadMethod();
                Object result = readMethod.invoke(bean, new Object[0]);
                returnMap.put(propertyName, result(result));
            }
        }
    } catch (IntrospectionException e) {
        log.error(e);
        throw new RuntimeException("分析类属性失败", e);
    } catch (IllegalAccessException e) {
        log.error(e);
        throw new RuntimeException("分析类属性失败", e);
    } catch (InvocationTargetException e) {
        log.error(e);
        throw new RuntimeException("分析类属性失败", e);
    }
    return returnMap;
}
Example 14
Project: ManagedRuntimeInitiative-master  File: Test4984912.java View source code
public PropertyDescriptor[] getPropertyDescriptors() {
    try {
        PropertyDescriptor pdProperty = new PropertyDescriptor("property", SimpleBean.class, "getProperty", "setProperty");
        PropertyDescriptor pdNullable = new PropertyDescriptor("nullable", SimpleBean.class, null, null);
        PropertyDescriptor pdIndexed = new IndexedPropertyDescriptor("indexed", SimpleBean.class, null, null, null, null);
        pdNullable.setValue("name", "value");
        return new PropertyDescriptor[] { pdProperty, pdNullable, pdIndexed };
    } catch (IntrospectionException exception) {
        throw new Error(exception);
    }
}
Example 15
Project: cloudtm-data-platform-master  File: SpatialFieldBridge.java View source code
private Double getCoordinateFromField(String coordinateField, Object value) {
    Class<?> clazz = value.getClass();
    try {
        Field latitude = clazz.getField(coordinateField);
        return (Double) latitude.get(value);
    } catch (NoSuchFieldException e) {
        try {
            PropertyDescriptor propertyDescriptor = new PropertyDescriptor(coordinateField, clazz, "get" + capitalize(coordinateField), null);
            Method latitudeGetter = propertyDescriptor.getReadMethod();
            if (latitudeGetter != null) {
                return (Double) latitudeGetter.invoke(value);
            } else {
                throw LOG.cannotReadFieldForClass(coordinateField, clazz.getName());
            }
        } catch (IllegalAccessException ex) {
            throw LOG.cannotReadFieldForClass(coordinateField, clazz.getName());
        } catch (InvocationTargetException ex) {
            throw LOG.cannotReadFieldForClass(coordinateField, clazz.getName());
        } catch (IntrospectionException ex) {
            throw LOG.cannotReadFieldForClass(coordinateField, clazz.getName());
        }
    } catch (IllegalAccessException e) {
        throw LOG.cannotReadFieldForClass(coordinateField, clazz.getName());
    }
}
Example 16
Project: hibernate-core-ogm-master  File: BeanInfoHelper.java View source code
public static void visitBeanInfo(Class beanClass, Class stopClass, BeanInfoDelegate delegate) {
    try {
        BeanInfo info = Introspector.getBeanInfo(beanClass, stopClass);
        try {
            delegate.processBeanInfo(info);
        } catch (RuntimeException e) {
            throw e;
        } catch (InvocationTargetException e) {
            throw new BeanIntrospectionException("Error delegating bean info use", e.getTargetException());
        } catch (Exception e) {
            throw new BeanIntrospectionException("Error delegating bean info use", e);
        } finally {
            Introspector.flushFromCaches(beanClass);
        }
    } catch (IntrospectionException e) {
        throw new BeanIntrospectionException("Unable to determine bean info from class [" + beanClass.getName() + "]", e);
    }
}
Example 17
Project: cdt-tests-runner-master  File: DebugUtil.java View source code
/**
	 * Prints the values of javabean properties to the console.
	 * This method is not recursive, it does not print nested properties.
	 * 
	 * Example of usage: 
	 * 
	 * IResource resource = ...;
	 * DebugUtil.printObjectProperties(resource);
	 * DebugUtil.printObjectProperties(resource.getResourceAttributes());
	 * @since 5.1
	 */
public static void printObjectProperties(Object obj) {
    try {
        System.out.println("Object: " + obj);
        BeanInfo info = Introspector.getBeanInfo(obj.getClass());
        for (PropertyDescriptor propertyDescriptor : info.getPropertyDescriptors()) {
            Method getter = propertyDescriptor.getReadMethod();
            try {
                System.out.println("  " + getter.getName() + "=" + getter.invoke(obj, new Object[0]));
            } catch (Exception e) {
            }
        }
    } catch (IntrospectionException e) {
    }
}
Example 18
Project: richfaces-master  File: FacesServiceBase.java View source code
protected void fillParameters(BaseFacesObjectDescriptor<T> descriptor, T component) {
    // get bean attributes for converter, put them into parameters.
    try {
        BeanInfo beanInfo = Introspector.getBeanInfo(component.getClass());
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
            String name = propertyDescriptor.getName();
            if (!HIDDEN_PROPERTIES.contains(name)) {
                try {
                    final Method readMethod = propertyDescriptor.getReadMethod();
                    if (readMethod == null) {
                        continue;
                    }
                    Object value = readMethod.invoke(component);
                    if (null != value) {
                        descriptor.addParameter(name, value);
                    }
                } catch (IllegalArgumentException e) {
                } catch (IllegalAccessException e) {
                } catch (InvocationTargetException e) {
                }
            }
        }
    } catch (IntrospectionException e) {
    }
}
Example 19
Project: cdt-master  File: DebugUtil.java View source code
/**
	 * Prints the values of javabean properties to the console.
	 * This method is not recursive, it does not print nested properties.
	 * 
	 * Example of usage: 
	 * 
	 * IResource resource = ...;
	 * DebugUtil.printObjectProperties(resource);
	 * DebugUtil.printObjectProperties(resource.getResourceAttributes());
	 * @since 5.1
	 */
public static void printObjectProperties(Object obj) {
    try {
        System.out.println("Object: " + obj);
        BeanInfo info = Introspector.getBeanInfo(obj.getClass());
        for (PropertyDescriptor propertyDescriptor : info.getPropertyDescriptors()) {
            Method getter = propertyDescriptor.getReadMethod();
            try {
                System.out.println("  " + getter.getName() + "=" + getter.invoke(obj, new Object[0]));
            } catch (Exception e) {
            }
        }
    } catch (IntrospectionException e) {
    }
}
Example 20
Project: clinic-softacad-master  File: BeanInfoHelper.java View source code
public static void visitBeanInfo(Class beanClass, Class stopClass, BeanInfoDelegate delegate) {
    try {
        BeanInfo info = Introspector.getBeanInfo(beanClass, stopClass);
        try {
            delegate.processBeanInfo(info);
        } catch (RuntimeException e) {
            throw e;
        } catch (InvocationTargetException e) {
            throw new BeanIntrospectionException("Error delegating bean info use", e.getTargetException());
        } catch (Exception e) {
            throw new BeanIntrospectionException("Error delegating bean info use", e);
        } finally {
            Introspector.flushFromCaches(beanClass);
        }
    } catch (IntrospectionException e) {
        throw new BeanIntrospectionException("Unable to determine bean info from class [" + beanClass.getName() + "]", e);
    }
}
Example 21
Project: JBossAS51-master  File: Server.java View source code
public static AttributeList setAttributes(String name, HashMap attributes) throws JMException {
    MBeanServer server = getMBeanServer();
    ObjectName objName = new ObjectName(name);
    MBeanInfo info = server.getMBeanInfo(objName);
    MBeanAttributeInfo[] attributesInfo = info.getAttributes();
    AttributeList newAttributes = new AttributeList();
    for (int a = 0; a < attributesInfo.length; a++) {
        MBeanAttributeInfo attrInfo = attributesInfo[a];
        String attrName = attrInfo.getName();
        if (attributes.containsKey(attrName) == false)
            continue;
        String value = (String) attributes.get(attrName);
        if (value.equals("null") && server.getAttribute(objName, attrName) == null) {
            log.trace("ignoring 'null' for " + attrName);
            continue;
        }
        String attrType = attrInfo.getType();
        Attribute attr = null;
        try {
            Object realValue = PropertyEditors.convertValue(value, attrType);
            attr = new Attribute(attrName, realValue);
        } catch (ClassNotFoundException e) {
            String s = (attr != null) ? attr.getName() : attrType;
            log.trace("Failed to load class for attribute: " + s, e);
            throw new ReflectionException(e, "Failed to load class for attribute: " + s);
        } catch (IntrospectionException e) {
            log.trace("Skipped setting attribute: " + attrName + ", cannot find PropertyEditor for type: " + attrType);
            continue;
        }
        server.setAttribute(objName, attr);
        newAttributes.add(attr);
    }
    return newAttributes;
}
Example 22
Project: JBossAS_5_1_EDG-master  File: Server.java View source code
public static AttributeList setAttributes(String name, HashMap attributes) throws JMException {
    MBeanServer server = getMBeanServer();
    ObjectName objName = new ObjectName(name);
    MBeanInfo info = server.getMBeanInfo(objName);
    MBeanAttributeInfo[] attributesInfo = info.getAttributes();
    AttributeList newAttributes = new AttributeList();
    for (int a = 0; a < attributesInfo.length; a++) {
        MBeanAttributeInfo attrInfo = attributesInfo[a];
        String attrName = attrInfo.getName();
        if (attributes.containsKey(attrName) == false)
            continue;
        String value = (String) attributes.get(attrName);
        if (value.equals("null") && server.getAttribute(objName, attrName) == null) {
            log.trace("ignoring 'null' for " + attrName);
            continue;
        }
        String attrType = attrInfo.getType();
        Attribute attr = null;
        try {
            Object realValue = PropertyEditors.convertValue(value, attrType);
            attr = new Attribute(attrName, realValue);
        } catch (ClassNotFoundException e) {
            String s = (attr != null) ? attr.getName() : attrType;
            log.trace("Failed to load class for attribute: " + s, e);
            throw new ReflectionException(e, "Failed to load class for attribute: " + s);
        } catch (IntrospectionException e) {
            log.trace("Skipped setting attribute: " + attrName + ", cannot find PropertyEditor for type: " + attrType);
            continue;
        }
        server.setAttribute(objName, attr);
        newAttributes.add(attr);
    }
    return newAttributes;
}
Example 23
Project: ESPlorer-master  File: ReflectionUtil.java View source code
/**
     * @param base
     * @param property
     * @return
     * @throws ELException
     * @throws PropertyNotFoundException
     */
public static PropertyDescriptor getPropertyDescriptor(Object base, Object property) throws ELException, PropertyNotFoundException {
    String name = ELSupport.coerceToString(property);
    PropertyDescriptor p = null;
    try {
        PropertyDescriptor[] desc = Introspector.getBeanInfo(base.getClass()).getPropertyDescriptors();
        for (int i = 0; i < desc.length; i++) {
            if (desc[i].getName().equals(name)) {
                return desc[i];
            }
        }
    } catch (IntrospectionException ie) {
        throw new ELException(ie);
    }
    throw new PropertyNotFoundException(MessageFactory.get("error.property.notfound", base, name));
}
Example 24
Project: Rio-master  File: SamplingWatch.java View source code
private Method getAccessor() {
    BeanInfo bi = null;
    try {
        bi = Introspector.getBeanInfo(bean.getClass());
    } catch (IntrospectionException e) {
        e.printStackTrace();
    }
    if (bi == null)
        return null;
    Method accessor = null;
    PropertyDescriptor[] pds = bi.getPropertyDescriptors();
    boolean propertyMatch = false;
    for (PropertyDescriptor pd : pds) {
        String propName = pd.getName();
        if (propName.equals(property)) {
            propertyMatch = true;
            Method m = pd.getReadMethod();
            if (m != null) {
                accessor = m;
            } else {
                logger.warn("SamplingWatch [{}], with declared propertyName " + "[{}], matched, no readMethod found on target object [{}]", getId(), property, bean.getClass().getName());
            }
        }
    }
    if (!propertyMatch) {
        logger.warn("SamplingWatch [{}] with property [{}] not found on target object {}", getId(), property, bean.getClass().getName());
    }
    return accessor;
}
Example 25
Project: Valkyrie-RCP-master  File: JSR303Validator.java View source code
/**
	 * Validates the object through Hibernate Validator
	 *
	 * @param object The object that needs to be validated
	 * @param property The properties that needs to be validated
	 * @return An array of [email protected] ConstraintViolation}, containing all validation
	 * errors
	 */
protected Set<ConstraintViolation<T>> doValidate(final T object, final String property) {
    if (property == null) {
        final Set<ConstraintViolation<T>> ret = Sets.newHashSet();
        PropertyDescriptor[] propertyDescriptors;
        try {
            propertyDescriptors = Introspector.getBeanInfo(object.getClass()).getPropertyDescriptors();
        } catch (IntrospectionException e) {
            throw new IllegalStateException("Could not retrieve property information");
        }
        for (final PropertyDescriptor prop : propertyDescriptors) {
            String propertyName = prop.getName();
            if (formModel.hasValueModel(propertyName) && !ignoredProperties.contains(propertyName)) {
                final Set<ConstraintViolation<T>> result = validator.validateValue(beanClass, propertyName, formModel.getValueModel(//validator.validateProperty(object, propertyName);
                propertyName).getValue());
                if (result != null) {
                    ret.addAll(result);
                }
            }
        }
        return ret;
    } else if (!ignoredProperties.contains(property) && formModel.hasValueModel(property)) {
        return validator.validateValue(beanClass, property, formModel.getValueModel(property).getValue());
    } else {
        return null;
    }
}