List of usage examples for java.beans PropertyDescriptor getName
public String getName()
From source file:de.erdesignerng.dialect.ModelItemProperties.java
public void copyTo(T aObject) { ModelProperties theProperties = aObject.getProperties(); try {//from w w w .j a v a 2s . c om for (PropertyDescriptor theDescriptor : PropertyUtils.getPropertyDescriptors(this)) { if (theDescriptor.getReadMethod() != null && theDescriptor.getWriteMethod() != null) { Object theValue = PropertyUtils.getProperty(this, theDescriptor.getName()); if (theValue != null) { theProperties.setProperty(theDescriptor.getName(), theValue.toString()); } else { theProperties.setProperty(theDescriptor.getName(), null); } } } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.twinsoft.convertigo.engine.admin.services.database_objects.Set.java
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception { Element root = document.getDocumentElement(); Document post = null;/* ww w . j a v a 2s . c om*/ Element response = document.createElement("response"); try { Map<String, DatabaseObject> map = com.twinsoft.convertigo.engine.admin.services.projects.Get .getDatabaseObjectByQName(request); xpath = new TwsCachedXPathAPI(); post = XMLUtils.parseDOM(request.getInputStream()); postElt = document.importNode(post.getFirstChild(), true); String objectQName = xpath.selectSingleNode(postElt, "./@qname").getNodeValue(); DatabaseObject object = map.get(objectQName); // String comment = getPropertyValue(object, "comment").toString(); // object.setComment(comment); if (object instanceof Project) { Project project = (Project) object; String objectNewName = getPropertyValue(object, "name").toString(); Engine.theApp.databaseObjectsManager.renameProject(project, objectNewName); map.remove(objectQName); map.put(project.getQName(), project); } BeanInfo bi = CachedIntrospector.getBeanInfo(object.getClass()); PropertyDescriptor[] propertyDescriptors = bi.getPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String propertyName = propertyDescriptor.getName(); Method setter = propertyDescriptor.getWriteMethod(); Class<?> propertyTypeClass = propertyDescriptor.getReadMethod().getReturnType(); if (propertyTypeClass.isPrimitive()) { propertyTypeClass = ClassUtils.primitiveToWrapper(propertyTypeClass); } try { String propertyValue = getPropertyValue(object, propertyName).toString(); Object oPropertyValue = createObject(propertyTypeClass, propertyValue); if (object.isCipheredProperty(propertyName)) { Method getter = propertyDescriptor.getReadMethod(); String initialValue = (String) getter.invoke(object, (Object[]) null); if (oPropertyValue.equals(initialValue) || DatabaseObject.encryptPropertyValue(initialValue).equals(oPropertyValue)) { oPropertyValue = initialValue; } else { object.hasChanged = true; } } if (oPropertyValue != null) { Object args[] = { oPropertyValue }; setter.invoke(object, args); } } catch (IllegalArgumentException e) { } } Engine.theApp.databaseObjectsManager.exportProject(object.getProject()); response.setAttribute("state", "success"); response.setAttribute("message", "Project have been successfully updated!"); } catch (Exception e) { Engine.logAdmin.error("Error during saving the properties!\n" + e.getMessage()); response.setAttribute("state", "error"); response.setAttribute("message", "Error during saving the properties!"); Element stackTrace = document.createElement("stackTrace"); stackTrace.setTextContent(e.getMessage()); root.appendChild(stackTrace); } finally { xpath.resetCache(); } root.appendChild(response); }
From source file:de.erdesignerng.dialect.ModelItemProperties.java
public void initializeFrom(T aObject) { ModelProperties theProperties = aObject.getProperties(); try {/*from w w w . j a v a2 s .c om*/ for (PropertyDescriptor theDescriptor : PropertyUtils.getPropertyDescriptors(this)) { if (theDescriptor.getReadMethod() != null && theDescriptor.getWriteMethod() != null) { String theValue = theProperties.getProperty(theDescriptor.getName()); if (!StringUtils.isEmpty(theValue)) { Class theType = theDescriptor.getPropertyType(); if (theType.isEnum()) { PropertyUtils.setProperty(this, theDescriptor.getName(), Enum.valueOf(theType, theValue)); } if (String.class.equals(theType)) { PropertyUtils.setProperty(this, theDescriptor.getName(), theValue); } if (Long.class.equals(theType) || long.class.equals(theType)) { PropertyUtils.setProperty(this, theDescriptor.getName(), Long.parseLong(theValue)); } if (Integer.class.equals(theType) || int.class.equals(theType)) { PropertyUtils.setProperty(this, theDescriptor.getName(), Integer.parseInt(theValue)); } if (Boolean.class.equals(theType) || boolean.class.equals(theType)) { PropertyUtils.setProperty(this, theDescriptor.getName(), Boolean.parseBoolean(theValue)); } } } } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.twinsoft.convertigo.beans.core.MySimpleBeanInfo.java
protected PropertyDescriptor getPropertyDescriptor(String name) throws IntrospectionException { checkAdditionalProperties();// www.ja va 2 s. com for (int i = 0; i < properties.length; i++) { PropertyDescriptor property = properties[i]; if (name.equals(property.getName())) { PropertyDescriptor clone = new PropertyDescriptor(name, property.getReadMethod(), property.getWriteMethod()); clone.setDisplayName(property.getDisplayName()); clone.setShortDescription(property.getShortDescription()); clone.setPropertyEditorClass(property.getPropertyEditorClass()); clone.setBound(property.isBound()); clone.setConstrained(property.isConstrained()); clone.setExpert(property.isExpert()); clone.setHidden(property.isHidden()); clone.setPreferred(property.isPreferred()); for (String attributeName : Collections.list(property.attributeNames())) { clone.setValue(attributeName, property.getValue(attributeName)); } return properties[i] = clone; } } return null; }
From source file:gr.abiss.calipso.uischema.serializer.UiSchemaSerializer.java
@Override public void serialize(UiSchema schema, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { try {/*w w w . j a va 2 s.c o m*/ Class domainClass = schema.getDomainClass(); if (null == domainClass) { throw new RuntimeException("formSchema has no domain class set"); } else { // start json jgen.writeStartObject(); // write superclass hint ModelResource superResource = (ModelResource) domainClass.getSuperclass() .getAnnotation(ModelResource.class); if (superResource != null) { jgen.writeFieldName("superPathFragment"); jgen.writeString(superResource.path()); } // write pathFragment ModelResource modelResource = (ModelResource) domainClass.getAnnotation(ModelResource.class); jgen.writeFieldName("pathFragment"); jgen.writeString(modelResource.path()); // write simple class name jgen.writeFieldName("simpleClassName"); jgen.writeString(domainClass.getSimpleName()); // start fields jgen.writeFieldName("fields"); jgen.writeStartObject(); PropertyDescriptor[] descriptors = new PropertyUtilsBean().getPropertyDescriptors(domainClass); for (int i = 0; i < descriptors.length; i++) { PropertyDescriptor descriptor = descriptors[i]; String name = descriptor.getName(); if (!ignoredFieldNames.contains(name)) { String fieldValue = this.getDataType(domainClass, descriptor, name); if (StringUtils.isNotBlank(fieldValue)) { jgen.writeFieldName(name); jgen.writeStartObject(); jgen.writeFieldName("fieldType"); jgen.writeString(fieldValue); jgen.writeEndObject(); } } } // end fields jgen.writeEndObject(); // end json jgen.writeEndObject(); } } catch (Exception e) { new RuntimeException("Failed serializing form schema", e); } }
From source file:com.urbanmania.spring.beans.factory.config.annotations.PropertyAnnotationAndPlaceholderConfigurer.java
public void registerBeanPropertyForUpdate(Class<?> beanClass, Property annotation, PropertyDescriptor property) { log.info("watching updates for property=[" + property.getPropertyType().getName() + "." + property.getName() + "] key=[" + annotation.key() + "]"); List<UpdateDescriptor> properties = updatableProperties.get(annotation.key()); if (properties == null) { properties = new ArrayList<UpdateDescriptor>(); }/*w ww. j av a 2s . c om*/ UpdateDescriptor descriptor = new UpdateDescriptor(); descriptor.setPropertyDescriptor(property); descriptor.setBeanClass(beanClass); properties.add(descriptor); updatableProperties.put(annotation.key(), properties); }
From source file:net.paoding.rose.jade.core.BeanPropertyRowMapper.java
/** * Initialize the mapping metadata for the given class. * /*from w w w .j av a2 s. c o m*/ */ protected void initialize() { this.mappedFields = new HashMap<String, PropertyDescriptor>(); PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(mappedClass); for (int i = 0; i < pds.length; i++) { PropertyDescriptor pd = pds[i]; if (pd.getWriteMethod() != null) { this.mappedProperties.add(pd.getName()); this.mappedFields.put(pd.getName().toLowerCase(), pd); for (String underscoredName : underscoreName(pd.getName())) { if (!pd.getName().toLowerCase().equals(underscoredName)) { this.mappedFields.put(underscoredName, pd); } } } } }
From source file:com.panguso.lc.analysis.format.dao.impl.DaoImpl.java
@Override public long searchCount(T condition) { StringBuilder qString = new StringBuilder( "select count(model) from " + entityClass.getSimpleName() + " model"); StringBuilder qWhere = new StringBuilder(" where "); StringBuilder qCondition = new StringBuilder(); PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(entityClass); for (int i = 0, count = propertyDescriptors.length; i < count; i++) { PropertyDescriptor propertyDescriptor = propertyDescriptors[i]; String name = propertyDescriptor.getName(); Class<?> type = propertyDescriptor.getPropertyType(); String value = null;// w w w. jav a 2 s. c om try { value = BeanUtils.getProperty(condition, name); } catch (Exception e) { // ? continue; } if (value == null || name.equals("class")) { continue; } if ("java.lang.String".equals(type.getName())) { qCondition.append("model."); qCondition.append(name); qCondition.append(" like "); qCondition.append("'%"); qCondition.append(value); qCondition.append("%'"); } else { qCondition.append("model."); qCondition.append(name); qCondition.append("="); qCondition.append(value); } qCondition.append(" and "); } if (qCondition.length() != 0) { qString.append(qWhere).append(qCondition); if (qCondition.toString().endsWith(" and ")) { qString.delete(qString.length() - " and ".length(), qString.length()); } } Query query = em.createQuery(qString.toString()); return (Long) query.getSingleResult(); }
From source file:org.jdal.swing.bind.AutoBinder.java
/** * Execute BinderCommand (update or refresh) for all model properties * @param command Command to execute.//from ww w . ja v a2 s. c om */ private void executeBinderCommand(BinderCommand command) { modelPropertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(model); // iterate on model properties for (PropertyDescriptor pd : modelPropertyAccessor.getPropertyDescriptors()) { String propertyName = pd.getName(); if (!ignoredProperties.contains(propertyName)) { ControlAccessor controlAccessor = getControlAccessor(propertyName); if (controlAccessor != null) command.execute(controlAccessor, propertyName); } } }
From source file:com.panguso.lc.analysis.format.dao.impl.DaoImpl.java
@Override public List<T> search(T condition, int pageNo, int pageSize) { StringBuilder qString = new StringBuilder("select model from " + entityClass.getSimpleName() + " model"); StringBuilder qWhere = new StringBuilder(" where "); StringBuilder qCondition = new StringBuilder(); PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(entityClass); for (int i = 0, count = propertyDescriptors.length; i < count; i++) { PropertyDescriptor propertyDescriptor = propertyDescriptors[i]; String name = propertyDescriptor.getName(); Class<?> type = propertyDescriptor.getPropertyType(); String value = null;/* www.ja v a 2 s. co m*/ try { value = BeanUtils.getProperty(condition, name); } catch (Exception e) { // ? continue; } if (value == null || name.equals("class")) { continue; } if ("java.lang.String".equals(type.getName())) { qCondition.append("model."); qCondition.append(name); qCondition.append(" like "); qCondition.append("'%"); qCondition.append(value); qCondition.append("%'"); } else { qCondition.append("model."); qCondition.append(name); qCondition.append("="); qCondition.append(value); } qCondition.append(" and "); } if (qCondition.length() != 0) { qString.append(qWhere).append(qCondition); if (qCondition.toString().endsWith(" and ")) { qString.delete(qString.length() - " and ".length(), qString.length()); } } Query query = em.createQuery(qString.toString()); query.setFirstResult(pageNo * pageSize); query.setMaxResults(pageSize); return query.getResultList(); }