public Object getPropertyObj(Class<?> type, String name) { List<ComponentProperty> props = component.getProperties(); for (ComponentProperty prop : props) { if (prop.getName().equals(name)) { return propertyFactory.createPropertyValue(prop, type); } } return null; // property name not found } }
/** * Gets the value for the specified property with the specified type. * * @param type The type of the property value we are getting * @param propertyName The name of the property we are getting * @param B The class of the property value we are getting * * @throws ServiceRuntimeException If a Property for the specified propertyName * is not found * * @see #setPropertyValueFactory(PropertyValueFactory) */ public <B> B getProperty(Class<B> type, String propertyName) { for (ComponentProperty p : component.getProperties()) { if (propertyName.equals(p.getName())) { return propertyFactory.createPropertyValue(p, type); } } throw new IllegalArgumentException("Property not found: " + propertyName); }
/** * Method to create a Java Bean for a Property value * @param <B> the class type of the Bean * @param requiredType - a Class object for the required type * @param name - the Property name * @return - a Bean of the specified property, with value set */ private <B> B getPropertyBean(Class<?> requiredType, String name) { B propertyObject = null; // Get the component's list of properties List<ComponentProperty> props = component.getProperties(); for (ComponentProperty prop : props) { if (prop.getName().equals(name)) { // On finding the property, create a factory for it and create a Bean using // the factory propertyObject = (B)propertyFactory.createPropertyValue(prop, requiredType); } // end if } // end for return propertyObject; }