/** * {@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 public boolean isWritable() { boolean writable = super.isWritable(); if (accessor != null) { writable = writable && accessor.isWritable(); } if (getModelProvider() != null) { writable = writable && getModelProvider().getModel() != null; } return writable; }
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()); } } }
if (propertyDescriptor instanceof IRelationshipEndPropertyDescriptor) { getAccessorFactory().createPropertyAccessor(propertyName, componentContract).getValue(component); if (propertyDescriptor instanceof IReferencePropertyDescriptor && propertyValue instanceof IEntity) { if (((IRelationshipEndPropertyDescriptor) propertyDescriptor).isComposition()) { } else { getAccessorFactory().createPropertyAccessor(reversePropertyDescriptor.getName(), getComponentContract(((IComponent) propertyValue))).setValue(propertyValue, null); .getValue(propertyValue); ((ICollectionPropertyDescriptor<?>) reversePropertyDescriptor).preprocessRemover( propertyValue, reverseCollection, component); } else { getAccessorFactory().createPropertyAccessor(reversePropertyDescriptor.getName(), getComponentContract((IComponent) collectionElement)).setValue(collectionElement, null); getComponentContract((IComponent) collectionElement)).getValue(collectionElement); ((ICollectionPropertyDescriptor<?>) reversePropertyDescriptor).preprocessRemover( collectionElement, reverseCollection, component);
/** * Constructs a new {@code ComparableProperties} instance. * * @param sourceObject * the source object to compare properties. * @param orderingAccessors * the accessors to extract properties to compare. */ public ComparableProperties(Object sourceObject, List<IAccessor> orderingAccessors) { this.sourceObject = sourceObject; if (sourceObject != null) { valuesToCompare = new Object[orderingAccessors.size()]; for (int i = 0; i < valuesToCompare.length; i++) { try { valuesToCompare[i] = orderingAccessors.get(i).getValue(sourceObject); } catch (IllegalAccessException | NoSuchMethodException ex) { throw new MissingPropertyException(ex.getMessage()); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } throw new RuntimeException(ex.getCause()); } } } }
try { oldProperty = accessorFactory.createPropertyAccessor(propertyName, componentDescriptor.getComponentContract()) .getValue(proxy); } catch (IllegalAccessException | NoSuchMethodException ex) { throw new ComponentException(ex); .getComponentContract()); if (oldProperty != null) { reversePropertyAccessor.setValue(oldProperty, null); reversePropertyAccessor.setValue(actualNewProperty, proxy);
/** * {@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()); } } }
/** * Accesses the underlying model property and sets its value. * <p> * {@inheritDoc} */ @Override protected void setConnecteeValue(Object aValue) { if (!ObjectUtils.equals(aValue, getConnecteeValue())) { try { accessor.setValue(getModelProvider().getModel(), aValue); } catch (IllegalAccessException | NoSuchMethodException ex) { throw new ConnectorBindingException(ex); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } throw new ConnectorBindingException(ex.getCause()); } } } }
/** * Accesses the underlying model property and gets its value. * <p> * {@inheritDoc} */ @Override protected Object getConnecteeValue() { try { return accessor.getValue(getModelProvider().getModel()); } catch (IllegalAccessException ex) { throw new ConnectorBindingException(ex); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } throw new ConnectorBindingException(ex.getCause()); } catch (NoSuchMethodException ex) { // this may be a normal behaviour in case of polymorphism. // don't throw any exception. // throw new ConnectorBindingException(ex); return null; } }
accessor.setValue(component, initValue); if (LOG.isDebugEnabled()) { LOG.debug("Init value assigned.");
/** * {@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; }
E modelValue = accessor.getValue(elt); eltOpen = shouldOpen(modelValue); if (!openOnTrue) {
collectionConnector.getId(), targetContract).setValue(master, targetList); } catch (IllegalAccessException | NoSuchMethodException ex) {
IAccessor sessionAccessor = getAccessorFactory() .createPropertyAccessor(sessionProperty, sessionContract); initValue = sessionAccessor.getValue(applicationSession); if (LOG.isDebugEnabled()) { LOG.debug("Session contract : " + sessionContract.getName());
String rawPropertyName = propertyDescriptor.getName() + IComponentDescriptor.RAW_SUFFIX; getAccessorFactory().createPropertyAccessor(rawPropertyName, getComponentDescriptor().getComponentContract()) .setValue(proxy, translatedValue); } catch (IllegalAccessException | NoSuchMethodException ex) { throw new ComponentException(ex);
if (lastDotIndexOfReferencePath > 0) { refinedMasterComponent = accessorFactory.createPropertyAccessor( referencePath.substring(0, lastDotIndexOfReferencePath), masterComponentContract).getValue( masterComponent); masterComponentContract = getComponentContract(refinedMasterComponent); IAccessor masterAccessor = accessorFactory.createPropertyAccessor((String) initializedAttributeValue, masterComponentContract); initValue = masterAccessor.getValue(refinedMasterComponent); if (LOG.isDebugEnabled()) { LOG.debug("Master component contract : " + masterComponentContract.getName());