@SuppressWarnings("rawtypes") private Map<String, IComponentDescriptor<?>> buildContractNameIdMap() { Map<String, IComponentDescriptor<?>> map = new HashMap<>(); Map<String, IComponentDescriptor> idToComponentDescriptors = componentApplicationContext.getBeansOfType( IComponentDescriptor.class, false, false); for (Map.Entry<String, IComponentDescriptor> descriptorEntry : idToComponentDescriptors.entrySet()) { IComponentDescriptor componentDescriptor = descriptorEntry.getValue(); if (componentDescriptor.getComponentContract() != null) { map.put(componentDescriptor.getComponentContract().getName(), componentDescriptor); if (componentDescriptor.isTranslatable()) { ICollectionPropertyDescriptor<?> collectionPropertyDescriptor = (ICollectionPropertyDescriptor<?>) componentDescriptor .getPropertyDescriptor(AbstractComponentDescriptor.getComponentTranslationsDescriptorTemplate().getName()); if (collectionPropertyDescriptor != null) { IComponentDescriptor<?> translationComponentDescriptor = collectionPropertyDescriptor .getReferencedDescriptor().getElementDescriptor(); if (translationComponentDescriptor.getComponentContract() != null) { map.put(translationComponentDescriptor.getComponentContract().getName(), translationComponentDescriptor); } } } } } map.put(BasicDescriptorDescriptor.INSTANCE.getName(), BasicDescriptorDescriptor.INSTANCE); return map; } }
/** * Gets the new entity to add. It is created using the informations contained * in the context. * * @param context * the action context. * @return the entity to add to the collection. */ @Override @SuppressWarnings("unchecked") protected List<?> getAddedComponents(Map<String, Object> context) { IComponentDescriptor elementDescriptor = (IComponentDescriptor) context .get(ActionContextConstants.ELEMENT_DESCRIPTOR); if (elementDescriptor == null) { elementDescriptor = ((ICollectionPropertyDescriptor) getModelDescriptor(context)) .getReferencedDescriptor().getElementDescriptor(); } IEntity newEntity = getEntityFactory(context).createEntityInstance( (Class<? extends IEntity>) elementDescriptor.getComponentContract()); return Collections.singletonList(newEntity); } }
if (property == null) { property = collectionFactory.createComponentCollection( propertyDescriptor.getReferencedDescriptor().getCollectionInterface()); storeProperty(propertyName, property); IComponent referent = propertyAsList.get(i); IComponent decorated = decorateReferent(referent, propertyDescriptor.getReferencedDescriptor().getElementDescriptor().getComponentDescriptor()); if (decorated != referent) { propertyAsList.set(i, decorated); propertyDescriptor.getReferencedDescriptor().getElementDescriptor())) { if (decorated != null) { decorated.setOwningComponent((IComponent) proxy, propertyDescriptor); for (IComponent referent : new THashSet<>(propertyAsSet)) { IComponent decorated = decorateReferent(referent, propertyDescriptor.getReferencedDescriptor().getElementDescriptor().getComponentDescriptor()); if (decorated != referent) { propertyAsSet.add(decorated); propertyDescriptor.getReferencedDescriptor().getElementDescriptor())) { if (decorated != null) { decorated.setOwningComponent((IComponent) proxy, propertyDescriptor);
/** * Process. * * @param componentDescriptor * the component descriptor */ protected void process(IComponentDescriptor<?> componentDescriptor) { String compPermId = componentDescriptor.getPermId(); if (compPermId != null) { if (isPermIdExcluded(compPermId) || modelPermIds.contains(compPermId)) { return; } modelPermIds.add(compPermId); } for (IPropertyDescriptor propertyDescriptor : componentDescriptor.getPropertyDescriptors()) { process(propertyDescriptor, compPermId, modelPermIds); if (propertyDescriptor instanceof IRelationshipEndPropertyDescriptor) { if (propertyDescriptor instanceof IReferencePropertyDescriptor<?>) { process(((IReferencePropertyDescriptor<?>) propertyDescriptor).getReferencedDescriptor()); } else if (propertyDescriptor instanceof ICollectionPropertyDescriptor<?>) { process( ((ICollectionPropertyDescriptor<?>) propertyDescriptor).getReferencedDescriptor().getElementDescriptor()); } } } }
.getPropertyDescriptor(translationsPropertyName)).getReferencedDescriptor().getElementDescriptor() .getComponentContract(); ICollectionAccessor translationsAccessor = getAccessorFactory().
/** * Gets added element descriptor. * * @param context * the context * @return the added element descriptor */ protected IComponentDescriptor<?> getAddedElementDescriptor(Map<String, Object> context) { IComponentDescriptor<?> elementDescriptor; String collectionPropertyName = getModelDescriptor(context).getName(); Object master = getModelConnector(context).getModelProvider().getModel(); if (master instanceof IComponent) { // Component type should be refined depending on concrete master. See property translations for instance. elementDescriptor = ((ICollectionPropertyDescriptor<?>) getEntityFactory(context).getComponentDescriptor( ((IComponent) master).getComponentContract()).getPropertyDescriptor(collectionPropertyName)) .getReferencedDescriptor().getElementDescriptor(); } else { elementDescriptor = ((ICollectionPropertyDescriptor<?>) getModelDescriptor(context)).getReferencedDescriptor() .getElementDescriptor(); } return elementDescriptor; }
/** * Gets added element descriptor. * * @param context * the context * @return the added element descriptor */ protected IComponentDescriptor<?> getRemovedElementDescriptor(Map<String, Object> context) { IComponentDescriptor<?> elementDescriptor; String collectionPropertyName = getModelDescriptor(context).getName(); Object master = getModelConnector(context).getModelProvider().getModel(); if (master instanceof IComponent) { // Component type should be refined depending on concrete master. See property translations for instance. elementDescriptor = ((ICollectionPropertyDescriptor<?>) getEntityFactory(context).getComponentDescriptor( ((IComponent) master).getComponentContract()).getPropertyDescriptor(collectionPropertyName)) .getReferencedDescriptor().getElementDescriptor(); } else { elementDescriptor = ((ICollectionPropertyDescriptor<?>) getModelDescriptor(context)).getReferencedDescriptor() .getElementDescriptor(); } return elementDescriptor; } }
currentPropertyValue)) { currentPropertyValue = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[]{ ((ICollectionPropertyDescriptor<?>) propertyDescriptor).getReferencedDescriptor() .getCollectionInterface()}, new NeverEqualsInvocationHandler(CollectionHelper.cloneCollection((Collection<?>) currentPropertyValue)));
if (reversePropertyDescriptor instanceof IReferencePropertyDescriptor<?>) { accessorFactory.createPropertyAccessor(reversePropertyDescriptor.getName(), propertyDescriptor.getReferencedDescriptor().getElementDescriptor().getComponentContract()).setValue( value, proxy); } else if (reversePropertyDescriptor instanceof ICollectionPropertyDescriptor<?>) { ICollectionAccessor collectionAccessor = accessorFactory.createCollectionPropertyAccessor( reversePropertyDescriptor.getName(), propertyDescriptor.getReferencedDescriptor().getElementDescriptor().getComponentContract(), ((ICollectionPropertyDescriptor<?>) reversePropertyDescriptor).getCollectionDescriptor() .getElementDescriptor() propertyDescriptor.getReferencedDescriptor().getElementDescriptor())) { if (value != null) { ((IComponent) value).setOwningComponent((IComponent) proxy, propertyDescriptor);
} else if (collectionDescriptor.getReverseRelationEnd() instanceof ICollectionPropertyDescriptor<?>) { masterContract = ((ICollectionPropertyDescriptor<?>) collectionDescriptor.getReverseRelationEnd()) .getReferencedDescriptor().getElementDescriptor().getComponentContract();
if (reversePropertyDescriptor instanceof IReferencePropertyDescriptor<?>) { accessorFactory.createPropertyAccessor(reversePropertyDescriptor.getName(), propertyDescriptor.getReferencedDescriptor().getElementDescriptor().getComponentContract()).setValue( value, null); } else if (reversePropertyDescriptor instanceof ICollectionPropertyDescriptor<?>) { ICollectionAccessor collectionAccessor = accessorFactory.createCollectionPropertyAccessor( reversePropertyDescriptor.getName(), propertyDescriptor.getReferencedDescriptor().getElementDescriptor().getComponentContract(), ((ICollectionPropertyDescriptor<?>) reversePropertyDescriptor).getCollectionDescriptor() .getElementDescriptor() if (collectionProperty.remove(value)) { if (EntityHelper.isInlineComponentReference( propertyDescriptor.getReferencedDescriptor().getElementDescriptor())) { if (value != null) { ((IComponent) value).setOwningComponent(null, null);
private void checkMandatoryProperties(Object proxy) { if (propertyProcessorsEnabled) { for (IPropertyDescriptor propertyDescriptor : componentDescriptor.getPropertyDescriptors()) { if (!propertyDescriptor.isComputed()) { if (propertyDescriptor.isMandatory()) { Object newValue = straightGetProperty(proxy, propertyDescriptor.getName()); if (newValue == null || (isInitialized(newValue) && newValue instanceof Collection<?> && ((Collection<?>) newValue).isEmpty())) { throw new MandatoryPropertyException(propertyDescriptor, proxy); } } if (propertyDescriptor instanceof ICollectionPropertyDescriptor<?> && !((ICollectionPropertyDescriptor<?>) propertyDescriptor).getReferencedDescriptor() .isNullElementAllowed()) { Object newValue = straightGetProperty(proxy, propertyDescriptor.getName()); if (isInitialized(newValue) && newValue instanceof Collection<?>) { for (Object element : ((Collection<?>) newValue)) { if (element == null) { throw new MandatoryPropertyException(propertyDescriptor, proxy); } } } } } } } }
Object oldPropertyValue, Object newPropertyValue) { String propertyName = propertyDescriptor.getName(); if (EntityHelper.isInlineComponentReference(propertyDescriptor.getReferencedDescriptor().getElementDescriptor())) { if (oldPropertyValue instanceof Collection<?> && isInitialized(oldPropertyValue)) { for (IComponent component : (Collection<IComponent>) oldPropertyValue) {