Refine search
if (bean instanceof DynaBean) { final DynaProperty[] descriptors = ((DynaBean) bean).getDynaClass().getDynaProperties(); for (DynaProperty descriptor : descriptors) { final String name = descriptor.getName(); description.put(name, getProperty(bean, name)); getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { final String name = descriptor.getName(); if (descriptor.getReadMethod() != null) { description.put(name, getProperty(bean, name));
final DynaClass dynaClass = ((DynaBean) target).getDynaClass(); final DynaProperty dynaProperty = dynaClass.getDynaProperty(propName); if (dynaProperty == null) { return null; // Skip this property setter type = dynaProperty.getType(); try { descriptor = getPropertyUtils().getPropertyDescriptor(target, name); if (descriptor == null) { return null; // Skip this property setter type = descriptor.getPropertyType();
getPropertyUtilsBean().getPropertyDescriptors(beanClass); if (regulars == null) { regulars = new PropertyDescriptor[0]; descriptorsMap.put(regulars[i].getName(), regulars[i]); properties[i] = new DynaProperty(regulars[i].getName(), regulars[i].getPropertyType()); propertiesMap.put(properties[i].getName(), properties[i]); (PropertyDescriptor) mappeds.get(name); properties[j] = new DynaProperty(descriptor.getName(), Map.class); propertiesMap.put(properties[j].getName(), properties[j]); j++;
/** * Writes this object safely. * There are issues with serializing primitive class types on certain JVM versions * (including java 1.3). * This method provides a workaround. */ private void writeObject(final ObjectOutputStream out) throws IOException { writeAnyClass(this.type,out); if (isMapped() || isIndexed()) { writeAnyClass(this.contentType,out); } // write out other values out.defaultWriteObject(); }
/** * Reads field values for this object safely. * There are issues with serializing primitive class types on certain JVM versions * (including java 1.3). * This method provides a workaround. * * @throws StreamCorruptedException when the stream data values are outside expected range */ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { this.type = readAnyClass(in); if (isMapped() || isIndexed()) { this.contentType = readAnyClass(in); } // read other values in.defaultReadObject(); }
/** * Determines the type of a {@code DynaProperty}. Here a special treatment * is needed for mapped properties. * * @param dynaProperty the property descriptor * @param value the value object to be set for this property * @return the type of this property */ private static Class<?> dynaPropertyType(final DynaProperty dynaProperty, final Object value) { if (!dynaProperty.isMapped()) { return dynaProperty.getType(); } return (value == null) ? String.class : value.getClass(); } }
((DynaBean) orig).getDynaClass().getDynaProperties(); for (DynaProperty origDescriptor : origDescriptors) { final String name = origDescriptor.getName(); if (isReadable(orig, name) && isWriteable(dest, name)) { try { final Object value = ((DynaBean) orig).get(name); if (dest instanceof DynaBean) { ((DynaBean) dest).set(name, value); } else { setSimpleProperty(dest, name, value); getPropertyDescriptors(orig); for (PropertyDescriptor origDescriptor : origDescriptors) { final String name = origDescriptor.getName(); if (isReadable(orig, name) && isWriteable(dest, name)) { try {
if (bean instanceof DynaBean) { final DynaProperty[] descriptors = ((DynaBean) bean).getDynaClass().getDynaProperties(); for (DynaProperty descriptor : descriptors) { final String name = descriptor.getName(); description.put(name, getProperty(bean, name)); getPropertyUtils().getPropertyDescriptors(bean); final Class<?> clazz = bean.getClass(); for (PropertyDescriptor descriptor : descriptors) { final String name = descriptor.getName(); if (getPropertyUtils().getReadMethod(clazz, descriptor) != null) { description.put(name, getProperty(bean, name));
public static Map<String, Object> toMap(Object bean) { if (bean == null) { return Collections.emptyMap(); } try { Map<String, Object> description = new HashMap<String, Object>(); if (bean instanceof DynaBean) { DynaProperty[] descriptors = ((DynaBean) bean).getDynaClass().getDynaProperties(); for (DynaProperty descriptor : descriptors) { String name = descriptor.getName(); description.put(name, BeanUtils.getProperty(bean, name)); } } else { PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { String name = descriptor.getName(); if (PropertyUtils.getReadMethod(descriptor) != null) { description.put(name, PropertyUtils.getNestedProperty(bean, name)); } } } return description; } catch (Exception e) { return Collections.emptyMap(); } }
/** * @return the type of the given attribute. By default just return * Object.class if this is not known. */ public Class getAttributeType(String name) throws JellyTagException { DynaProperty property = getDynaBean().getDynaClass().getDynaProperty(name); if (property != null) { return property.getType(); } return Object.class; }
/** * Returns the set of property values in the * decorated {@link DynaBean}. * * @return Unmodifiable collection of values. */ public Collection<Object> values() { final DynaProperty[] properties = getDynaProperties(); final List<Object> values = new ArrayList<Object>(properties.length); for (DynaProperty propertie : properties) { final String key = propertie.getName(); final Object value = getDynaBean().get(key); values.add(value); } return Collections.unmodifiableList(values); }
/** * Creates a new instance of {@code MultiWrapDynaBean} and initializes it * with the given collections of beans to be wrapped. * * @param beans the wrapped beans */ public MultiWrapDynaBean(final Collection<?> beans) { propsToBeans = new HashMap<>(); final Collection<DynaClass> beanClasses = new ArrayList<>(beans.size()); for (final Object bean : beans) { final DynaBean dynaBean = createDynaBean(bean); final DynaClass beanClass = dynaBean.getDynaClass(); for (final DynaProperty prop : beanClass.getDynaProperties()) { // ensure an order of properties if (!propsToBeans.containsKey(prop.getName())) { propsToBeans.put(prop.getName(), dynaBean); } } beanClasses.add(beanClass); } dynaClass = new MultiWrapDynaClass(beanClasses); }
/** * <p>Returns the Set of the property * names in the decorated {@link DynaBean}.</p> * * <p><b>N.B.</b>For {@link DynaBean}s whose associated {@link DynaClass} * is a {@link MutableDynaClass} a new Set is created every * time, otherwise the Set is created only once and cached.</p> * * @return An unmodifiable set of the {@link DynaBean}s * property names. */ public Set<K> keySet() { if (keySet != null) { return keySet; } // Create a Set of the keys final DynaProperty[] properties = getDynaProperties(); Set<K> set = new HashSet<K>(properties.length); for (DynaProperty propertie : properties) { set.add(convertKey(propertie.getName())); } set = Collections.unmodifiableSet(set); // Cache the keySet if Not a MutableDynaClass final DynaClass dynaClass = getDynaBean().getDynaClass(); if (!(dynaClass instanceof MutableDynaClass)) { keySet = set; } return set; }
final Class<?> contentType = getDynaClass().getDynaProperty(name).getContentType(); Object value = null; if (contentType != null) {
/** * Learn whether the property referenced is an indexed property. * @return boolean */ protected boolean isIndexedProperty() { DynaClass dynaClass = dynaBean.getDynaClass(); DynaProperty property = dynaClass.getDynaProperty(name); return property.isIndexed(); }
/** * Add a new dynamic property with no restrictions on data type, * readability, or writeability. * * @param name Name of the new dynamic property * * @throws IllegalArgumentException if name is null * @throws IllegalStateException if this DynaClass is currently * restricted, so no new properties can be added */ public void add(final String name) { add(new DynaProperty(name)); }
/** * <p>Copy the column values for each row in the specified * <code>ResultSet</code> into a newly created {@link DynaBean}, and add * this bean to the list of {@link DynaBean}s that will later by * returned by a call to <code>getRows()</code>.</p> * * @param resultSet The <code>ResultSet</code> whose data is to be * copied * * @throws SQLException if an error is encountered copying the data */ protected void copy(final ResultSet resultSet) throws SQLException { int cnt = 0; while (resultSet.next() && (limit < 0 || cnt++ < limit) ) { final DynaBean bean = createDynaBean(); for (DynaProperty propertie : properties) { final String name = propertie.getName(); final Object value = getObject(resultSet, name); bean.set(name, value); } rows.add(bean); } }
/** * Initializes the members related to the properties of the wrapped classes. * * @param wrappedCls the collection with the wrapped classes */ private void initProperties(final Collection<? extends DynaClass> wrappedCls) { for (final DynaClass cls : wrappedCls) { final DynaProperty[] props = cls.getDynaProperties(); for (final DynaProperty p : props) { properties.add(p); namedProperties.put(p.getName(), p); } } } }
public boolean contains(String property, String key) { if (!getDynaClass().getDynaProperty(property).isMapped()) throw new UnsupportedOperationException(); assert dynaClassInfo.isFunctional(property); SesameProperty sp = getSesameProperty(property); Map map = (Map) sp.getSingle(); if (map == null) return false; return map.containsKey(key); }