/** * {@inheritDoc} */ public IAccessor createPropertyAccessor(String property, Class<?> beanClass) { return getAccessorDelegate(beanClass).createPropertyAccessor(property, beanClass); }
/** * {@inheritDoc} */ public ICollectionAccessor createCollectionPropertyAccessor(String property, Class<?> beanClass, Class<?> elementClass) { return getAccessorDelegate(beanClass).createCollectionPropertyAccessor( property, beanClass, elementClass); }
/** * {@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()); } } }
IAccessorFactory accessorFactory = accessorFactoryProvider.getAccessorFactory(); Object newValue = accessorFactory.createPropertyAccessor(prop, targetBeanComponentContract).getValue( targetBean); targetBean.firePropertyChange(prop, IPropertyChangeCapable.UNKNOWN, newValue);
ICollectionAccessor translationsAccessor = accessorFactory.createCollectionPropertyAccessor( translationsPropertyName, owningComponent.getClass(), target.getComponentContract()); try { translationsAccessor.removeFromValue(owningComponent, target); translationsAccessor.addToValue(owningComponent, newPropertyTranslation); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new NestedRuntimeException(e);
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()); } } }
private void registerDependsOnListeners(DependsOn dependsOn, IPropertyChangeCapable sourceBean, Method method, IAccessorFactoryProvider accessorFactoryProvider) { IAccessorFactory accessorFactory = accessorFactoryProvider.getAccessorFactory(); AccessorInfo accessorInfo = accessorFactory.getAccessorInfo(method); String targetProperty = accessorInfo.getAccessedPropertyName(); EAccessorType accessorType = accessorInfo.getAccessorType();
/** * {@inheritDoc} */ @Override public boolean isWritable() { boolean writable = super.isWritable(); if (accessor != null) { writable = writable && accessor.isWritable(); } if (getModelProvider() != null) { writable = writable && getModelProvider().getModel() != null; } return writable; }
elementContract = elt.getClass(); IAccessor accessor = accessorFactory.createPropertyAccessor( propertyName, elementContract); E modelValue = accessor.getValue(elt); eltOpen = shouldOpen(modelValue); if (!openOnTrue) {
/** * {@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()); } } }
private void unregisterDependsOnListeners(DependsOn dependsOn, IPropertyChangeCapable sourceBean, Method method, IAccessorFactoryProvider accessorFactoryProvider) { IAccessorFactory accessorFactory = accessorFactoryProvider.getAccessorFactory(); AccessorInfo accessorInfo = accessorFactory.getAccessorInfo(method); String targetProperty = accessorInfo.getAccessedPropertyName(); EAccessorType accessorType = accessorInfo.getAccessorType();
/** * {@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()); } }
/** * 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; }
/** * 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()); } }
try { String rawPropertyName = propertyDescriptor.getName() + IComponentDescriptor.RAW_SUFFIX; getAccessorFactory().createPropertyAccessor(rawPropertyName, getComponentDescriptor().getComponentContract()) .setValue(proxy, translatedValue); } catch (IllegalAccessException | NoSuchMethodException ex) { throw new ComponentException(ex);
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; }
.createPropertyAccessor(property, targetContract) .getValue(model); setActionParameter(propertyValue, context); } catch (IllegalAccessException | NoSuchMethodException ex) {
if (!Hibernate.isInitialized(newValue)) { IAccessor propertyAccessor = accessorFactory.createPropertyAccessor(propertyName, evt.getSource().getClass()); propertyAccessor.getValue(evt.getSource());
/** * 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; }