private void setIndexedWriteMethod(Class<?> beanClass, String indexedSetterName, Class<?> argType) throws IntrospectionException { try { Method setter = beanClass.getMethod(indexedSetterName, new Class[] {Integer.TYPE, argType}); internalSetIndexedWriteMethod(setter, true); } catch (NoSuchMethodException exception) { // beans.5D=No such indexed write method throw new IntrospectionException(Messages.getString("beans.5D")); // $NON-NLS-1$ } catch (SecurityException exception) { // beans.5C=Security violation accessing indexed write method throw new IntrospectionException(Messages.getString("beans.5C")); // $NON-NLS-1$ } }
private void setIndexedReadMethod(Class<?> beanClass, String indexedGetterName) throws IntrospectionException { Method getter; try { getter = beanClass.getMethod(indexedGetterName, new Class[] {Integer.TYPE}); } catch (NoSuchMethodException exception) { // beans.58=No such indexed read method throw new IntrospectionException(Messages.getString("beans.58")); // $NON-NLS-1$ } catch (SecurityException exception) { // beans.59=Security violation accessing indexed read method throw new IntrospectionException(Messages.getString("beans.59")); // $NON-NLS-1$ } internalSetIndexedReadMethod(getter); }
// ensures that there is no nulls @SuppressWarnings("nls") private void checkNotNull( Object sourceClass, Object eventSetName, Object alistenerType, Object listenerMethodName) { if (sourceClass == null) { throw new NullPointerException(Messages.getString("beans.0C")); } if (eventSetName == null) { throw new NullPointerException(Messages.getString("beans.53")); } if (alistenerType == null) { throw new NullPointerException(Messages.getString("beans.54")); } if (listenerMethodName == null) { throw new NullPointerException(Messages.getString("beans.52")); } }
private void setIndexedWriteMethod(Class<?> beanClass, String indexedSetterName) throws IntrospectionException { Method setter = null; try { setter = beanClass.getMethod( indexedSetterName, new Class[] {Integer.TYPE, getPropertyType().getComponentType()}); } catch (SecurityException e) { // beans.5C=Security violation accessing indexed write method throw new IntrospectionException(Messages.getString("beans.5C")); // $NON-NLS-1$ } catch (NoSuchMethodException e) { // beans.5D=No such indexed write method throw new IntrospectionException(Messages.getString("beans.5D")); // $NON-NLS-1$ } internalSetIndexedWriteMethod(setter, true); }
private void internalSetIndexedReadMethod(Method indexGetter) throws IntrospectionException { // Clearing the indexed read method. if (indexGetter == null) { if (indexedSetter == null) { if (getPropertyType() != null) { // beans.5A=Indexed method is not compatible with non indexed method throw new IntrospectionException(Messages.getString("beans.5A")); // $NON-NLS-1$ } indexedPropertyType = null; } this.indexedGetter = null; return; } // Validate the indexed getter. if ((indexGetter.getParameterTypes().length != 1) || (indexGetter.getParameterTypes()[0] != Integer.TYPE)) { // beans.5B=Indexed read method must take a single int argument throw new IntrospectionException(Messages.getString("beans.5B")); // $NON-NLS-1$ } Class<?> indexedReadType = indexGetter.getReturnType(); if (indexedReadType == Void.TYPE) { // beans.5B=Indexed read method must take a single int argument throw new IntrospectionException(Messages.getString("beans.5B")); // $NON-NLS-1$ } else if (indexedSetter != null && indexGetter.getReturnType() != indexedSetter.getParameterTypes()[1]) { // beans.5A=Indexed read method is not compatible with indexed write method throw new IntrospectionException(Messages.getString("beans.5A")); // $NON-NLS-1$ } // Set the indexed property type if not already set, confirm validity if // it is. if (this.indexedGetter == null) { indexedPropertyType = indexedReadType; } else { if (indexedPropertyType != indexedReadType) { // beans.5A=Indexed read method is not compatible with indexed write method throw new IntrospectionException(Messages.getString("beans.5A")); // $NON-NLS-1$ } } // Set the indexed getter this.indexedGetter = indexGetter; }
private void internalSetIndexedWriteMethod(Method indexSetter, boolean initialize) throws IntrospectionException { // Clearing the indexed write method. if (indexSetter == null) { if (indexedGetter == null) { if (getPropertyType() != null) { // beans.5E=Indexed method is not compatible with non indexed method throw new IntrospectionException(Messages.getString("beans.5E")); // $NON-NLS-1$ } indexedPropertyType = null; } this.indexedSetter = null; return; } // Validate the indexed write method. Class<?>[] indexedSetterArgs = indexSetter.getParameterTypes(); if (indexedSetterArgs.length != 2) { // beans.5F=Indexed write method must take two arguments throw new IntrospectionException(Messages.getString("beans.5F")); // $NON-NLS-1$ } if (indexedSetterArgs[0] != Integer.TYPE) { // beans.60=Indexed write method must take an int as its first argument throw new IntrospectionException(Messages.getString("beans.60")); // $NON-NLS-1$ } // Set the indexed property type if not already set, confirm validity if // it is. Class<?> indexedWriteType = indexedSetterArgs[1]; if (initialize && indexedGetter == null) { indexedPropertyType = indexedWriteType; } else { if (indexedPropertyType != indexedWriteType) { // beans.61=Indexed write method is not compatible with indexed read method throw new IntrospectionException(Messages.getString("beans.61")); // $NON-NLS-1$ } } // Set the indexed write method. this.indexedSetter = indexSetter; }
/** * Searches for {add|remove}Listener methods in the event source. Parameter check is also * performed. * * @param sourceClass event source class * @param methodName method name to search * @return found method * @throws IntrospectionException if no valid method found */ private Method findAddRemoveListenerMethod(Class<?> sourceClass, String methodName) throws IntrospectionException { try { return sourceClass.getMethod(methodName, listenerType); } catch (NoSuchMethodException e) { return findAddRemoveListnerMethodWithLessCheck(sourceClass, methodName); } catch (Exception e) { throw new IntrospectionException( Messages.getString( "beans.31", //$NON-NLS-1$ methodName, listenerType.getName())); } }
/** * Constructs a new instance of <code>IndexedPropertyDescriptor</code>. * * @param propertyName the specified indexed property's name. * @param getter the array getter * @param setter the array setter * @param indexedGetter the indexed getter * @param indexedSetter the indexed setter * @throws IntrospectionException */ public IndexedPropertyDescriptor( String propertyName, Method getter, Method setter, Method indexedGetter, Method indexedSetter) throws IntrospectionException { super(propertyName, getter, setter); if (indexedGetter != null) { internalSetIndexedReadMethod(indexedGetter); internalSetIndexedWriteMethod(indexedSetter, true); } else { internalSetIndexedWriteMethod(indexedSetter, true); internalSetIndexedReadMethod(indexedGetter); } if (!isCompatible()) { // beans.57=Property type is incompatible with the indexed property type throw new IntrospectionException(Messages.getString("beans.57")); // $NON-NLS-1$ } }
/** * Checks that given listener method has an argument of the valid type. * * @param eventSetName event set name * @param listenerMethod listener method * @throws IntrospectionException if check fails */ private static void checkEventType(String eventSetName, Method listenerMethod) throws IntrospectionException { Class<?>[] params = listenerMethod.getParameterTypes(); String firstParamTypeName = null; String eventTypeName = prepareEventTypeName(eventSetName); if (params.length > 0) { firstParamTypeName = extractShortClassName(params[0].getName()); } if (firstParamTypeName == null || !firstParamTypeName.equals(eventTypeName)) { throw new IntrospectionException( Messages.getString( "beans.51", //$NON-NLS-1$ listenerMethod.getName(), eventTypeName)); } }
private Method findListenerMethodByName(String listenerMethodName) throws IntrospectionException { Method result = null; Method[] methods = listenerType.getMethods(); for (Method method : methods) { if (listenerMethodName.equals(method.getName())) { Class<?>[] paramTypes = method.getParameterTypes(); if (paramTypes.length == 1 && paramTypes[0].getName().endsWith("Event")) { // $NON-NLS-1$ result = method; break; } } } if (null == result) { throw new IntrospectionException( Messages.getString( "beans.31", //$NON-NLS-1$ listenerMethodName, listenerType.getName())); } return result; }
public EventSetDescriptor( Class<?> sourceClass, String eventSetName, Class<?> listenerType, String listenerMethodName) throws IntrospectionException { checkNotNull(sourceClass, eventSetName, listenerType, listenerMethodName); setName(eventSetName); this.listenerType = listenerType; Method method = findListenerMethodByName(listenerMethodName); checkEventType(eventSetName, method); listenerMethodDescriptors = new ArrayList<MethodDescriptor>(); listenerMethodDescriptors.add(new MethodDescriptor(method)); addListenerMethod = findMethodByPrefix(sourceClass, "add", ""); // $NON-NLS-1$ //$NON-NLS-2$ removeListenerMethod = findMethodByPrefix(sourceClass, "remove", ""); // $NON-NLS-1$ //$NON-NLS-2$ if (addListenerMethod == null || removeListenerMethod == null) { throw new IntrospectionException(Messages.getString("beans.38")); // $NON-NLS-1$ } getListenerMethod = findMethodByPrefix(sourceClass, "get", "s"); // $NON-NLS-1$ //$NON-NLS-2$ unicast = isUnicastByDefault(addListenerMethod); }
private Method findAddRemoveListnerMethodWithLessCheck(Class<?> sourceClass, String methodName) throws IntrospectionException { Method[] methods = sourceClass.getMethods(); Method result = null; for (Method method : methods) { if (method.getName().equals(methodName)) { Class<?>[] paramTypes = method.getParameterTypes(); if (paramTypes.length == 1) { result = method; break; } } } if (null == result) { throw new IntrospectionException( Messages.getString( "beans.31", //$NON-NLS-1$ methodName, listenerType.getName())); } return result; }
private void setIndexedByName( Class<?> beanClass, String indexedGetterName, String indexedSetterName) throws IntrospectionException { String theIndexedGetterName = indexedGetterName; if (theIndexedGetterName == null) { if (indexedSetterName != null) { setIndexedWriteMethod(beanClass, indexedSetterName); } } else { if (theIndexedGetterName.length() == 0) { theIndexedGetterName = "get" + name; // $NON-NLS-1$ } setIndexedReadMethod(beanClass, theIndexedGetterName); if (indexedSetterName != null) { setIndexedWriteMethod(beanClass, indexedSetterName, indexedPropertyType); } } if (!isCompatible()) { // beans.57=Property type is incompatible with the indexed property type throw new IntrospectionException(Messages.getString("beans.57")); // $NON-NLS-1$ } }