/** * Return a comma-separated String of r/w properties of the specified object. * @param obj the object to introspect. * @return a a comma-separated String of r/w properties. */ public static String propertiesToString(Object obj) { StringBuffer sb = new StringBuffer(); Map properties = new TreeMap(getProperties(obj)); Iterator it = properties.keySet().iterator(); while (it.hasNext()) { String property = (String) it.next(); Object val = getProperty(obj, property); sb.append(property); sb.append("="); sb.append(val); if (it.hasNext()) sb.append(", "); } return sb.toString(); }
/** * Set a {@link Map} of direct or indirect properties on the target object. * @param target the target object on which to set the properties. * @param properties a {@link Map} of String/Object pairs. * @throws PropertyException if an error happened while trying to set a property. */ public static void setProperties(Object target, Map<String, Object> properties) throws PropertyException { for (Map.Entry<String, Object> entry : properties.entrySet()) { String name = entry.getKey(); Object value = entry.getValue(); setProperty(target, name, value); } }
public PoolingDataSource getObject() throws Exception { if (ds == null) { ds = new PoolingDataSource(); PropertyUtils.setProperties(ds, PropertyUtils.getProperties(this)); log.debug("Initializing PoolingDataSource with id '{}'", ds.getUniqueName()); ds.init(); } return ds; }
while (i < propertyNames.length -1) { String name = propertyNames[i]; Object result = callGetter(currentTarget, name); if (result == null) { Class propertyType = getPropertyType(target, name); try { result = propertyType.newInstance(); throw new PropertyException("cannot set property '" + propertyName + "' - '" + name + "' is null and cannot be auto-filled", ex); callSetter(currentTarget, name, result); setDirectProperty(currentTarget, lastPropertyName, propertyValue);
Map properties = PropertyUtils.getProperties(resource); StringBuilder sb = new StringBuilder(); Iterator it2 = properties.entrySet().iterator();
@Override public String extractExtraXAExceptionDetails(XAException ex) { if (ex.getClass().getName().equals("oracle.jdbc.xa.OracleXAException")) { try { return "ORA-" + PropertyUtils.getProperty(ex, "oracleError"); } catch (PropertyException e) { return null; } } return null; }
for (Method method : methods) { String name = method.getName(); if (method.getModifiers() == Modifier.PUBLIC && method.getParameterTypes().length == 0 && (name.startsWith("get") || name.startsWith("is")) && containsSetterForGetter(clazz, method)) { String propertyName; if (name.startsWith("get")) { if (propertyValue != null && propertyValue instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> propertiesContent = getNestedProperties(propertyName, (Map<String, Object>) propertyValue); properties.putAll(propertiesContent); } else {
@Override public XAConnection createXAConnection(String user, String password) throws JMSException { try { Class<?> clazz = ClassLoaderUtils.loadClass(connectionFactoryClassName); ConnectionFactory nonXaConnectionFactory = (ConnectionFactory) clazz.newInstance(); PropertyUtils.setProperties(nonXaConnectionFactory, properties); return new LrcXAConnection(nonXaConnectionFactory.createConnection(user, password)); } catch (Exception ex) { throw (JMSException) new JMSException("unable to connect to non-XA resource " + connectionFactoryClassName).initCause(ex); } }
private static Object callGetter(Object target, String propertyName) throws PropertyException { Method getter = getGetter(target, propertyName); try { return getter.invoke(target); } catch (IllegalAccessException ex) { throw new PropertyException("property '" + propertyName + "' is not accessible", ex); } catch (InvocationTargetException ex) { throw new PropertyException("property '" + propertyName + "' access threw an exception", ex); } }
/** * Get a direct or indirect property (dotted property: prop1.prop2.prop3) on the target object. * @param target the target object from which to get the property. * @param propertyName the name of the property to get. * @return the value of the specified property. * @throws PropertyException if an error happened while trying to get the property. */ public static Object getProperty(Object target, String propertyName) throws PropertyException { String[] propertyNames = propertyName.split("\\."); Object currentTarget = target; for (int i = 0; i < propertyNames.length; i++) { String name = propertyNames[i]; Object result = callGetter(currentTarget, name); if (result == null && i < propertyNames.length -1) throw new PropertyException("cannot get property '" + propertyName + "' - '" + name + "' is null"); currentTarget = result; } return currentTarget; }
while (i < propertyNames.length -1) { String name = propertyNames[i]; Object result = callGetter(currentTarget, name); if (result == null) { Class<?> propertyType = getPropertyType(target, name); try { result = propertyType.newInstance(); throw new PropertyException("cannot set property '" + propertyName + "' - '" + name + "' is null and cannot be auto-filled", ex); callSetter(currentTarget, name, result); p.put(lastPropertyName, propertyValue.toString()); if (parentName != null) { callSetter(parentTarget, parentName, p); setDirectProperty(currentTarget, lastPropertyName, propertyValue);
Map properties = PropertyUtils.getProperties(resource); StringBuffer sb = new StringBuffer(); Iterator it2 = properties.entrySet().iterator();
@Override public String extractExtraXAExceptionDetails(XAException ex) { if (ex.getClass().getName().equals("oracle.jdbc.xa.OracleXAException")) { try { return "ORA-" + PropertyUtils.getProperty(ex, "oracleError"); } catch (PropertyException e) { return null; } } return null; }
for (Method method : methods) { String name = method.getName(); if (method.getModifiers() == Modifier.PUBLIC && method.getParameterTypes().length == 0 && (name.startsWith("get") || name.startsWith("is")) && containsSetterForGetter(clazz, method)) { String propertyName; if (name.startsWith("get")) { if (propertyValue != null && propertyValue instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> propertiesContent = getNestedProperties(propertyName, (Map<String, Object>) propertyValue); properties.putAll(propertiesContent); } else {
@Override public XAConnection createXAConnection() throws JMSException { try { Class<?> clazz = ClassLoaderUtils.loadClass(connectionFactoryClassName); ConnectionFactory nonXaConnectionFactory = (ConnectionFactory) clazz.newInstance(); PropertyUtils.setProperties(nonXaConnectionFactory, properties); return new LrcXAConnection(nonXaConnectionFactory.createConnection()); } catch (Exception ex) { throw (JMSException) new JMSException("unable to connect to non-XA resource " + connectionFactoryClassName).initCause(ex); } }
private static Object callGetter(Object target, String propertyName) throws PropertyException { Method getter = getGetter(target, propertyName); try { return getter.invoke(target); } catch (IllegalAccessException ex) { throw new PropertyException("property '" + propertyName + "' is not accessible", ex); } catch (InvocationTargetException ex) { throw new PropertyException("property '" + propertyName + "' access threw an exception", ex); } }
/** * Get a direct or indirect property (dotted property: prop1.prop2.prop3) on the target object. * @param target the target object from which to get the property. * @param propertyName the name of the property to get. * @return the value of the specified property. * @throws PropertyException if an error happened while trying to get the property. */ public static Object getProperty(Object target, String propertyName) throws PropertyException { String[] propertyNames = propertyName.split("\\."); Object currentTarget = target; for (int i = 0; i < propertyNames.length; i++) { String name = propertyNames[i]; Object result = callGetter(currentTarget, name); if (result == null && i < propertyNames.length -1) { throw new PropertyException("cannot get property '" + propertyName + "' - '" + name + "' is null"); } currentTarget = result; } return currentTarget; }
/** * Set a {@link Map} of direct or indirect properties on the target object. * @param target the target object on which to set the properties. * @param properties a {@link Map} of String/Object pairs. * @throws PropertyException if an error happened while trying to set a property. */ public static void setProperties(Object target, Map<String, Object> properties) throws PropertyException { for (Map.Entry<String, Object> entry : properties.entrySet()) { String name = entry.getKey(); Object value = entry.getValue(); setProperty(target, name, value); } }
while (i < propertyNames.length -1) { String name = propertyNames[i]; Object result = callGetter(currentTarget, name); if (result == null) { Class<?> propertyType = getPropertyType(target, name); try { result = propertyType.newInstance(); throw new PropertyException("cannot set property '" + propertyName + "' - '" + name + "' is null and cannot be auto-filled", ex); callSetter(currentTarget, name, result); p.put(lastPropertyName, propertyValue.toString()); if (parentName != null) { callSetter(parentTarget, parentName, p); setDirectProperty(currentTarget, lastPropertyName, propertyValue);
/** * Return a comma-separated String of r/w properties of the specified object. * @param obj the object to introspect. * @return a a comma-separated String of r/w properties. */ public static String propertiesToString(Object obj) { StringBuilder sb = new StringBuilder(); Map<String, Object> properties = new TreeMap<String, Object>(getProperties(obj)); Iterator<String> it = properties.keySet().iterator(); while (it.hasNext()) { String property = it.next(); Object val = getProperty(obj, property); sb.append(property); sb.append("="); sb.append(val); if (it.hasNext()) { sb.append(", "); } } return sb.toString(); }