List of usage examples for java.beans PropertyDescriptor isHidden
public boolean isHidden()
From source file:net.sf.taverna.t2.workbench.ui.servicepanel.actions.AddServiceProviderAction.java
protected JPanel buildEditor(Configuration configuration) { List<String> uiBuilderConfig = new ArrayList<>(); int lastPreferred = 0; for (PropertyDescriptor property : getProperties(configuration)) { if (property.isHidden() || property.isExpert()) // TODO: Add support for expert properties continue; String propertySpec = property.getName() + ":name=" + property.getDisplayName(); if (property.isPreferred()) // Add it to the front uiBuilderConfig.add(lastPreferred++, propertySpec); else//from ww w . ja v a2 s. c o m uiBuilderConfig.add(propertySpec); } return UIBuilder.buildEditor(configuration, uiBuilderConfig.toArray(new String[0])); }
From source file:com.twinsoft.convertigo.beans.core.MySimpleBeanInfo.java
protected PropertyDescriptor getPropertyDescriptor(String name) throws IntrospectionException { checkAdditionalProperties();/*from w w w .ja va 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:com.googlecode.wicketwebbeans.model.BeanMetaData.java
private void init() { // Check if bean supports PropertyChangeListeners. hasAddPropertyChangeListenerMethod = getAddPropertyChangeListenerMethod() != null; hasRemovePropertyChangeListenerMethod = getRemovePropertyChangeListenerMethod() != null; String baseBeanClassName = getBaseClassName(beanClass); // Deduce actions from the component. List<Method> actionMethods = getActionMethods(component.getClass()); for (Method method : actionMethods) { String name = method.getName(); String prefixedName = ACTION_PROPERTY_PREFIX + name; String label = getLabelFromLocalizer(baseBeanClassName, prefixedName); if (label == null) { label = createLabel(name);/*from w ww . j a v a 2 s . c o m*/ } ElementMetaData actionMeta = new ElementMetaData(this, prefixedName, label, null); actionMeta.setAction(true); elements.add(actionMeta); } // Create defaults based on the bean itself. PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(beanClass); for (PropertyDescriptor descriptor : descriptors) { String name = descriptor.getName(); // Skip getClass() and methods that are not readable or hidden. if (name.equals("class") || descriptor.getReadMethod() == null || descriptor.isHidden()) { continue; } String label = getLabelFromLocalizer(baseBeanClassName, name); if (label == null) { label = descriptor.getDisplayName(); } if (label.equals(name)) { label = createLabel(name); } ElementMetaData propertyMeta = new ElementMetaData(this, name, label, descriptor.getReadMethod().getGenericReturnType()); propertyMeta.setViewOnly(isViewOnly()); elements.add(propertyMeta); if (descriptor.getWriteMethod() == null) { propertyMeta.setViewOnly(true); } deriveElementFromAnnotations(descriptor, propertyMeta); } // Collect various sources of metadata for the bean we're interested in. collectAnnotations(); collectFromBeanProps(); collectBeansAnnotation(beansMetaData, false); // Process action annotations on component. for (Method method : getActionMethods(component.getClass())) { Action action = method.getAnnotation(Action.class); processActionAnnotation(action, method.getName()); } // Determine the hierarchy of Bean contexts. I.e., the default Bean is always processed first, followed by those that // extend it, etc. This acts as a stack. List<Bean> beansHier = buildContextStack(); // Apply beans in order from highest to lowest. The default context will always be first. boolean foundSpecifiedContext = false; for (Bean bean : beansHier) { if (context != null && context.equals(bean.context())) { foundSpecifiedContext = true; } processBeanAnnotation(bean); } // Ensure that if a context was specified, that we found one in the metadata. Otherwise it might have been a typo. if (context != null && !foundSpecifiedContext) { throw new RuntimeException("Could not find specified context '" + context + "' in metadata."); } // Post-process Bean-level parameters if (!getBooleanParameter(PARAM_DISPLAYED)) { elements.clear(); tabs.clear(); } // Configure tabs if (tabs.isEmpty()) { // Create single default tab. tabs.add(new TabMetaData(this, DEFAULT_TAB_ID, getParameter(PARAM_LABEL))); } String defaultTabId = tabs.get(0).getId(); if (!getBooleanParameter(PARAM_EXPLICIT_ONLY) || defaultTabId.equals(DEFAULT_TAB_ID)) { // Post-process each property based on bean parameters for (ElementMetaData elementMeta : elements) { // If element is not on a tab, add it to the first. If it's an // action, it must have been assigned an order to // appear on a tab. Otherwise it is a global action. if (elementMeta.getTabId() == null && (!elementMeta.isAction() || (elementMeta.isAction() && elementMeta.isActionSpecifiedInProps()))) { elementMeta.setTabId(defaultTabId); } } } // Remove elements not specified in props if (getBooleanParameter(PARAM_EXPLICIT_ONLY)) { for (Iterator<ElementMetaData> iter = elements.iterator(); iter.hasNext();) { ElementMetaData element = iter.next(); if (!element.isSpecifiedInProps()) { iter.remove(); } } } Collections.sort(elements, new Comparator<ElementMetaData>() { public int compare(ElementMetaData o1, ElementMetaData o2) { return (o1.getOrder() > o2.getOrder() ? 1 : (o1.getOrder() < o2.getOrder() ? -1 : 0)); } }); }
From source file:com.ocs.dynamo.domain.model.impl.EntityModelFactoryImpl.java
/** * Constructs an attribute model for a property * /* w w w . j a v a 2 s . com*/ * @param descriptor * the property descriptor * @param entityModel * the entity model * @param parentClass * the type of the direct parent of the attribute (relevant in case of embedded * attributes) * @param nested * whether this is a nested attribute * @param prefix * the prefix to apply to the attribute name * @return */ private <T> List<AttributeModel> constructAttributeModel(PropertyDescriptor descriptor, EntityModelImpl<T> entityModel, Class<?> parentClass, boolean nested, String prefix) { List<AttributeModel> result = new ArrayList<AttributeModel>(); // validation methods annotated with @AssertTrue or @AssertFalse have to // be ignored String fieldName = descriptor.getName(); AssertTrue assertTrue = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, AssertTrue.class); AssertFalse assertFalse = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, AssertFalse.class); if (assertTrue == null && assertFalse == null) { AttributeModelImpl model = new AttributeModelImpl(); model.setEntityModel(entityModel); String displayName = DefaultFieldFactory.createCaptionByPropertyId(fieldName); // first, set the defaults model.setDisplayName(displayName); model.setDescription(displayName); model.setPrompt(displayName); model.setMainAttribute(descriptor.isPreferred()); model.setSearchable(descriptor.isPreferred()); model.setName((prefix == null ? "" : (prefix + ".")) + fieldName); model.setImage(false); model.setReadOnly(descriptor.isHidden()); model.setSortable(true); model.setComplexEditable(false); model.setPrecision(SystemPropertyUtils.getDefaultDecimalPrecision()); model.setSearchCaseSensitive(false); model.setSearchPrefixOnly(false); model.setUrl(false); model.setUseThousandsGrouping(true); Id idAttr = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, Id.class); if (idAttr != null) { entityModel.setIdAttributeModel(model); // the ID column is hidden. details collections are also hidden // by default model.setVisible(false); } else { model.setVisible(true); } model.setType(descriptor.getPropertyType()); // determine the possible date type model.setDateType(determineDateType(model.getType(), entityModel.getEntityClass(), fieldName)); // determine default display format model.setDisplayFormat(determineDefaultDisplayFormat(model.getType(), entityModel.getEntityClass(), fieldName, model.getDateType())); // determine if the attribute is required based on the @NotNull // annotation NotNull notNull = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, NotNull.class); model.setRequired(notNull != null); model.setAttributeType(determineAttributeType(parentClass, model)); // minimum and maximum length based on the @Size annotation Size size = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, Size.class); if (AttributeType.BASIC.equals(model.getAttributeType()) && size != null) { model.setMaxLength(size.max()); model.setMinLength(size.min()); } setNestedEntityModel(model); // only basic attributes are shown in the table by default model.setVisibleInTable( !nested && model.isVisible() && (AttributeType.BASIC.equals(model.getAttributeType()))); if (getMessageService() != null) { model.setTrueRepresentation(getMessageService().getMessage("ocs.true")); model.setFalseRepresentation(getMessageService().getMessage("ocs.false")); } // by default, use a combo box to look up model.setSelectMode(AttributeSelectMode.COMBO); model.setTextFieldMode(AttributeTextFieldMode.TEXTFIELD); model.setSearchSelectMode(AttributeSelectMode.COMBO); // is the field an email field? Email email = ClassUtils.getAnnotation(entityModel.getEntityClass(), fieldName, Email.class); model.setEmail(email != null); // override the defaults with annotation values setAnnotationOverrides(parentClass, model, descriptor, nested); // override any earlier version with message bundle contents setMessageBundleOverrides(entityModel, model); if (!model.isEmbedded()) { result.add(model); } else { // an embedded object is not directly added. Instead, its child // properties are added as attributes if (model.getType().equals(entityModel.getEntityClass())) { throw new IllegalStateException("Embedding a class in itself is not allowed"); } PropertyDescriptor[] embeddedDescriptors = BeanUtils.getPropertyDescriptors(model.getType()); for (PropertyDescriptor embeddedDescriptor : embeddedDescriptors) { String name = embeddedDescriptor.getName(); if (!skipAttribute(name)) { List<AttributeModel> embeddedModels = constructAttributeModel(embeddedDescriptor, entityModel, model.getType(), nested, model.getName()); result.addAll(embeddedModels); } } } } return result; }
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); }/* w w w . j a v a 2s . 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:org.archive.crawler.restlet.JobRelatedResource.java
/** * Constructs a nested Map data structure of the information represented * by {@code object}. The result is particularly suitable for use with with * {@link XmlMarshaller}.//from w ww . ja va2 s .c o m * * @param field * field name for object * @param object * object to make presentable map for * @param alreadyWritten * Set of objects already made presentable whose addition to the * Map should be suppressed * @param beanPathPrefix * beanPath prefix to apply to sub fields browse links * @return the presentable Map */ protected Map<String, Object> makePresentableMapFor(String field, Object object, HashSet<Object> alreadyWritten, String beanPathPrefix) { Map<String, Object> info = new LinkedHashMap<String, Object>(); Reference baseRef = getRequest().getResourceRef().getBaseRef(); String beanPath = beanPathPrefix; if (StringUtils.isNotBlank(field)) { info.put("field", field); if (StringUtils.isNotBlank(beanPathPrefix)) { if (beanPathPrefix.endsWith(".")) { beanPath += field; } else if (beanPathPrefix.endsWith("[")) { beanPath += field + "]"; } info.put("url", new Reference(baseRef, "../beans/" + TextUtils.urlEscape(beanPath)).getTargetRef()); } } String key = getBeanToNameMap().get(object); if (object == null) { info.put("propValue", null); return info; } if (object instanceof String || BeanUtils.isSimpleValueType(object.getClass()) || object instanceof File) { info.put("class", object.getClass().getName()); info.put("propValue", object); return info; } if (alreadyWritten.contains(object)) { info.put("propValuePreviouslyDescribed", true); return info; } alreadyWritten.add(object); // guard against repeats and cycles if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(field)) { info.put("key", key); info.put("url", new Reference(baseRef, "../beans/" + key).getTargetRef()); return info; } info.put("class", object.getClass().getName()); Collection<Object> properties = new LinkedList<Object>(); BeanWrapperImpl bwrap = new BeanWrapperImpl(object); for (PropertyDescriptor pd : getPropertyDescriptors(bwrap)) { if (pd.getReadMethod() != null && !pd.isHidden()) { String propName = pd.getName(); if (beanPath != null) { beanPathPrefix = beanPath + "."; } Object propValue = makePresentableMapFor(propName, bwrap.getPropertyValue(propName), alreadyWritten, beanPathPrefix); properties.add(propValue); } } if (properties.size() > 0) { info.put("properties", properties); } Collection<Object> propValues = new LinkedList<Object>(); if (object.getClass().isArray()) { // TODO: may want a special handling for an array of // primitive types? int len = Array.getLength(object); for (int i = 0; i < len; i++) { if (beanPath != null) { beanPathPrefix = beanPath + "["; } // TODO: protect against overlong content? propValues.add(makePresentableMapFor(i + "", Array.get(object, i), alreadyWritten, beanPathPrefix)); } } if (object instanceof List<?>) { List<?> list = (List<?>) object; for (int i = 0; i < list.size(); i++) { if (beanPath != null) { beanPathPrefix = beanPath + "["; } // TODO: protect against overlong content? try { propValues.add(makePresentableMapFor(i + "", list.get(i), alreadyWritten, beanPathPrefix)); } catch (Exception e) { LOGGER.warning(list + ".get(" + i + ") -" + e); } } } else if (object instanceof Iterable<?>) { for (Object next : (Iterable<?>) object) { propValues.add(makePresentableMapFor("#", next, alreadyWritten, beanPathPrefix)); } } if (object instanceof Map<?, ?>) { for (Object next : ((Map<?, ?>) object).entrySet()) { // TODO: protect against giant maps? Map.Entry<?, ?> entry = (Map.Entry<?, ?>) next; if (beanPath != null) { beanPathPrefix = beanPath + "["; } propValues.add(makePresentableMapFor(entry.getKey().toString(), entry.getValue(), alreadyWritten, beanPathPrefix)); } } if (propValues.size() > 0) { info.put("propValue", propValues); } return info; }
From source file:org.pentaho.reporting.engine.classic.core.util.beans.BeanUtility.java
public String[] getProperties() throws BeanException { final ArrayList<String> propertyNames = new ArrayList<String>(); final PropertyDescriptor[] pd = getPropertyInfos(); for (int i = 0; i < pd.length; i++) { final PropertyDescriptor property = pd[i]; if (property.isHidden()) { continue; }//from w w w. jav a 2s. c om if (property.getReadMethod() == null || property.getWriteMethod() == null) { // it will make no sense to write a property now, that // we can't read in later... continue; } if (BeanUtility.getPropertyType(property).isArray()) { final int max = findMaximumIndex(property); for (int idx = 0; idx < max; idx++) { propertyNames.add(property.getName() + '[' + idx + ']'); } } else { propertyNames.add(property.getName()); } } return propertyNames.toArray(new String[propertyNames.size()]); }