/** * JavaBeansの値をJavaBeansにコピーします。 * * @param src ソース * @param dest あて先 * @param includeNull <code>null</code>を含めるかどうか */ public static void copyProperties( final Object src, final Object dest, final boolean includeNull) { final BeanDesc srcBeanDesc = BeanDescFactory.getBeanDesc(src.getClass()); final BeanDesc destBeanDesc = BeanDescFactory.getBeanDesc(dest.getClass()); final int propertyDescSize = destBeanDesc.getPropertyDescSize(); for (int i = 0; i < propertyDescSize; i++) { final PropertyDesc destPropertyDesc = destBeanDesc.getPropertyDesc(i); final String propertyName = destPropertyDesc.getPropertyName(); if (srcBeanDesc.hasPropertyDesc(propertyName)) { final PropertyDesc srcPropertyDesc = srcBeanDesc.getPropertyDesc(propertyName); if (destPropertyDesc.isWritable() && srcPropertyDesc.isReadable()) { final Object value = srcPropertyDesc.getValue(src); if (includeNull || value != null) { destPropertyDesc.setValue(dest, srcPropertyDesc.getValue(src)); } } } } }
protected void addAutoUpdateWhereBindVariables( List<Object> varList, List<ValueType> varValueTypeList, Object bean) { BeanMetaData bmd = getBeanMetaData(); for (int i = 0; i < bmd.getPrimaryKeySize(); ++i) { PropertyType pt = bmd.getPropertyTypeByColumnName(bmd.getPrimaryKey(i)); PropertyDesc pd = pt.getPropertyDesc(); varList.add(pd.getValue(bean)); varValueTypeList.add(pt.getValueType()); } if (bmd.hasVersionNoPropertyType()) { PropertyType pt = bmd.getVersionNoPropertyType(); PropertyDesc pd = pt.getPropertyDesc(); varList.add(pd.getValue(bean)); varValueTypeList.add(pt.getValueType()); } if (bmd.hasTimestampPropertyType()) { PropertyType pt = bmd.getTimestampPropertyType(); PropertyDesc pd = pt.getPropertyDesc(); varList.add(pd.getValue(bean)); varValueTypeList.add(pt.getValueType()); } }
/** * JavaBeansの値をマップにコピーします。 * * @param src ソース * @param dest あて先 */ public static void copyProperties(Object src, Map dest) { if (src == null || dest == null) { return; } final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(src.getClass()); final int size = beanDesc.getPropertyDescSize(); for (int i = 0; i < size; ++i) { final PropertyDesc pd = beanDesc.getPropertyDesc(i); if (pd.isReadable() && pd.isWritable()) { final Object value = pd.getValue(src); dest.put(pd.getPropertyName(), value); } } }
/** * JavaBeansの値からマップを作成します。 * * @param src ソース * @param prefix プレフィックス * @return JavaBeansの値を持つマップ */ public static Map createProperties(Object src, String prefix) { Map map = new HashMap(); if (src == null) { return map; } final BeanDesc beanDesc = BeanDescFactory.getBeanDesc(src.getClass()); final int size = beanDesc.getPropertyDescSize(); for (int i = 0; i < size; ++i) { final PropertyDesc pd = beanDesc.getPropertyDesc(i); if (pd.isReadable()) { if (prefix == null) { final Object value = pd.getValue(src); String name = pd.getPropertyName().replace('$', '.'); map.put(name, value); } else if (pd.getPropertyName().startsWith(prefix)) { final Object value = pd.getValue(src); String name = pd.getPropertyName().substring(prefix.length()).replace('$', '.'); map.put(name, value); } } } return map; }
/** * パラメータを準備します。 * * @param parameter パラメータ */ protected void prepareParameter(T parameter) { sqlContext = new SqlContextImpl(); if (parameter != null) { Class<?> clazz = parameter.getClass(); if (ValueTypes.isSimpleType(clazz) || TemporalParameter.class == clazz || LobParameter.class == clazz) { sqlContext.addArg("$1", parameter, clazz); } else if (parameter instanceof Map) { @SuppressWarnings("unchecked") Map<Object, Object> paramMap = (Map<Object, Object>) parameter; Set<Entry<Object, Object>> entrySet = paramMap.entrySet(); for (Map.Entry<Object, Object> entry : entrySet) { Object value = entry.getValue(); Object key = entry.getKey(); if (key == null || !(key instanceof CharSequence)) { continue; } String name = ((CharSequence) key).toString(); sqlContext.addArg(name, value, (value == null ? String.class : value.getClass())); } } else { BeanDesc beanDesc = BeanDescFactory.getBeanDesc(clazz); for (int i = 0; i < beanDesc.getPropertyDescSize(); i++) { PropertyDesc pd = beanDesc.getPropertyDesc(i); if (!pd.isReadable()) { continue; } Object value = Parameter.wrapIfNecessary(pd, pd.getValue(parameter)); sqlContext.addArg(pd.getPropertyName(), value, pd.getPropertyType()); } } } node.accept(sqlContext); Object[] vars = sqlContext.getBindVariables(); Class<?>[] types = sqlContext.getBindVariableTypes(); int size = vars.length; for (int i = 0; i < size; i++) { addParam(vars[i], types[i]); } }
public Object getValue() { Object value = super.getValue(); if (value instanceof SelectItem[] || value instanceof SelectItem) { return value; } List list = new ArrayList(); boolean nullLabelSet = false; if (nullLabelRequired) { SelectItem si = new SelectItem(); si.setValue(""); final FacesContext context = getFacesContext(); FacesMessage mes = FacesMessageUtil.getMessage(context, NULL_LABEL_MESSAGE_CODE, null); si.setLabel(mes.getSummary()); list.add(si); nullLabelSet = true; } if (value != null && value.getClass().isArray()) { value = Arrays.asList((Object[]) value); } if (value instanceof Collection) { final Collection valueCollection = (Collection) value; if (!nullLabelSet && valueCollection.size() == 0) { list.add(BLANK_SELECT_ITEM); } else { for (Iterator it = valueCollection.iterator(); it.hasNext(); ) { Object item = it.next(); if (item instanceof SelectItem) { list.add(item); } else if (item instanceof Map) { Map map = (Map) item; SelectItem si = new SelectItem(); Object itemValueValue = map.get(itemValue); if (itemValueValue != null) { si.setValue(itemValueValue); } Object itemLabelValue = map.get(itemLabel); if (itemLabelValue == null) { itemLabelValue = itemValueValue; } if (itemLabelValue != null) { si.setLabel(itemLabelValue.toString()); } list.add(si); } else { SelectItem si = new SelectItem(); BeanDesc bd = BeanDescFactory.getBeanDesc(item.getClass()); PropertyDesc pd = bd.getPropertyDesc(itemValue); Object itemValueValue = (pd.isReadable()) ? pd.getValue(item) : null; if (itemValueValue != null) { si.setValue(itemValueValue); } Object itemLabelValue = null; if (bd.hasPropertyDesc(itemLabel)) { pd = bd.getPropertyDesc(itemLabel); itemLabelValue = (pd.isReadable()) ? pd.getValue(item) : null; } if (itemLabelValue == null) { itemLabelValue = itemValueValue; } if (itemLabelValue != null) { si.setLabel(itemLabelValue.toString()); } list.add(si); } } } } else if (value instanceof Map) { final Map map = (Map) value; if (!nullLabelSet && map.size() == 0) { list.add(BLANK_SELECT_ITEM); } else { for (Iterator it = map.keySet().iterator(); it.hasNext(); ) { Object key = it.next(); Object val = map.get(key); SelectItem si = new SelectItem(); if (key != null) { si.setLabel(key.toString()); } if (val != null) { si.setValue(val); } list.add(si); } } } else { if (!nullLabelSet && value == null) { list.add(BLANK_SELECT_ITEM); } } return list; }