Search in sources :

Example 1 with IntrospectionException

use of java.beans.IntrospectionException in project Core by iConomy.

the class QueryRunner method fillStatementWithBean.

/**
     * Fill the <code>PreparedStatement</code> replacement parameters with the
     * given object's bean property values.
     * 
     * @param stmt
     *            PreparedStatement to fill
     * @param bean
     *            a JavaBean object
     * @param propertyNames
     *            an ordered array of property names (these should match the
     *            getters/setters); this gives the order to insert values in the
     *            statement
     * @throws SQLException
     *             if a database access error occurs
     */
public void fillStatementWithBean(PreparedStatement stmt, Object bean, String... propertyNames) throws SQLException {
    PropertyDescriptor[] descriptors;
    try {
        descriptors = Introspector.getBeanInfo(bean.getClass()).getPropertyDescriptors();
    } catch (IntrospectionException e) {
        throw new RuntimeException("Couldn't introspect bean " + bean.getClass().toString(), e);
    }
    PropertyDescriptor[] sorted = new PropertyDescriptor[propertyNames.length];
    for (int i = 0; i < propertyNames.length; i++) {
        String propertyName = propertyNames[i];
        if (propertyName == null) {
            throw new NullPointerException("propertyName can't be null: " + i);
        }
        boolean found = false;
        for (int j = 0; j < descriptors.length; j++) {
            PropertyDescriptor descriptor = descriptors[j];
            if (propertyName.equals(descriptor.getName())) {
                sorted[i] = descriptor;
                found = true;
                break;
            }
        }
        if (!found) {
            throw new RuntimeException("Couldn't find bean property: " + bean.getClass() + " " + propertyName);
        }
    }
    fillStatementWithBean(stmt, bean, sorted);
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException)

Example 2 with IntrospectionException

use of java.beans.IntrospectionException in project core-java by SpineEventEngine.

the class Columns method addToCache.

/**
     * Caches the {@linkplain Entity entity type} for further {@link Column Columns} retrieving.
     */
private static void addToCache(Class<? extends Entity> entityType) {
    final BeanInfo entityDescriptor;
    try {
        entityDescriptor = Introspector.getBeanInfo(entityType);
    } catch (IntrospectionException e) {
        throw new IllegalStateException(e);
    }
    for (PropertyDescriptor property : entityDescriptor.getPropertyDescriptors()) {
        final Method getter = property.getReadMethod();
        if (!ExcludedMethod.contain(getter.getName())) {
            final Column<?> storageField = Column.from(getter);
            knownEntityProperties.put(entityType, storageField);
        }
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) Method(java.lang.reflect.Method)

Example 3 with IntrospectionException

use of java.beans.IntrospectionException in project ACS by ACS-Community.

the class TestTreeExplorer method createTreeExplorer.

public static TreeExplorer createTreeExplorer() {
    TreeExplorer expl = null;
    try {
        GPNode root = NodeFactory.createNode(new SimpleDemoBean("parent"), new RecursiveChildrenListManager());
        expl = new TreeExplorer();
        expl.setRootNode(root);
    } catch (IntrospectionException ex) {
        ex.printStackTrace();
    }
    return expl;
}
Also used : TreeExplorer(cern.gp.explorer.TreeExplorer) SimpleDemoBean(cern.gp.explorer.test.helpers.SimpleDemoBean) RecursiveChildrenListManager(cern.gp.explorer.test.helpers.RecursiveChildrenListManager) IntrospectionException(java.beans.IntrospectionException) GPNode(cern.gp.nodes.GPNode)

Example 4 with IntrospectionException

use of java.beans.IntrospectionException in project ACS by ACS-Community.

the class TestTreeExplorerWithButtons method createTreeExplorer.

public static TreeExplorer createTreeExplorer() {
    TreeExplorer expl = null;
    try {
        GPNode root = NodeFactory.createNode(new SimpleDemoBean("parent"), new RecursiveChildrenListManager());
        expl = new TreeExplorer();
        expl.setRootNode(root);
    } catch (IntrospectionException ex) {
        ex.printStackTrace();
    }
    return expl;
}
Also used : TreeExplorer(cern.gp.explorer.TreeExplorer) SimpleDemoBean(cern.gp.explorer.test.helpers.SimpleDemoBean) RecursiveChildrenListManager(cern.gp.explorer.test.helpers.RecursiveChildrenListManager) IntrospectionException(java.beans.IntrospectionException) GPNode(cern.gp.nodes.GPNode)

Example 5 with IntrospectionException

use of java.beans.IntrospectionException in project intellij-community by JetBrains.

the class Palette method getIntrospectedProperties.

/**
   * @return arrays of all properties that can be introspected from the
   * specified class. Only properties with getter and setter methods are
   * returned.
   */
@NotNull
public IntrospectedProperty[] getIntrospectedProperties(@NotNull final Class aClass, @NotNull final Class delegeeClass) {
    // TODO[vova, anton] update cache after class reloading (its properties could be hanged).
    if (myClass2Properties.containsKey(aClass)) {
        return myClass2Properties.get(aClass);
    }
    final ArrayList<IntrospectedProperty> result = new ArrayList<>();
    try {
        final BeanInfo beanInfo = Introspector.getBeanInfo(aClass);
        final PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
        for (final PropertyDescriptor descriptor : descriptors) {
            Method readMethod = descriptor.getReadMethod();
            Method writeMethod = descriptor.getWriteMethod();
            Class propertyType = descriptor.getPropertyType();
            if (writeMethod == null || readMethod == null || propertyType == null) {
                continue;
            }
            boolean storeAsClient = false;
            try {
                delegeeClass.getMethod(readMethod.getName(), readMethod.getParameterTypes());
                delegeeClass.getMethod(writeMethod.getName(), writeMethod.getParameterTypes());
            } catch (NoSuchMethodException e) {
                storeAsClient = true;
            }
            @NonNls final String name = descriptor.getName();
            final IntrospectedProperty property;
            final Properties properties = (myProject == null) ? new Properties() : Properties.getInstance();
            if (int.class.equals(propertyType)) {
                // int
                IntEnumEditor.Pair[] enumPairs = properties.getEnumPairs(aClass, name);
                if (enumPairs != null) {
                    property = createIntEnumProperty(name, readMethod, writeMethod, enumPairs);
                } else if (JLabel.class.isAssignableFrom(aClass)) {
                    // special handling for javax.swing.JLabel
                    if (JLabel.class.isAssignableFrom(aClass) && ("displayedMnemonic".equals(name) || "displayedMnemonicIndex".equals(name))) {
                        // skip JLabel#displayedMnemonic and JLabel#displayedMnemonicIndex
                        continue;
                    } else {
                        property = new IntroIntProperty(name, readMethod, writeMethod, storeAsClient);
                    }
                } else if (AbstractButton.class.isAssignableFrom(aClass)) {
                    // special handling AbstractButton subclasses
                    if ("mnemonic".equals(name) || "displayedMnemonicIndex".equals(name)) {
                        // AbstractButton#mnemonic
                        continue;
                    } else {
                        property = new IntroIntProperty(name, readMethod, writeMethod, storeAsClient);
                    }
                } else if (JTabbedPane.class.isAssignableFrom(aClass)) {
                    if (SwingProperties.SELECTED_INDEX.equals(name)) {
                        continue;
                    }
                    property = new IntroIntProperty(name, readMethod, writeMethod, storeAsClient);
                } else {
                    property = new IntroIntProperty(name, readMethod, writeMethod, storeAsClient);
                }
            } else if (boolean.class.equals(propertyType)) {
                // boolean
                property = new IntroBooleanProperty(name, readMethod, writeMethod, storeAsClient);
            } else if (double.class.equals(propertyType)) {
                property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Double.class);
            } else if (float.class.equals(propertyType)) {
                property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Float.class);
            } else if (long.class.equals(propertyType)) {
                property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Long.class);
            } else if (byte.class.equals(propertyType)) {
                property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Byte.class);
            } else if (short.class.equals(propertyType)) {
                property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Short.class);
            } else if (char.class.equals(propertyType)) {
                // java.lang.String
                property = new IntroCharProperty(name, readMethod, writeMethod, storeAsClient);
            } else if (String.class.equals(propertyType)) {
                // java.lang.String
                property = new IntroStringProperty(name, readMethod, writeMethod, myProject, storeAsClient);
            } else if (Insets.class.equals(propertyType)) {
                // java.awt.Insets
                property = new IntroInsetsProperty(name, readMethod, writeMethod, storeAsClient);
            } else if (Dimension.class.equals(propertyType)) {
                // java.awt.Dimension
                property = new IntroDimensionProperty(name, readMethod, writeMethod, storeAsClient);
            } else if (Rectangle.class.equals(propertyType)) {
                // java.awt.Rectangle
                property = new IntroRectangleProperty(name, readMethod, writeMethod, storeAsClient);
            } else if (Component.class.isAssignableFrom(propertyType)) {
                if (JSplitPane.class.isAssignableFrom(aClass) && (name.equals("leftComponent") || name.equals("rightComponent") || name.equals("topComponent") || name.equals("bottomComponent"))) {
                    // these properties are set through layout
                    continue;
                }
                if (JTabbedPane.class.isAssignableFrom(aClass) && name.equals(SwingProperties.SELECTED_COMPONENT)) {
                    // can't set selectedComponent because of set property / add child sequence
                    continue;
                }
                if (JMenuBar.class.isAssignableFrom(propertyType) || JPopupMenu.class.isAssignableFrom(propertyType)) {
                    // no menu editing yet
                    continue;
                }
                Condition<RadComponent> filter = null;
                if (name.equals(SwingProperties.LABEL_FOR)) {
                    filter = t -> {
                        ComponentItem item = getItem(t.getComponentClassName());
                        return item != null && item.isCanAttachLabel();
                    };
                }
                property = new IntroComponentProperty(name, readMethod, writeMethod, propertyType, filter, storeAsClient);
            } else if (Color.class.equals(propertyType)) {
                property = new IntroColorProperty(name, readMethod, writeMethod, storeAsClient);
            } else if (Font.class.equals(propertyType)) {
                property = new IntroFontProperty(name, readMethod, writeMethod, storeAsClient);
            } else if (Icon.class.equals(propertyType)) {
                property = new IntroIconProperty(name, readMethod, writeMethod, storeAsClient);
            } else if (ListModel.class.isAssignableFrom(propertyType)) {
                property = new IntroListModelProperty(name, readMethod, writeMethod, storeAsClient);
            } else if (Enum.class.isAssignableFrom(propertyType)) {
                property = new IntroEnumProperty(name, readMethod, writeMethod, storeAsClient, propertyType);
            } else {
                // other types are not supported (yet?)
                continue;
            }
            result.add(property);
        }
    } catch (IntrospectionException e) {
        throw new RuntimeException(e);
    }
    final IntrospectedProperty[] properties = result.toArray(new IntrospectedProperty[result.size()]);
    myClass2Properties.put(aClass, properties);
    return properties;
}
Also used : BeanInfo(java.beans.BeanInfo) ArrayList(java.util.ArrayList) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) IntrospectionException(java.beans.IntrospectionException) SwingProperties(com.intellij.uiDesigner.SwingProperties) Properties(com.intellij.uiDesigner.Properties) NonNls(org.jetbrains.annotations.NonNls) PropertyDescriptor(java.beans.PropertyDescriptor) Method(java.lang.reflect.Method) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IntrospectionException (java.beans.IntrospectionException)244 PropertyDescriptor (java.beans.PropertyDescriptor)159 BeanInfo (java.beans.BeanInfo)106 Method (java.lang.reflect.Method)91 InvocationTargetException (java.lang.reflect.InvocationTargetException)56 ArrayList (java.util.ArrayList)31 Field (java.lang.reflect.Field)29 IOException (java.io.IOException)28 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)24 HashMap (java.util.HashMap)23 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)21 Map (java.util.Map)20 List (java.util.List)13 Introspector (java.beans.Introspector)12 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)10 MessageFormat (java.text.MessageFormat)9 UUID (java.util.UUID)9 Collectors (java.util.stream.Collectors)8 Assert (org.springframework.util.Assert)8 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)7