List of usage examples for org.springframework.beans InvalidPropertyException InvalidPropertyException
public InvalidPropertyException(Class<?> beanClass, String propertyName, String msg)
From source file:cern.jarrace.controller.io.JarWriter.java
@PostConstruct void init() throws InvalidPropertyException { if (deploymentPath == null || deploymentPath.isEmpty()) { throw new InvalidPropertyException(JarWriter.class, IO_DEPLOYMENT_DIR_PROPERTY_NAME, "Property cannot be null nor empty"); }//from ww w. j av a 2 s. c o m File deploymentDir = new File(deploymentPath); checkDirectory(deploymentDir); }
From source file:org.systemexception.simplexdb.Application.java
@Bean public DatabaseApi databaseService() throws IOException, ClassNotFoundException { if ("mapdb".equals(databaseType)) { return new MapDbService(storageService(), databaseFilename, maxMemoryOccupation); }/*w ww . j a v a 2 s . co m*/ if ("berkeleydb".equals(databaseType)) { return new BerkeleyDbService(storageService(), databaseFilename, maxMemoryOccupation); } throw new InvalidPropertyException(DatabaseApi.class, "database.type", "Database configuration missing"); }
From source file:cern.jarrace.controller.io.JarWriter.java
private void checkDirectory(File deploymentDir) { if (!deploymentDir.exists()) { if (!deploymentDir.mkdirs()) { throw new IllegalStateException( String.format("Deployment folder cannot be created: [%s]", deploymentPath)); }/*from ww w . j av a2s .c o m*/ } else if (!deploymentDir.isDirectory()) { throw new InvalidPropertyException(JarWriter.class, "deployment_dir", "Property points to a file and not a directory."); } }
From source file:org.jasig.portlet.proxy.mvc.portlet.gateway.GatewayPortletController.java
@PostConstruct private void validateGatewayEntries() { HashSet<GatewayEntry> set = new HashSet<GatewayEntry>(); for (GatewayEntry entry : gatewayEntries) { if (!set.add(entry)) { throw new InvalidPropertyException(GatewayEntry.class, "name", "Error initializing Gateway Entries, multiple entries with name " + entry.getName()); }//from w ww .j av a 2 s.co m } }
From source file:net.yasion.common.core.bean.wrapper.impl.ExtendedBeanWrapperImpl.java
@Override public PropertyDescriptor getPropertyDescriptor(String propertyName) throws BeansException { PropertyDescriptor pd = getPropertyDescriptorInternal(propertyName); if (pd == null) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "No property '" + propertyName + "' found"); }/* w ww .j ava 2 s. c om*/ return pd; }
From source file:net.yasion.common.core.bean.wrapper.impl.ExtendedBeanWrapperImpl.java
/** * Convert the given value for the specified property to the latter's type. * <p>//w ww . j a v a2 s . c o m * This method is only intended for optimizations in a BeanFactory. Use the {@code convertIfNecessary} methods for programmatic conversion. * * @param value * the value to convert * @param propertyName * the target property (note that nested or indexed properties are not supported here) * @return the new value, possibly the result of type conversion * @throws TypeMismatchException * if type conversion failed */ public Object convertForProperty(Object value, String propertyName) throws TypeMismatchException { CachedIntrospectionResults cachedIntrospectionResults = getCachedIntrospectionResults(); PropertyDescriptor pd = cachedIntrospectionResults.getPropertyDescriptor(propertyName); if (pd == null) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "No property '" + propertyName + "' found"); } TypeDescriptor td = cachedIntrospectionResults.getTypeDescriptor(pd); if (td == null) { td = cachedIntrospectionResults.addTypeDescriptor(pd, new TypeDescriptor(property(pd))); } return convertForProperty(propertyName, null, value, td); }
From source file:net.yasion.common.core.bean.wrapper.impl.ExtendedBeanWrapperImpl.java
@SuppressWarnings("unchecked") private Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException { String propertyName = tokens.canonicalName; String actualName = tokens.actualName; PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName); if (pd == null || pd.getReadMethod() == null) { throw new NotReadablePropertyException(getRootClass(), this.nestedPath + propertyName); }/*from w w w. j a va 2 s . c o m*/ final Method readMethod = pd.getReadMethod(); try { if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers()) && !readMethod.isAccessible()) { if (System.getSecurityManager() != null) { AccessController.doPrivileged(new PrivilegedAction<Object>() { @Override public Object run() { readMethod.setAccessible(true); return null; } }); } else { readMethod.setAccessible(true); } } Object value; if (System.getSecurityManager() != null) { try { value = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { @Override public Object run() throws Exception { return readMethod.invoke(object, (Object[]) null); } }, acc); } catch (PrivilegedActionException pae) { throw pae.getException(); } } else { value = readMethod.invoke(object, (Object[]) null); } if (tokens.keys != null) { if (value == null) { if (isAutoGrowNestedPaths()) { value = setDefaultValue(tokens.actualName); } else { throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName, "Cannot access indexed value of property referenced in indexed " + "property path '" + propertyName + "': returned null"); } } String indexedPropertyName = tokens.actualName; // apply indexes and map keys for (int i = 0; i < tokens.keys.length; i++) { String key = tokens.keys[i]; if (value == null) { throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName, "Cannot access indexed value of property referenced in indexed " + "property path '" + propertyName + "': returned null"); } else if (value.getClass().isArray()) { int index = Integer.parseInt(key); value = growArrayIfNecessary(value, index, indexedPropertyName); value = Array.get(value, index); } else if (value instanceof List) { int index = Integer.parseInt(key); List<Object> list = (List<Object>) value; growCollectionIfNecessary(list, index, indexedPropertyName, pd, i + 1); value = list.get(index); } else if (value instanceof Set) { // Apply index to Iterator in case of a Set. Set<Object> set = (Set<Object>) value; int index = Integer.parseInt(key); if (index < 0 || index >= set.size()) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Cannot get element with index " + index + " from Set of size " + set.size() + ", accessed using property path '" + propertyName + "'"); } Iterator<Object> it = set.iterator(); for (int j = 0; it.hasNext(); j++) { Object elem = it.next(); if (j == index) { value = elem; break; } } } else if (value instanceof Map) { Map<Object, Object> map = (Map<Object, Object>) value; Class<?> mapKeyType = GenericCollectionTypeResolver.getMapKeyReturnType(pd.getReadMethod(), i + 1); // IMPORTANT: Do not pass full property name in here - property editors // must not kick in for map keys but rather only for map values. TypeDescriptor typeDescriptor = TypeDescriptor.valueOf(mapKeyType); Object convertedMapKey = convertIfNecessary(null, null, key, mapKeyType, typeDescriptor); value = map.get(convertedMapKey); } else { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Property referenced in indexed property path '" + propertyName + "' is neither an array nor a List nor a Set nor a Map; returned value was [" + value + "]"); } indexedPropertyName += PROPERTY_KEY_PREFIX + key + PROPERTY_KEY_SUFFIX; } } return value; } catch (IndexOutOfBoundsException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Index of out of bounds in property path '" + propertyName + "'", ex); } catch (NumberFormatException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Invalid index in property path '" + propertyName + "'", ex); } catch (TypeMismatchException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Invalid index in property path '" + propertyName + "'", ex); } catch (InvocationTargetException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Getter for property '" + actualName + "' threw exception", ex); } catch (Exception ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Illegal attempt to get property '" + actualName + "' threw exception", ex); } }
From source file:org.nextframework.controller.ExtendedBeanWrapper.java
protected Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException { String propertyName = tokens.canonicalName; String actualName = tokens.actualName; PropertyDescriptor pd = getPropertyDescriptorInternal(tokens.actualName); if (pd == null || pd.getReadMethod() == null) { throw new NotReadablePropertyException(getRootClass(), this.nestedPath + propertyName); }/*from w ww . j ava 2 s .co m*/ if (logger.isDebugEnabled()) logger.debug("About to invoke read method [" + pd.getReadMethod() + "] on object of class [" + this.object.getClass().getName() + "]"); try { Object value = pd.getReadMethod().invoke(this.object, (Object[]) null); Type genericReturnType = pd.getReadMethod().getGenericReturnType(); Class rawReturnType = pd.getReadMethod().getReturnType(); if (tokens.keys != null) { // apply indexes and map keys for (int i = 0; i < tokens.keys.length; i++) { String key = tokens.keys[i]; //cria listas sob demanda.. no mais necessrio utilizar o ListSet no pojo Class originalClass = null; if (value != null) { originalClass = value.getClass(); } if (value == null && rawReturnType != null && genericReturnType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) genericReturnType; if (Map.class.isAssignableFrom(rawReturnType)) { value = new LinkedHashMap(); pd.getWriteMethod().invoke(this.object, value); } else if (List.class.isAssignableFrom(rawReturnType) || Set.class.isAssignableFrom(rawReturnType)) { Type type = parameterizedType.getActualTypeArguments()[0]; value = new ListSet(type instanceof Class ? (Class) type : (Class) ((ParameterizedType) type).getRawType()); pd.getWriteMethod().invoke(this.object, value); } } //fim da criacao sob demanda if (value == null) { throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName, "Cannot access indexed value of property referenced in indexed " + "property path '" + propertyName + "': returned null"); } else if (value.getClass().isArray()) { value = Array.get(value, Integer.parseInt(key)); } else if (value instanceof List) { List list = (List) value; try { value = list.get(Integer.parseInt(key)); } catch (IndexOutOfBoundsException e) { //tentar instanciar um bean da lista String extraMessage = ""; if (genericReturnType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) genericReturnType; Type type = parameterizedType.getActualTypeArguments()[0]; if (type instanceof Class) { Class clazz = (Class) type; extraMessage = "A classe " + clazz.getName() + " no possui um construtor publico sem argumentos"; try { value = clazz.newInstance(); int index = Integer.parseInt(key); int insertNulls = index - list.size(); while (insertNulls > 0) { // 11/06/2012 list.add(null); insertNulls--; } list.add(index, value); // CDIGO 15/01/2007 } catch (InstantiationException e1) { throw new RuntimeException( "Aconteceu um erro ao acessar um elemento da classe " + originalClass.getName() + " propriedade " + propertyName + " No foi possvel instanciar um bean para preencher a lista. " + extraMessage, e); } } } else if (originalClass != null) { throw new RuntimeException("Aconteceu um erro ao acessar um elemento da classe " + originalClass.getName() + " propriedade " + propertyName + " Sugesto: Utilize uma lista que cresa quando for necessrio como o ListSet ou no instancie nenhum objeto para essa propriedade", e); } else { throw e; } } } else if (value instanceof Set) { // apply index to Iterator in case of a Set //TODO CRIAR AUTOMATICAMENTE O BEAN DO SET Set set = (Set) value; int index = Integer.parseInt(key); if (index < 0 || index >= set.size()) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Cannot get element with index " + index + " from Set of size " + set.size() + ", accessed using property path '" + propertyName + "'" + " Sugesto: Utilize o ListSet ou no instancie nenhum objeto"); } Iterator it = set.iterator(); for (int j = 0; it.hasNext(); j++) { Object elem = it.next(); if (j == index) { value = elem; break; } } } else if (value instanceof Map) { if (!(genericReturnType instanceof ParameterizedType)) { throw new NotParameterizedTypeException( "Path direciona a um Map no parameterizado com generics. " + " Propriedade '" + this.nestedPath + propertyName + "' da classe [" + this.rootObject.getClass().getName() + "]"); } ParameterizedType parameterizedType = ((ParameterizedType) genericReturnType); Type mapKeyType = parameterizedType.getActualTypeArguments()[0]; Type mapValueType = parameterizedType.getActualTypeArguments()[1]; Class rawKeyType = mapKeyType instanceof Class ? (Class) mapKeyType : (Class) ((ParameterizedType) mapKeyType).getRawType(); Class rawValueType = mapValueType instanceof Class ? (Class) mapValueType : (Class) ((ParameterizedType) mapValueType).getRawType(); Object objectKey = doTypeConversionIfNecessary(key, rawKeyType); Map map = (Map) value; value = map.get(objectKey); if (value == null && List.class.isAssignableFrom(rawValueType)) { List mapValue; try { Type listType = ((ParameterizedType) mapValueType).getActualTypeArguments()[0]; mapValue = new ListSet(listType instanceof Class ? (Class) listType : (Class) ((ParameterizedType) listType).getRawType()); } catch (ClassCastException e) { throw new RuntimeException( "Na path " + propertyName + " um mapa contm uma lista no parametrizada"); } map.put(objectKey, mapValue); value = mapValue; } } else { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Property referenced in indexed property path '" + propertyName + "' is neither an array nor a List nor a Set nor a Map; returned value was [" + value + "]"); } } } return value; } catch (InvocationTargetException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Getter for property '" + actualName + "' threw exception", ex); } catch (IllegalAccessException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Illegal attempt to get property '" + actualName + "' threw exception", ex); } catch (IndexOutOfBoundsException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Index of out of bounds in property path '" + propertyName + "'", ex); } catch (NumberFormatException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "Invalid index in property path '" + propertyName + "'", ex); } }
From source file:org.nextframework.controller.ExtendedBeanWrapper.java
public PropertyDescriptor getPropertyDescriptor(String propertyName) throws BeansException { if (propertyName == null) { throw new IllegalArgumentException("Can't find property descriptor for <code>null</code> property"); }/*w w w . j a v a2s.co m*/ PropertyDescriptor pd = getPropertyDescriptorInternal(propertyName); if (pd != null) { return pd; } else { throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName, "No property '" + propertyName + "' found"); } }
From source file:org.springframework.beans.AbstractNestablePropertyAccessor.java
@SuppressWarnings("unchecked") private void processKeyedProperty(PropertyTokenHolder tokens, PropertyValue pv) { Object propValue = getPropertyHoldingValue(tokens); PropertyHandler ph = getLocalPropertyHandler(tokens.actualName); if (ph == null) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + tokens.actualName, "No property handler found"); }//from w w w. jav a2 s . co m Assert.state(tokens.keys != null, "No token keys"); String lastKey = tokens.keys[tokens.keys.length - 1]; if (propValue.getClass().isArray()) { Class<?> requiredType = propValue.getClass().getComponentType(); int arrayIndex = Integer.parseInt(lastKey); Object oldValue = null; try { if (isExtractOldValueForEditor() && arrayIndex < Array.getLength(propValue)) { oldValue = Array.get(propValue, arrayIndex); } Object convertedValue = convertIfNecessary(tokens.canonicalName, oldValue, pv.getValue(), requiredType, ph.nested(tokens.keys.length)); int length = Array.getLength(propValue); if (arrayIndex >= length && arrayIndex < this.autoGrowCollectionLimit) { Class<?> componentType = propValue.getClass().getComponentType(); Object newArray = Array.newInstance(componentType, arrayIndex + 1); System.arraycopy(propValue, 0, newArray, 0, length); setPropertyValue(tokens.actualName, newArray); propValue = getPropertyValue(tokens.actualName); } Array.set(propValue, arrayIndex, convertedValue); } catch (IndexOutOfBoundsException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + tokens.canonicalName, "Invalid array index in property path '" + tokens.canonicalName + "'", ex); } } else if (propValue instanceof List) { Class<?> requiredType = ph.getCollectionType(tokens.keys.length); List<Object> list = (List<Object>) propValue; int index = Integer.parseInt(lastKey); Object oldValue = null; if (isExtractOldValueForEditor() && index < list.size()) { oldValue = list.get(index); } Object convertedValue = convertIfNecessary(tokens.canonicalName, oldValue, pv.getValue(), requiredType, ph.nested(tokens.keys.length)); int size = list.size(); if (index >= size && index < this.autoGrowCollectionLimit) { for (int i = size; i < index; i++) { try { list.add(null); } catch (NullPointerException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + tokens.canonicalName, "Cannot set element with index " + index + " in List of size " + size + ", accessed using property path '" + tokens.canonicalName + "': List does not support filling up gaps with null elements"); } } list.add(convertedValue); } else { try { list.set(index, convertedValue); } catch (IndexOutOfBoundsException ex) { throw new InvalidPropertyException(getRootClass(), this.nestedPath + tokens.canonicalName, "Invalid list index in property path '" + tokens.canonicalName + "'", ex); } } } else if (propValue instanceof Map) { Class<?> mapKeyType = ph.getMapKeyType(tokens.keys.length); Class<?> mapValueType = ph.getMapValueType(tokens.keys.length); Map<Object, Object> map = (Map<Object, Object>) propValue; // IMPORTANT: Do not pass full property name in here - property editors // must not kick in for map keys but rather only for map values. TypeDescriptor typeDescriptor = TypeDescriptor.valueOf(mapKeyType); Object convertedMapKey = convertIfNecessary(null, null, lastKey, mapKeyType, typeDescriptor); Object oldValue = null; if (isExtractOldValueForEditor()) { oldValue = map.get(convertedMapKey); } // Pass full property name and old value in here, since we want full // conversion ability for map values. Object convertedMapValue = convertIfNecessary(tokens.canonicalName, oldValue, pv.getValue(), mapValueType, ph.nested(tokens.keys.length)); map.put(convertedMapKey, convertedMapValue); } else { throw new InvalidPropertyException(getRootClass(), this.nestedPath + tokens.canonicalName, "Property referenced in indexed property path '" + tokens.canonicalName + "' is neither an array nor a List nor a Map; returned value was [" + propValue + "]"); } }