assertThat(property.getName(), is("status")); assertThat(property.getLabel(), is("Status")); assertThat(property.getType().equals(Status.class), is(true)); assertThat(property.isReadOnly(), is(true)); assertThat(property, is(findProperty(property.getName(), props))); assertValue(reflection, problem, property, status); assertThat(property.getName(), is("code")); assertThat(property.getLabel(), is("Code")); assertThat(property.getType().equals(Integer.TYPE), is(true)); assertThat(property.isReadOnly(), is(true)); assertValue(reflection, problem, property, code); assertThat(property.getName(), is("message")); assertThat(property.getLabel(), is("Message")); assertThat(property.getType().equals(I18n.class), is(true)); assertThat(property.isReadOnly(), is(true)); assertValue(reflection, problem, property, msg); assertThat(property.getName(), is("messageString")); assertThat(property.getLabel(), is("Message String")); assertThat(property.getType().equals(String.class), is(true)); assertThat(property.isReadOnly(), is(true)); assertValue(reflection, problem, property, msg.text(params)); assertThat(property.getName(), is("parameters")); assertThat(property.getLabel(), is("Parameters")); assertThat(property.getType().equals(Object[].class), is(true)); assertThat(property.isReadOnly(), is(true));
assertThat(property.getName(), is("identifier")); assertThat(property.getLabel(), is(CommonI18n.noMoreContent.text())); assertThat(property.getDescription(), is(CommonI18n.nullActivityMonitorTaskName.text())); assertThat(property.getCategory(), is(CommonI18n.noMoreContent.text())); assertThat(property.getType().equals(String.class), is(true)); assertThat(property.isReadOnly(), is(false)); assertThat(property, is(findProperty(property.getName(), props))); assertValue(reflection, structure, property, structure.getIdentifier()); assertThat(property.getName(), is("count")); assertThat(property.getLabel(), is("Count")); assertThat(property.getDescription(), is("This is the count")); assertThat(property.getCategory(), is("")); assertThat(property.getType().equals(Integer.TYPE), is(true)); assertThat(property.isReadOnly(), is(false)); assertValue(reflection, structure, property, structure.getCount()); assertThat(property.getName(), is("onFire")); assertThat(property.getLabel(), is("On Fire")); assertThat(property.getDescription(), is("")); assertThat(property.getCategory(), is("")); assertThat(property.getType().equals(Boolean.TYPE), is(true)); assertThat(property.isReadOnly(), is(true)); assertValue(reflection, structure, property, structure.isOnFire());
Property property = new Property(propertyName, label, description, category, readOnly, type, allowedValues); property.setInferred(inferred); return property;
Property property = new Property(propertyName, label, description, category, readOnly, type, allowedValues); property.setInferred(inferred); return property;
Property property = new Property(propertyName, label, description, category, readOnly, type, allowedValues); property.setInferred(inferred); return property;
/** * Create a new object property with the supplied parameters set. * * @param name the property name; may be null * @param label the human-readable property label; may be null * @param description the description for this property; may be null * @param category the category for this property; may be null * @param readOnly true if the property is read-only, or false otherwise * @param type the value class; may be null * @param allowedValues the array of allowed values, or null or empty if the values are not constrained */ public Property( String name, String label, String description, String category, boolean readOnly, Class<?> type, Object... allowedValues ) { setName(name); if (label != null) setLabel(label); if (description != null) setDescription(description); setCategory(category); setReadOnly(readOnly); setType(type); setAllowedValues(allowedValues); }
/** * Get representations for all of the Java properties on the supplied object. * * @param target the target on which the setter is to be called; may not be null * @return the map of all properties keyed by their name; never null * @throws NoSuchMethodException if a matching method is not found. * @throws SecurityException if access to the information is denied. * @throws IllegalAccessException if the setter method could not be accessed * @throws InvocationTargetException if there was an error invoking the setter method on the target * @throws IllegalArgumentException if 'target' is null, or if 'propertyName' is null or empty */ public Map<String, Property> getAllPropertiesByNameOn( Object target ) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { String[] propertyNames = findGetterPropertyNames(); Map<String, Property> results = new HashMap<String, Property>(); for (String propertyName : propertyNames) { if ("class".equals(propertyName)) continue; Property prop = getProperty(target, propertyName); results.put(prop.getName(), prop); } return results; }
/** * Create a new object property with the supplied parameters set. * * @param name the property name; may be null * @param label the human-readable property label; may be null * @param description the description for this property; may be null * @param category the category for this property; may be null * @param readOnly true if the property is read-only, or false otherwise * @param type the value class; may be null * @param allowedValues the array of allowed values, or null or empty if the values are not constrained */ public Property( String name, String label, String description, String category, boolean readOnly, Class<?> type, Object... allowedValues ) { setName(name); if (label != null) setLabel(label); if (description != null) setDescription(description); setCategory(category); setReadOnly(readOnly); setType(type); setAllowedValues(allowedValues); }
/** * Set the property on the supplied target object to the specified value. * * @param target the target on which the setter is to be called; may not be null * @param property the property that is to be set on the target * @param value the new value for the property * @throws NoSuchMethodException if a matching method is not found. * @throws SecurityException if access to the information is denied. * @throws IllegalAccessException if the setter method could not be accessed * @throws InvocationTargetException if there was an error invoking the setter method on the target * @throws IllegalArgumentException if 'target' is null, 'property' is null, or 'property.getName()' is null */ public void setProperty( Object target, Property property, Object value ) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { CheckArg.isNotNull(target, "target"); CheckArg.isNotNull(property, "property"); CheckArg.isNotNull(property.getName(), "property.getName()"); invokeSetterMethodOnTarget(property.getName(), target, value); }
/** * Set the property on the supplied target object to the specified value. * * @param target the target on which the setter is to be called; may not be null * @param property the property that is to be set on the target * @param value the new value for the property * @throws NoSuchMethodException if a matching method is not found. * @throws SecurityException if access to the information is denied. * @throws IllegalAccessException if the setter method could not be accessed * @throws InvocationTargetException if there was an error invoking the setter method on the target * @throws IllegalArgumentException if 'target' is null, 'property' is null, or 'property.getName()' is null */ public void setProperty( Object target, Property property, Object value ) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { CheckArg.isNotNull(target, "target"); CheckArg.isNotNull(property, "property"); CheckArg.isNotNull(property.getName(), "property.getName()"); invokeSetterMethodOnTarget(property.getName(), target, value); }
/** * Set the property on the supplied target object to the specified value. * * @param target the target on which the setter is to be called; may not be null * @param property the property that is to be set on the target * @param value the new value for the property * @throws NoSuchMethodException if a matching method is not found. * @throws SecurityException if access to the information is denied. * @throws IllegalAccessException if the setter method could not be accessed * @throws InvocationTargetException if there was an error invoking the setter method on the target * @throws IllegalArgumentException if 'target' is null, 'property' is null, or 'property.getName()' is null */ public void setProperty( Object target, Property property, Object value ) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { CheckArg.isNotNull(target, "target"); CheckArg.isNotNull(property, "property"); CheckArg.isNotNull(property.getName(), "property.getName()"); invokeSetterMethodOnTarget(property.getName(), target, value); }
@Test public void shouldHaveProperties() throws Exception { Reflection reflection = new Reflection(source.getClass()); Property property = reflection.getProperty(source, "updatesAllowed"); assertThat(property.getDescription(), is(GraphI18n.updatesAllowedPropertyDescription.text())); assertThat(property.getLabel(), is(GraphI18n.updatesAllowedPropertyLabel.text())); assertThat(property.getCategory(), is(GraphI18n.updatesAllowedPropertyCategory.text())); assertThat(property.getCategory(), is("Advanced")); assertThat(property.isInferred(), is(false)); assertThat(property.isReadOnly(), is(true)); assertThat(property.isBooleanType(), is(true)); property = reflection.getProperty(source, "defaultCachePolicy"); assertThat(property.getDescription(), is("")); assertThat(property.getLabel(), is("Default Cache Policy")); assertThat(property.getCategory(), is("")); assertThat(property.isInferred(), is(true)); assertThat(property.isReadOnly(), is(false)); assertThat(property.isBooleanType(), is(false)); Map<String, Property> properties = reflection.getAllPropertiesByNameOn(source); assertThat(properties.containsKey("name"), is(true)); assertThat(properties.containsKey("jndiName"), is(true)); assertThat(properties.containsKey("defaultWorkspaceName"), is(true)); assertThat(properties.containsKey("predefinedWorkspaceNames"), is(true)); assertThat(properties.containsKey("updatesAllowed"), is(true)); assertThat(properties.containsKey("defaultCachePolicy"), is(true)); }
/** * Create a new object property with the supplied parameters set. * * @param name the property name; may be null * @param label the human-readable property label; may be null * @param description the description for this property; may be null * @param category the category for this property; may be null * @param readOnly true if the property is read-only, or false otherwise * @param type the value class; may be null * @param allowedValues the array of allowed values, or null or empty if the values are not constrained */ public Property( String name, String label, String description, String category, boolean readOnly, Class<?> type, Object... allowedValues ) { setName(name); if (label != null) setLabel(label); if (description != null) setDescription(description); setCategory(category); setReadOnly(readOnly); setType(type); setAllowedValues(allowedValues); }
/** * Get representations for all of the Java properties on the supplied object. * * @param target the target on which the setter is to be called; may not be null * @return the map of all properties keyed by their name; never null * @throws NoSuchMethodException if a matching method is not found. * @throws SecurityException if access to the information is denied. * @throws IllegalAccessException if the setter method could not be accessed * @throws InvocationTargetException if there was an error invoking the setter method on the target * @throws IllegalArgumentException if 'target' is null, or if 'propertyName' is null or empty */ public Map<String, Property> getAllPropertiesByNameOn( Object target ) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { String[] propertyNames = findGetterPropertyNames(); Map<String, Property> results = new HashMap<String, Property>(); for (String propertyName : propertyNames) { if ("class".equals(propertyName)) continue; Property prop = getProperty(target, propertyName); results.put(prop.getName(), prop); } return results; }
/** * Get representations for all of the Java properties on the supplied object. * * @param target the target on which the setter is to be called; may not be null * @return the map of all properties keyed by their name; never null * @throws NoSuchMethodException if a matching method is not found. * @throws SecurityException if access to the information is denied. * @throws IllegalAccessException if the setter method could not be accessed * @throws InvocationTargetException if there was an error invoking the setter method on the target * @throws IllegalArgumentException if 'target' is null, or if 'propertyName' is null or empty */ public Map<String, Property> getAllPropertiesByNameOn( Object target ) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { String[] propertyNames = findGetterPropertyNames(); Map<String, Property> results = new HashMap<String, Property>(); for (String propertyName : propertyNames) { if ("class".equals(propertyName)) continue; Property prop = getProperty(target, propertyName); results.put(prop.getName(), prop); } return results; }
/** * Get current value for the property on the supplied target object. * * @param target the target on which the setter is to be called; may not be null * @param property the property that is to be set on the target * @return the current value for the property; may be null * @throws NoSuchMethodException if a matching method is not found. * @throws SecurityException if access to the information is denied. * @throws IllegalAccessException if the setter method could not be accessed * @throws InvocationTargetException if there was an error invoking the setter method on the target * @throws IllegalArgumentException if 'target' is null, 'property' is null, or 'property.getName()' is null */ public Object getProperty( Object target, Property property ) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { CheckArg.isNotNull(target, "target"); CheckArg.isNotNull(property, "property"); CheckArg.isNotNull(property.getName(), "property.getName()"); return invokeGetterMethodOnTarget(property.getName(), target); }
/** * Get current value for the property on the supplied target object. * * @param target the target on which the setter is to be called; may not be null * @param property the property that is to be set on the target * @return the current value for the property; may be null * @throws NoSuchMethodException if a matching method is not found. * @throws SecurityException if access to the information is denied. * @throws IllegalAccessException if the setter method could not be accessed * @throws InvocationTargetException if there was an error invoking the setter method on the target * @throws IllegalArgumentException if 'target' is null, 'property' is null, or 'property.getName()' is null */ public Object getProperty( Object target, Property property ) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { CheckArg.isNotNull(target, "target"); CheckArg.isNotNull(property, "property"); CheckArg.isNotNull(property.getName(), "property.getName()"); return invokeGetterMethodOnTarget(property.getName(), target); }
/** * Get current value for the property on the supplied target object. * * @param target the target on which the setter is to be called; may not be null * @param property the property that is to be set on the target * @return the current value for the property; may be null * @throws NoSuchMethodException if a matching method is not found. * @throws SecurityException if access to the information is denied. * @throws IllegalAccessException if the setter method could not be accessed * @throws InvocationTargetException if there was an error invoking the setter method on the target * @throws IllegalArgumentException if 'target' is null, 'property' is null, or 'property.getName()' is null */ public Object getProperty( Object target, Property property ) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { CheckArg.isNotNull(target, "target"); CheckArg.isNotNull(property, "property"); CheckArg.isNotNull(property.getName(), "property.getName()"); return invokeGetterMethodOnTarget(property.getName(), target); }
protected Property findProperty( String propertyName, List<Property> properties ) { for (Property prop : properties) { if (prop.getName().equals(propertyName)) return prop; } return null; }