/** * {@inheritDoc} */ public IAccessor createPropertyAccessor(String property, Class<?> beanClass) { return getAccessorDelegate(beanClass).createPropertyAccessor(property, beanClass); }
/** * {@inheritDoc} * * @param propertyName * the property name * @return the object */ @Override public Object get(String propertyName) { try { return accessorFactory.createPropertyAccessor(propertyName, getClass()).getValue(this); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { throw new ComponentException(ex, "Can not read component property " + propertyName + " on " + getClass().getName()); } }
/** * {@inheritDoc} * * @param propertyName * the property name * @param propertyValue * the property value */ @Override public void set(String propertyName, Object propertyValue) { try { accessorFactory.createPropertyAccessor(propertyName, getClass()).setValue(this, propertyValue); } catch (NoSuchMethodException | InvocationTargetException | IllegalArgumentException | IllegalAccessException ex) { throw new ComponentException(ex, "Can not write component property " + propertyName + " on " + getClass().getName()); } } }
/** * {@inheritDoc} */ @Override protected Object retrievePropertyValue(String propertyName) { try { return getAccessorFactory().createPropertyAccessor(propertyName, getComponentContract()).getValue(delegate); } catch (IllegalAccessException | NoSuchMethodException ex) { throw new ComponentException(ex); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } throw new ComponentException(ex.getCause()); } }
try { IAccessor sessionAccessor = getAccessorFactory() .createPropertyAccessor(sessionProperty, sessionContract); initValue = sessionAccessor.getValue(applicationSession); if (LOG.isDebugEnabled()) {
elementContract = elt.getClass(); IAccessor accessor = accessorFactory.createPropertyAccessor( propertyName, elementContract); E modelValue = accessor.getValue(elt);
private List<Serializable> extractQueryPropertyValues(IEntity entity, List<String> extraProps) { List<Serializable> values = new ArrayList<>(); values.add(entity.getId()); values.add(entity.toString()); if (extraProps != null) { for (String extraProp : extraProps) { try { Serializable extraPropValue = getComponentFactory().getAccessorFactory().createPropertyAccessor(extraProp, entity.getComponentContract()).getValue(entity); values.add(extraPropValue); } catch (IllegalAccessException | NoSuchMethodException ex) { throw new NestedRuntimeException(ex, "Invalid property: " + extraProp); } catch (InvocationTargetException ex) { throw new NestedRuntimeException(ex.getTargetException(), "Invalid property: " + extraProp); } } } return values; }
/** * {@inheritDoc} */ @Override protected void storeProperty(String propertyName, Object propertyValue) { try { getAccessorFactory().createPropertyAccessor(propertyName, getComponentContract()).setValue(delegate, propertyValue); } catch (IllegalAccessException | NoSuchMethodException ex) { throw new ComponentException(ex); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } throw new ComponentException(ex.getCause()); } } }
/** * To string. * * @param proxy * the proxy * @return the to string */ protected String toString(Object proxy) { try { String toStringPropertyName = componentDescriptor.getToStringProperty(); Object toStringValue = accessorFactory.createPropertyAccessor(toStringPropertyName, componentDescriptor.getComponentContract()).getValue(proxy); if (toStringValue == null) { return ""; } return toStringValue.toString(); } catch (IllegalAccessException | NoSuchMethodException ex) { throw new ComponentException(ex); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } throw new ComponentException(ex.getCause()); } }
Object propertyHolder; try { propertyHolder = getAccessorFactory().createPropertyAccessor(propertyName.substring(0, lastIndexOfDelim), getComponentContract()).getValue(proxy); if (propertyHolder != null && propertyHolder instanceof IComponent) {
if (!Hibernate.isInitialized(newValue)) { IAccessor propertyAccessor = accessorFactory.createPropertyAccessor(propertyName, evt.getSource().getClass());
/** * Create random entity * <p> * Uses pairs of field name and field values * - If pair is an array, select of value randomly * - If pair value is anything else, simply use this value * <p> * * @param entityContract * The entity contract * @param initializations * The list of pairs * @return The created entity */ protected <T extends IEntity> T createRandomEntity(Class<T> entityContract, Pair<String, Object>... initializations) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { T entity = createEntityInstance(entityContract); IAccessorFactory accessorFactory = getEntityFactory().getAccessorFactory(); for (Pair<String, Object> init : initializations) { Object value = init.getValue(); if (value instanceof Object[]) { value = randomSelection((Object[]) value); } IAccessor propertyAccessor = accessorFactory.createPropertyAccessor(init.getLeft(), entityContract); propertyAccessor.setValue(entity, value); } return entity; }
.getComponentContract(); for (String orderingProperty : orderingProperties) { orderingAccessors.add(accessorFactory.createPropertyAccessor( orderingProperty, collectionElementContract));
componentContract = component.getClass(); IAccessor accessor = accessorFactory.createPropertyAccessor(getReferencePath(context), componentContract); Object reference = accessor.getValue(component); if (reference instanceof Collection<?>) {
.createPropertyAccessor(property, targetContract) .getValue(model); setActionParameter(propertyValue, context);
if (property != null) { try { property = getAccessorFactory().createPropertyAccessor(nestedProperty, property.getClass()).getValue( property); } catch (IllegalAccessException | NoSuchMethodException e) {
try { String rawPropertyName = propertyDescriptor.getName() + IComponentDescriptor.RAW_SUFFIX; getAccessorFactory().createPropertyAccessor(rawPropertyName, getComponentDescriptor().getComponentContract()) .setValue(proxy, translatedValue); } catch (IllegalAccessException | NoSuchMethodException ex) {
/** * Saves the account information as well as the account devices. * <p> * {@inheritDoc} */ @Override public boolean execute( @SuppressWarnings("unused") IActionHandler actionHandler, Map<String, Object> context) { IEntity model = (IEntity) getModelConnector(context).getConnectorValue(); if (model != null) { try { Object propertyValue = getAccessorFactory(context) .createPropertyAccessor(property, model.getContract()).getValue( model); context.put(ActionContextConstants.ACTION_PARAM, propertyValue); } catch (IllegalAccessException ex) { throw new ActionException(ex); } catch (InvocationTargetException ex) { throw new ActionException(ex); } catch (NoSuchMethodException ex) { throw new ActionException(ex); } } return true; }
private void recomputeAccessor(Object newModel) { if (isValueAccessedAsProperty() && getModelProvider() != null && accessorFactory != null && (accessor == null || !accessor.appliesTo(newModel))) { Class<?> modelType = null; try { if (newModel != null) { if (newModel instanceof IComponent) { modelType = ((IComponent) newModel).getComponentContract(); } else { modelType = newModel.getClass(); } } else { modelType = getModelProvider().getModelDescriptor().getModelType(); } accessor = accessorFactory.createPropertyAccessor(getId(), modelType); } catch (Exception ex) { LOG.error( "An error occurred when creating the accessor for the {} property on {} class.", getId(), modelType, ex); } if (accessor instanceof IModelDescriptorAware) { ((IModelDescriptorAware) accessor) .setModelDescriptor(getModelDescriptor()); } } }
/** * {@inheritDoc} * * @param actionHandler * the action handler * @param context * the context * @return the boolean */ @Override public boolean execute(IActionHandler actionHandler, Map<String, Object> context) { Object selectedModel = getSelectedModel(context); Object username; try { username = getBackendController(context).getAccessorFactory().createPropertyAccessor(getUsernameProperty(), selectedModel.getClass()).getValue(selectedModel); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new ActionException(ex, "Could not extract username from model"); } context.put(AbstractResetPasswordAction.USERNAME_KEY, username); if (super.execute(actionHandler, context)) { getFrontendController(context).popupInfo(getSourceComponent(context), actionHandler.getTranslation("password.reset.title", getLocale(context)), getIconFactory(context).getInfoIconImageURL(), HtmlHelper.toHtml( actionHandler.getTranslation("password.reset.message", getLocale(context)) + HtmlHelper .emphasis((String) context.get(AbstractResetPasswordAction.GENERATED_PASSWORD_KEY)))); return true; } return false; }