List of usage examples for java.beans PropertyDescriptor getShortDescription
public String getShortDescription()
From source file:com.twinsoft.convertigo.beans.core.MySimpleBeanInfo.java
protected PropertyDescriptor getPropertyDescriptor(String name) throws IntrospectionException { checkAdditionalProperties();//from www .j a v a 2 s . c o m 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:ca.sqlpower.architect.swingui.TestPlayPen.java
/** * Checks that the properties of an instance from the copy constructor are equal to the original. * In the case of a mutable property, it also checks that they don't share the same instance. * //from w w w .j ava 2s . c om * @throws Exception */ public void testCopyConstructor() throws Exception { List<PropertyDescriptor> settableProperties = Arrays .asList(PropertyUtils.getPropertyDescriptors(pp.getClass())); Set<String> copyIgnoreProperties = new HashSet<String>(); copyIgnoreProperties.add("UI"); copyIgnoreProperties.add("UIClassID"); copyIgnoreProperties.add("accessibleContext"); copyIgnoreProperties.add("actionMap"); copyIgnoreProperties.add("alignmentX"); copyIgnoreProperties.add("alignmentY"); copyIgnoreProperties.add("ancestorListeners"); copyIgnoreProperties.add("autoscrolls"); copyIgnoreProperties.add("border"); copyIgnoreProperties.add("class"); copyIgnoreProperties.add("component"); copyIgnoreProperties.add("componentPopupMenu"); copyIgnoreProperties.add("containerListeners"); copyIgnoreProperties.add("contentPane"); copyIgnoreProperties.add("cursorManager"); copyIgnoreProperties.add("debugGraphicsOptions"); copyIgnoreProperties.add("doubleBuffered"); copyIgnoreProperties.add("enabled"); copyIgnoreProperties.add("focusCycleRoot"); copyIgnoreProperties.add("focusTraversalKeys"); copyIgnoreProperties.add("focusTraversalPolicy"); copyIgnoreProperties.add("focusTraversalPolicyProvider"); copyIgnoreProperties.add("focusTraversalPolicySet"); copyIgnoreProperties.add("focusable"); copyIgnoreProperties.add("fontRenderContext"); copyIgnoreProperties.add("graphics"); copyIgnoreProperties.add("height"); copyIgnoreProperties.add("ignoreTreeSelection"); copyIgnoreProperties.add("inheritsPopupMenu"); copyIgnoreProperties.add("inputMap"); copyIgnoreProperties.add("inputVerifier"); copyIgnoreProperties.add("insets"); copyIgnoreProperties.add("layout"); copyIgnoreProperties.add("managingFocus"); copyIgnoreProperties.add("maximumSize"); copyIgnoreProperties.add("minimumSize"); copyIgnoreProperties.add("mouseMode"); copyIgnoreProperties.add("name"); copyIgnoreProperties.add("nextFocusableComponent"); copyIgnoreProperties.add("opaque"); copyIgnoreProperties.add("optimizedDrawingEnabled"); copyIgnoreProperties.add("paintingEnabled"); copyIgnoreProperties.add("paintingTile"); copyIgnoreProperties.add("panel"); copyIgnoreProperties.add("playPenContentPane"); copyIgnoreProperties.add("preferredScrollableViewportSize"); copyIgnoreProperties.add("preferredSize"); copyIgnoreProperties.add("registeredKeyStrokes"); copyIgnoreProperties.add("requestFocusEnabled"); copyIgnoreProperties.add("rootPane"); copyIgnoreProperties.add("scrollableTracksViewportHeight"); copyIgnoreProperties.add("scrollableTracksViewportWidth"); copyIgnoreProperties.add("selectedItems"); copyIgnoreProperties.add("selectedRelationShips"); copyIgnoreProperties.add("selectedTables"); copyIgnoreProperties.add("session"); copyIgnoreProperties.add("topLevelAncestor"); copyIgnoreProperties.add("toolTipText"); copyIgnoreProperties.add("transferHandler"); copyIgnoreProperties.add("usedArea"); copyIgnoreProperties.add("validateRoot"); copyIgnoreProperties.add("verifyInputWhenFocusTarget"); copyIgnoreProperties.add("vetoableChangeListeners"); copyIgnoreProperties.add("viewPosition"); copyIgnoreProperties.add("viewportSize"); copyIgnoreProperties.add("visible"); copyIgnoreProperties.add("visibleRect"); copyIgnoreProperties.add("width"); copyIgnoreProperties.add("x"); copyIgnoreProperties.add("y"); copyIgnoreProperties.add("draggingTablePanes"); copyIgnoreProperties.add("rubberBand"); // These should not be copied because any new PlayPen needs // different values or else it will not work on the new // PlayPen. copyIgnoreProperties.add("mouseZoomInAction"); copyIgnoreProperties.add("mouseZoomOutAction"); copyIgnoreProperties.add("scrollPane"); // we're not sure if zoom should be duplicated... // it might mess up printing?!?!? copyIgnoreProperties.add("zoom"); // individual lists (e.g. tables) checked instead copyIgnoreProperties.add("components"); // The copy of the play pen is for things like print preview, so we don't want to // duplicate menus and other interactive features. (?) copyIgnoreProperties.add("popupFactory"); //This property is specific to each play pen and it's settings will be re-calculated //regularly so it does not need to be copied. copyIgnoreProperties.add("criticismBucket"); // First pass: set all settable properties, because testing the duplication of // an object with all its properties at their defaults is not a // very convincing test of duplication! for (PropertyDescriptor property : settableProperties) { if (copyIgnoreProperties.contains(property.getName())) continue; Object oldVal; try { oldVal = PropertyUtils.getSimpleProperty(pp, property.getName()); // check for a setter if (property.getWriteMethod() != null) { Object newVal = getNewDifferentValue(property, oldVal); BeanUtils.copyProperty(pp, property.getName(), newVal); } } catch (NoSuchMethodException e) { logger.warn( "Skipping non-settable property " + property.getName() + " on " + pp.getClass().getName()); } } // Second pass get a copy make sure all of // the original mutable objects returned from getters are different // between the two objects, but have the same values. PlayPen duplicate = new PlayPen(pp.getSession(), pp); for (PropertyDescriptor property : settableProperties) { logger.info(property.getName() + property.getDisplayName() + property.getShortDescription()); if (copyIgnoreProperties.contains(property.getName())) continue; Object oldVal; try { oldVal = PropertyUtils.getSimpleProperty(pp, property.getName()); Object copyVal = PropertyUtils.getSimpleProperty(duplicate, property.getName()); if (oldVal == null) { throw new NullPointerException("We forgot to set " + property.getName()); } else { assertEquals("The two values for property " + property.getDisplayName() + " in " + pp.getClass().getName() + " should be equal", oldVal, copyVal); if (isPropertyInstanceMutable(property)) { assertNotSame("Copy shares mutable property with original, property name: " + property.getDisplayName(), copyVal, oldVal); } } } catch (NoSuchMethodException e) { logger.warn( "Skipping non-settable property " + property.getName() + " on " + pp.getClass().getName()); } } }
From source file:com.twinsoft.convertigo.beans.core.DatabaseObject.java
public Element toXml(Document document) throws EngineException { Element element = document.createElement(getDatabaseType().toLowerCase()); element.setAttribute("classname", getClass().getName()); if (exportOptions.contains(ExportOption.bIncludeVersion)) { element.setAttribute("version", com.twinsoft.convertigo.beans.Version.version); }/*from www . j a va 2 s .c o m*/ // Storing the database object priority element.setAttribute("priority", new Long(priority).toString()); int len; PropertyDescriptor[] propertyDescriptors; PropertyDescriptor propertyDescriptor; Element propertyElement; try { BeanInfo bi = CachedIntrospector.getBeanInfo(getClass()); propertyDescriptors = bi.getPropertyDescriptors(); len = propertyDescriptors.length; if (exportOptions.contains(ExportOption.bIncludeDisplayName)) { element.setAttribute("displayName", bi.getBeanDescriptor().getDisplayName()); } } catch (IntrospectionException e) { throw new EngineException("Couldn't introspect the bean \"" + getName() + "\"", e); } for (int i = 0; i < len; i++) { propertyDescriptor = propertyDescriptors[i]; String name = propertyDescriptor.getName(); String displayName = propertyDescriptor.getDisplayName(); String shortDescription = propertyDescriptor.getShortDescription(); Method getter = propertyDescriptor.getReadMethod(); // Only analyze read propertyDescriptors. if (getter == null) { continue; } if (checkBlackListParentClass(propertyDescriptor)) { continue; } try { // Storing the database object bean properties Object uncompiledValue = getCompilablePropertySourceValue(name); Object compiledValue = null; Object cypheredValue = null; Object value = getter.invoke(this); if (uncompiledValue != null) { compiledValue = value; value = uncompiledValue; } // Only write non-null values if (value == null) { Engine.logBeans.warn("Attempting to store null property (\"" + name + "\"); skipping..."); continue; } propertyElement = document.createElement("property"); propertyElement.setAttribute("name", name); // Encrypts value if needed //if (isCipheredProperty(name) && !this.exportOptions.contains(ExportOption.bIncludeDisplayName)) { if (isCipheredProperty(name) && (this.exportOptions.contains(ExportOption.bHidePassword) || !this.exportOptions.contains(ExportOption.bIncludeDisplayName))) { cypheredValue = encryptPropertyValue(value); if (!value.equals(cypheredValue)) { value = cypheredValue; propertyElement.setAttribute("ciphered", "true"); } } // Stores the value Node node = null; if (exportOptions.contains(ExportOption.bIncludeCompiledValue)) { node = XMLUtils.writeObjectToXml(document, value, compiledValue); } else { node = XMLUtils.writeObjectToXml(document, value); } propertyElement.appendChild(node); // Add visibility for logs if (!isTraceableProperty(name)) { propertyElement.setAttribute("traceable", "false"); } if (exportOptions.contains(ExportOption.bIncludeBlackListedElements)) { Object propertyDescriptorBlackListValue = propertyDescriptor .getValue(MySimpleBeanInfo.BLACK_LIST_NAME); if (propertyDescriptorBlackListValue != null && (Boolean) propertyDescriptorBlackListValue) { propertyElement.setAttribute("blackListed", "blackListed"); } } if (exportOptions.contains(ExportOption.bIncludeDisplayName)) { propertyElement.setAttribute("displayName", displayName); propertyElement.setAttribute("isHidden", Boolean.toString(propertyDescriptor.isHidden())); propertyElement.setAttribute("isMasked", isMaskedProperty(Visibility.Platform, name) ? "true" : "false"); propertyElement.setAttribute("isExpert", Boolean.toString(propertyDescriptor.isExpert())); } if (exportOptions.contains(ExportOption.bIncludeShortDescription)) { propertyElement.setAttribute("shortDescription", shortDescription); } if (exportOptions.contains(ExportOption.bIncludeEditorClass)) { Class<?> pec = propertyDescriptor.getPropertyEditorClass(); String message = ""; if (pec != null) { message = propertyDescriptor.getPropertyEditorClass().toString().replaceFirst("(.)*\\.", ""); } else { message = "null"; } if (this instanceof ITagsProperty || (pec != null && Enum.class.isAssignableFrom(pec))) { String[] sResults = null; try { if (this instanceof ITagsProperty) { sResults = ((ITagsProperty) this).getTagsForProperty(name); } else { sResults = EnumUtils.toNames(pec); } } catch (Exception ex) { sResults = new String[0]; } if (sResults != null) { if (sResults.length > 0) { Element possibleValues = document.createElement("possibleValues"); Element possibleValue = null; for (int j = 0; j < sResults.length; j++) { possibleValue = document.createElement("value"); possibleValue.setTextContent(sResults[j]); possibleValues.appendChild(possibleValue); } propertyElement.appendChild(possibleValues); } } } propertyElement.setAttribute("editorClass", message); } element.appendChild(propertyElement); if (Boolean.TRUE.equals(propertyDescriptor.getValue("nillable"))) { try { Method method = this.getClass().getMethod("isNullProperty", new Class[] { String.class }); Object isNull = method.invoke(this, new Object[] { name }); propertyElement.setAttribute("isNull", isNull.toString()); } catch (Exception ex) { Engine.logBeans.error( "[Serialization] Skipping 'isNull' attribute for property \"" + name + "\".", ex); } } } catch (Exception e) { Engine.logBeans.error("[Serialization] Skipping property \"" + name + "\".", e); } } return element; }
From source file:net.sourceforge.vulcan.web.struts.forms.PluginConfigForm.java
public void introspect(HttpServletRequest request) throws IntrospectionException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException { Class<?> cls = null;/*from w ww .j av a2s. co m*/ if ("pluginConfig".equals(focus)) { cls = pluginConfig.getClass(); this.breadCrumbs.clear(); this.breadCrumbs.add("Setup"); if (isProjectPlugin()) { this.breadCrumbs.add("Projects"); this.breadCrumbs.add(projectName); this.breadCrumbs.add(this.pluginConfig.getPluginName()); } else { this.breadCrumbs.add("Plugins"); this.breadCrumbs.add(this.pluginConfig.getPluginName()); } } else { cls = PropertyUtils.getPropertyType(this, focus); if (cls.isArray()) { cls = cls.getComponentType(); } } final String prefix = focus + "."; final PropertyDescriptor[] pds; if (PluginConfigDto.class.isAssignableFrom(cls)) { final PluginConfigDto pluginConfig = (PluginConfigDto) getFocusObject(); final List<PropertyDescriptor> tmp = pluginConfig.getPropertyDescriptors(request.getLocale()); pds = tmp.toArray(new PropertyDescriptor[tmp.size()]); if (pluginConfig instanceof PluginProfileDto) { ((PluginProfileDto) pluginConfig).checkPoint(); } } else { final BeanInfo beanInfo = Introspector.getBeanInfo(cls); Introspector.flushFromCaches(cls); pds = beanInfo.getPropertyDescriptors(); } if (isNested()) { for (PropertyDescriptor pd : propertyDescriptors) { if (focus.startsWith(pd.getName())) { breadCrumbs.add(pd.getDisplayName()); } } } types.clear(); choices.clear(); propertyDescriptors.clear(); hiddenPasswords.clear(); for (PropertyDescriptor pd : pds) { final String name = prefix + pd.getName(); final PropertyDescriptor cp = new PropertyDescriptor(pd.getName(), pd.getReadMethod(), pd.getWriteMethod()); cp.setShortDescription(pd.getShortDescription()); cp.setDisplayName(pd.getDisplayName()); cp.setName(name); propertyDescriptors.add(cp); types.put(name, getTypeAndPrepare(name, pd)); } putBreadCrumbsInRequest(request); }
From source file:org.ajax4jsf.builder.config.ComponentBaseBean.java
/** * Subclasses should extend this method to provide specifc checks * //w w w . jav a2 s. c om * Check existing and default properties * For properties filled from configuration, attempt to set additional parameters. * If base class have any bean properties, append it to configured * @throws ConfigurationException */ public void checkProperties() throws ParsingException { try { getLog().debug("Parse properties for Component " + getName() + " with superclass " + getSuperclass()); if (getSuperclass() != null) { Class<?> superClass = getLoader().loadClass(getSuperclass()); new ClassWalkingLogic(superClass).walk(new ClassVisitor() { public void visit(Class<?> clazz) { checkPropertiesForClass(clazz); } }); } } catch (ClassNotFoundException e) { getLog().error("superclass not found for component " + getName(), e); } if (null != getTag()) { try { Class superClass = getLoader().loadClass(getTag().getSuperclass()); PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(superClass); // for all properties, add it to component. If property have not abstract getter/setter , // add it with exist = true . If property in list of hidden names, set hidden = true. for (int i = 0; i < properties.length; i++) { PropertyDescriptor descriptor = properties[i]; Method writeMethod = descriptor.getWriteMethod(); if (containProperty(descriptor.getName())) { if (null != writeMethod && !Modifier.isAbstract(writeMethod.getModifiers()) && Modifier.isPublic(writeMethod.getModifiers())) { ((PropertyBean) this.properties.get(descriptor.getName())).setExistintag(true); } } else if (null != writeMethod && Modifier.isPublic(writeMethod.getModifiers())) { if (Arrays.asList(enabledTagProperties).contains(descriptor.getName())) { Class type = descriptor.getPropertyType(); getLog().debug("Register tag property " + descriptor.getName() + " with type name " + type.getCanonicalName()); PropertyBean property = new PropertyBean(); property.setName(descriptor.getName()); property.setDescription(descriptor.getShortDescription()); property.setDisplayname(descriptor.getDisplayName()); property.setClassname(descriptor.getPropertyType().getCanonicalName()); property.setExist(true); if (!Modifier.isAbstract(writeMethod.getModifiers())) { property.setExistintag(true); } addProperty(property); } } } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block getLog().error("superclass not found for tag " + getTag().getName(), e); } } }
From source file:org.ajax4jsf.builder.config.ComponentBaseBean.java
/** * @param superClass//w w w. j av a 2 s.co m */ private void checkPropertiesForClass(Class<?> superClass) { getLog().debug("Check properties for class " + superClass.getName()); // get all property descriptors PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(superClass); // for all properties, add it to component. If property have not abstract getter/setter , // add it with exist = true . If property in list of hidden names, set hidden = true. PropertyBean property; for (int i = 0; i < properties.length; i++) { PropertyDescriptor descriptor = properties[i]; if (!containProperty(descriptor.getName())) { if (isIgnorableProperty(superClass, descriptor.getName())) { continue; } Class<?> type = descriptor.getPropertyType(); getLog().debug("Register property " + descriptor.getName() + " with type name " + type.getCanonicalName()); property = new PropertyBean(); property.setName(descriptor.getName()); property.setDescription(descriptor.getShortDescription()); property.setDisplayname(descriptor.getDisplayName()); property.setClassname(descriptor.getPropertyType().getCanonicalName()); property.setExist(true); addProperty(property); } else { // Load and check property. getLog().debug("Check property " + descriptor.getName()); property = (PropertyBean) this.properties.get(descriptor.getName()); if (property.getClassname() == null) { property.setClassname(descriptor.getPropertyType().getCanonicalName()); } else { if (!property.getClassname().equals(descriptor.getPropertyType().getCanonicalName())) { String message = "Class " + property.getClassname() + " for property " + property.getName() + " not equals with real bean property type: " + descriptor.getPropertyType().getCanonicalName(); getLog().error(message); //throw new IllegalArgumentException(message); } } if (property.getDescription() == null) { property.setDescription(descriptor.getShortDescription()); } if (property.getDisplayname() == null) { property.setDisplayname(descriptor.getDisplayName()); } property.setExist(true); } Method getter = descriptor.getReadMethod(); Method setter = descriptor.getWriteMethod(); // Abstract methods if (null != setter && null != getter) { if ((Modifier.isAbstract(getter.getModifiers()) && Modifier.isAbstract(setter.getModifiers())) || superClass.isInterface()) { getLog().debug("Detect as abstract property " + descriptor.getName()); property.setExist(false); } } if (null == setter || (!Modifier.isPublic(setter.getModifiers()))) { getLog().debug("Detect as hidden property " + descriptor.getName()); property.setHidden(true); } if (isAttachedProperty(property)) { property.setAttachedstate(true); } if (property.isInstanceof("javax.faces.el.MethodBinding") || property.isInstanceof("javax.faces.el.ValueBinding")) { property.setElonly(true); } } }
From source file:org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer.java
private JLabel createLabel(PropertyDescriptor desc) { String text = desc.getDisplayName(); if (!"".equals(text)) { text = propertyFieldLabelMessage.format(new Object[] { desc.getDisplayName() }); }/*from w w w. j a v a 2 s . com*/ // if the displayName is the empty string, leave it like that. JLabel label = new JLabel(text); label.setHorizontalAlignment(SwingConstants.TRAILING); label.setToolTipText(propertyToolTipMessage.format(new Object[] { desc.getShortDescription() })); return label; }
From source file:org.catechis.Transformer.java
private static String getPDsFDsName(Object obj, String key) { String feature_descriptor = new String(); try {//from ww w . j a va 2 s . com PropertyDescriptor p_d = (PropertyDescriptor) PropertyUtils.getPropertyDescriptor(obj, key); feature_descriptor = p_d.getShortDescription(); } catch (java.lang.IllegalAccessException iae) { } catch (java.lang.reflect.InvocationTargetException ite) { } catch (java.lang.NoSuchMethodException nsme) { } return feature_descriptor; }
From source file:org.xmlactions.mapping.xml_to_bean.PopulateClassFromXml.java
public static PropertyDescriptor findPropertyDescriptor(Object object, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { PropertyDescriptor pd = null; PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(object); for (PropertyDescriptor p : pds) { if (p.getName().equals(name)) { pd = p;/* www. j a va 2 s. co m*/ break; } } if (pd != null) { log.debug("PropertyDescriptor [" + name + "] - " + " Name:" + pd.getName() + " DisplayName:" + pd.getDisplayName() + " ShortDescription:" + pd.getShortDescription() + " PropertyType:" + pd.getPropertyType() + " ReadMethod:" + pd.getReadMethod() + " WriteMethod:" + pd.getWriteMethod() + " Value:" + pd.getValue(name)); // } else { // log.error("PropertyDescriptor [" + name + // "] - not found in class [" + object.getClass().getName() + "]"); } return pd; }