List of usage examples for java.beans BeanInfo getBeanDescriptor
BeanDescriptor getBeanDescriptor();
From source file:com.twinsoft.convertigo.beans.core.MySimpleBeanInfo.java
public static String getIconName(BeanInfo bean, int iconType) { return bean != null ? (String) bean.getBeanDescriptor().getValue("icon" + iconType) : null; }
From source file:com.twinsoft.convertigo.engine.admin.services.database_objects.GetIcon.java
@Override protected void writeResponseResult(HttpServletRequest request, HttpServletResponse response) throws IOException, ServiceException { String className = request.getParameter("className"); if (className == null || !className.startsWith("com.twinsoft.convertigo.beans")) throw new ServiceException("Must provide className parameter", null); try {//w ww . j a v a2 s. c o m BeanInfo bi = CachedIntrospector .getBeanInfo(GenericUtils.<Class<? extends DatabaseObject>>cast(Class.forName(className))); IOUtils.copy( bi.getBeanDescriptor().getBeanClass() .getResourceAsStream(MySimpleBeanInfo.getIconName(bi, BeanInfo.ICON_COLOR_16x16)), response.getOutputStream()); } catch (Exception e) { throw new ServiceException("Icon unreachable", e); } Engine.logAdmin.info("The image has been exported"); }
From source file:org.senro.metadata.AOPMetadataManagerTest.java
/** * Test that the metadata recovery for the Class is correct * @throws Exception//from w w w . j a v a 2s .c o m */ public void testMetadataClass() throws Exception { Metadata result = metadataManager.getMetadata(A.class); BeanInfo beanInfo = Introspector.getBeanInfo(A.class); assertEquals("correct metadata retrieval", A.class, ((ReflectionMetadataClass) result).getType()); assertEquals("properties copy for reflective", beanInfo.getBeanDescriptor().getDisplayName(), ((ReflectionMetadataClass) result).getDisplayName()); }
From source file:kg.apc.jmeter.config.redis.RedisDataSet.java
/** * Override the setProperty method in order to convert * the original String calcMode property. * This used the locale-dependent display value, so caused * problems when the language was changed. * Note that the calcMode StringProperty is replaced with an IntegerProperty * so the conversion only needs to happen once. *///from w w w. j a va2 s. co m @Override public void setProperty(JMeterProperty property) { if (property instanceof StringProperty) { final String pn = property.getName(); if (pn.equals("getMode")) { final Object objectValue = property.getObjectValue(); try { final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass()); final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor() .getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE); for (Enum<GetMode> e : GetMode.values()) { final String propName = e.toString(); if (objectValue.equals(rb.getObject(propName))) { final int tmpMode = e.ordinal(); if (log.isDebugEnabled()) { log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode + " using Locale: " + rb.getLocale()); } super.setProperty(pn, tmpMode); return; } } log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale()); } catch (IntrospectionException e) { log.error("Could not find BeanInfo", e); } } else if (pn.equals("whenExhaustedAction")) { final Object objectValue = property.getObjectValue(); try { final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass()); final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor() .getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE); for (Enum<WhenExhaustedAction> e : WhenExhaustedAction.values()) { final String propName = e.toString(); if (objectValue.equals(rb.getObject(propName))) { final int tmpMode = e.ordinal(); if (log.isDebugEnabled()) { log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode + " using Locale: " + rb.getLocale()); } super.setProperty(pn, tmpMode); return; } } log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale()); } catch (IntrospectionException e) { log.error("Could not find BeanInfo", e); } } } super.setProperty(property); }
From source file:kg.apc.jmeter.listener.GraphsGeneratorListener.java
/** * Override the setProperty method in order to convert * the original String calcMode property. * This used the locale-dependent display value, so caused * problems when the language was changed. * Note that the calcMode StringProperty is replaced with an IntegerProperty * so the conversion only needs to happen once. */// w ww. j a va 2 s. c o m @Override public void setProperty(JMeterProperty property) { if (property instanceof StringProperty) { final String pn = property.getName(); if (pn.equals("exportMode")) { final Object objectValue = property.getObjectValue(); try { final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass()); final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor() .getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE); for (Enum<ExportMode> e : ExportMode.values()) { final String propName = e.toString(); if (objectValue.equals(rb.getObject(propName))) { final int tmpMode = e.ordinal(); if (log.isDebugEnabled()) { log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode + " using Locale: " + rb.getLocale()); } super.setProperty(pn, tmpMode); return; } } log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale()); } catch (IntrospectionException e) { log.error("Could not find BeanInfo", e); } } } super.setProperty(property); }
From source file:com.twinsoft.convertigo.beans.core.DatabaseObject.java
public DatabaseObject() { try {//from w ww . j a va 2 s . c o m BeanInfo bi = CachedIntrospector.getBeanInfo(getClass()); BeanDescriptor bd = bi.getBeanDescriptor(); setBeanName(StringUtils.normalize(bd.getDisplayName())); // normalize // bean // name // #283 identity = getNewOrderValue(); compilablePropertySourceValuesMap = new HashMap<String, Object>(5); } catch (Exception e) { name = getClass().getName(); Engine.logBeans .error("Unable to set the default name; using the class name instead (\"" + name + "\").", e); } }
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 w w w. j a v a2s . c om*/ // 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:com.twinsoft.convertigo.eclipse.ConvertigoPlugin.java
public synchronized Image getBeanIcon(BeanInfo bi, int iconKind) throws IntrospectionException { Class<?> beanClass = bi.getBeanDescriptor().getBeanClass(); String beanClassName = beanClass.getName(); Image beanIcon = icons.get(beanClassName + iconKind); if (beanIcon == null) { ConvertigoPlugin.studioLog.debug("Getting icon:" + beanClassName + iconKind); String iconName = MySimpleBeanInfo.getIconName(bi, iconKind); if (iconName == null) { iconName = "/com/twinsoft/convertigo/beans/core/images/default_color_32x32.png"; }/* w w w . java2 s.co m*/ Device device = getDisplay(); InputStream inputStream = ConvertigoPlugin.class.getResourceAsStream(iconName); if (inputStream != null) beanIcon = new Image(device, inputStream); if (beanIcon == null) beanIcon = getDefaultBeanIcon(beanClass, iconKind); icons.put(beanClassName + iconKind, beanIcon); } return beanIcon; }
From source file:org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer.java
/** * Create a customizer for a given test bean type. * * @param testBeanClass/*from ww w . j av a 2 s . co m*/ * a subclass of TestBean * @see org.apache.jmeter.testbeans.TestBean */ GenericTestBeanCustomizer(BeanInfo beanInfo) { super(); this.beanInfo = beanInfo; // Get and sort the property descriptors: descriptors = beanInfo.getPropertyDescriptors(); Arrays.sort(descriptors, new PropertyComparator(beanInfo)); // Obtain the propertyEditors: editors = new PropertyEditor[descriptors.length]; int scriptLanguageIndex = 0; int textAreaEditorIndex = 0; for (int i = 0; i < descriptors.length; i++) { // Index is also used for accessing editors array PropertyDescriptor descriptor = descriptors[i]; String name = descriptor.getName(); // Don't get editors for hidden or non-read-write properties: if (TestBeanHelper.isDescriptorIgnored(descriptor)) { log.debug("Skipping editor for property " + name); editors[i] = null; continue; } PropertyEditor propertyEditor; Object guiType = descriptor.getValue(GUITYPE); if (guiType instanceof TypeEditor) { propertyEditor = ((TypeEditor) guiType).getInstance(descriptor); } else if (guiType instanceof Class && Enum.class.isAssignableFrom((Class<?>) guiType)) { @SuppressWarnings("unchecked") // we check the class type above final Class<? extends Enum<?>> enumClass = (Class<? extends Enum<?>>) guiType; propertyEditor = new EnumEditor(descriptor, enumClass, (ResourceBundle) descriptor.getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE)); } else { Class<?> editorClass = descriptor.getPropertyEditorClass(); if (log.isDebugEnabled()) { log.debug("Property " + name + " has editor class " + editorClass); } if (editorClass != null) { try { propertyEditor = (PropertyEditor) editorClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { log.error("Can't create property editor.", e); throw new Error(e.toString()); } } else { Class<?> c = descriptor.getPropertyType(); propertyEditor = PropertyEditorManager.findEditor(c); } } if (propertyEditor == null) { log.warn("No editor for property: " + name + " type: " + descriptor.getPropertyType() + " in bean: " + beanInfo.getBeanDescriptor().getDisplayName()); editors[i] = null; continue; } if (log.isDebugEnabled()) { log.debug("Property " + name + " has property editor " + propertyEditor); } validateAttributes(descriptor, propertyEditor); if (!propertyEditor.supportsCustomEditor()) { propertyEditor = createWrapperEditor(propertyEditor, descriptor); if (log.isDebugEnabled()) { log.debug("Editor for property " + name + " is wrapped in " + propertyEditor); } } if (propertyEditor instanceof TestBeanPropertyEditor) { ((TestBeanPropertyEditor) propertyEditor).setDescriptor(descriptor); } if (propertyEditor instanceof TextAreaEditor) { textAreaEditorIndex = i; } if (propertyEditor.getCustomEditor() instanceof JScrollPane) { scrollerCount++; } editors[i] = propertyEditor; // Initialize the editor with the provided default value or null: setEditorValue(i, descriptor.getValue(DEFAULT)); if (name.equals("scriptLanguage")) { scriptLanguageIndex = i; } } // In case of BSF and JSR elements i want to add textAreaEditor as a listener to scriptLanguage ComboBox. String beanName = this.beanInfo.getBeanDescriptor().getName(); if (beanName.startsWith("BSF") || beanName.startsWith("JSR223")) { // $NON-NLS-1$ $NON-NLS-2$ WrapperEditor we = (WrapperEditor) editors[scriptLanguageIndex]; TextAreaEditor tae = (TextAreaEditor) editors[textAreaEditorIndex]; we.addChangeListener(tae); } // Obtain message formats: propertyFieldLabelMessage = new MessageFormat(JMeterUtils.getResString("property_as_field_label")); //$NON-NLS-1$ propertyToolTipMessage = new MessageFormat(JMeterUtils.getResString("property_tool_tip")); //$NON-NLS-1$ // Initialize the GUI: init(); }
From source file:org.apache.myfaces.application.ApplicationImpl.java
@Override public UIComponent createComponent(FacesContext context, Resource componentResource) { checkNull(context, "context"); checkNull(componentResource, "componentResource"); UIComponent component = null;//w w w .j a va 2 s.c o m Resource resource; String fqcn; Class<? extends UIComponent> componentClass = null; /* * Obtain a reference to the ViewDeclarationLanguage for this Application instance by calling * ViewHandler.getViewDeclarationLanguage(javax.faces.context.FacesContext, java.lang.String), passing the * viewId found by calling UIViewRoot.getViewId() on the UIViewRoot in the argument FacesContext. */ UIViewRoot view = context.getViewRoot(); Application application = context.getApplication(); ViewDeclarationLanguage vdl = application.getViewHandler().getViewDeclarationLanguage(context, view.getViewId()); /* * Obtain a reference to the composite component metadata for this composite component by calling * ViewDeclarationLanguage.getComponentMetadata(javax.faces.context.FacesContext, * javax.faces.application.Resource), passing the facesContext and componentResource arguments to this method. * This version of JSF specification uses JavaBeans as the API to the component metadata. */ BeanInfo metadata = vdl.getComponentMetadata(context, componentResource); if (metadata == null) { throw new FacesException("Could not get component metadata for " + componentResource.getResourceName() + ". Did you forget to specify <composite:interface>?"); } /* * Determine if the component author declared a component-type for this component instance by obtaining the * BeanDescriptor from the component metadata and calling its getValue() method, passing * UIComponent.COMPOSITE_COMPONENT_TYPE_KEY as the argument. If non-null, the result must be a ValueExpression * whose value is the component-type of the UIComponent to be created for this Resource component. Call through * to createComponent(java.lang.String) to create the component. */ BeanDescriptor descriptor = metadata.getBeanDescriptor(); ValueExpression componentType = (ValueExpression) descriptor .getValue(UIComponent.COMPOSITE_COMPONENT_TYPE_KEY); boolean annotationsApplied = false; if (componentType != null) { component = application.createComponent((String) componentType.getValue(context.getELContext())); annotationsApplied = true; } else { /* * Otherwise, determine if a script based component for this Resource can be found by calling * ViewDeclarationLanguage.getScriptComponentResource(javax.faces.context.FacesContext, * javax.faces.application.Resource). If the result is non-null, and is a script written in one of the * languages listed in JSF 4.3 of the specification prose document, create a UIComponent instance from the * script resource. */ resource = vdl.getScriptComponentResource(context, componentResource); if (resource != null) { String name = resource.getResourceName(); String className = name.substring(0, name.lastIndexOf('.')); component = (UIComponent) ClassUtils.newInstance(className); } else { /* * Otherwise, let library-name be the return from calling Resource.getLibraryName() on the argument * componentResource and resource-name be the return from calling Resource.getResourceName() on the * argument componentResource. Create a fully qualified Java class name by removing any file extension * from resource-name and let fqcn be library-name + "." + resource-name. If a class with the name of * fqcn cannot be found, take no action and continue to the next step. If any of * InstantiationException, * IllegalAccessException, or ClassCastException are thrown, wrap the exception in a FacesException and * re-throw it. If any other exception is thrown, log the exception and continue to the next step. */ boolean isProduction = FacesContext.getCurrentInstance().isProjectStage(ProjectStage.Production); String name = componentResource.getResourceName(); String className = name.substring(0, name.lastIndexOf('.')); fqcn = componentResource.getLibraryName() + "." + className; if (isProduction) { componentClass = (Class<? extends UIComponent>) _componentClassMap.get(fqcn); } if (componentClass == null) { try { componentClass = ClassUtils.classForName(fqcn); if (isProduction) { _componentClassMap.put(fqcn, componentClass); } } catch (ClassNotFoundException e) { // Remember here that classForName did not find Class if (isProduction) { _componentClassMap.put(fqcn, NOTHING.getClass()); } } } if (componentClass != null && NOTHING.getClass() != componentClass) { try { component = componentClass.newInstance(); } catch (InstantiationException e) { log.log(Level.SEVERE, "Could not instantiate component class name = " + fqcn, e); throw new FacesException("Could not instantiate component class name = " + fqcn, e); } catch (IllegalAccessException e) { log.log(Level.SEVERE, "Could not instantiate component class name = " + fqcn, e); throw new FacesException("Could not instantiate component class name = " + fqcn, e); } catch (Exception e) { log.log(Level.SEVERE, "Could not instantiate component class name = " + fqcn, e); } } /* * If none of the previous steps have yielded a UIComponent instance, call * createComponent(java.lang.String) passing "javax.faces.NamingContainer" as the argument. */ if (component == null) { component = application.createComponent(context, UINamingContainer.COMPONENT_TYPE, null); annotationsApplied = true; } } } /* * Call UIComponent.setRendererType(java.lang.String) on the UIComponent instance, passing * "javax.faces.Composite" as the argument. */ component.setRendererType("javax.faces.Composite"); /* * Store the argument Resource in the attributes Map of the UIComponent under the key, * Resource.COMPONENT_RESOURCE_KEY. */ component.getAttributes().put(Resource.COMPONENT_RESOURCE_KEY, componentResource); /* * Store composite component metadata in the attributes Map of the UIComponent under the key, * UIComponent.BEANINFO_KEY. */ component.getAttributes().put(UIComponent.BEANINFO_KEY, metadata); /* * Before the component instance is returned, it must be inspected for the presence of a * ListenerFor annotation. * If this annotation is present, the action listed in ListenerFor must be taken on the component, * before it is * returned from this method. */ if (!annotationsApplied) { _handleAnnotations(context, component, component); } return component; }