/** * Gets the interface class being the contract of this component. * * @return the component interface contract. */ public Class<?> getComponentContract() { return componentDescriptor.getComponentContract(); }
/** * {@inheritDoc} * * @return the query contract */ @Override @SuppressWarnings("unchecked") public <T> Class<T> getQueryContract() { if (componentDescriptor instanceof IQueryComponentDescriptor) { return (Class<T>) ((IQueryComponentDescriptor) componentDescriptor).getQueriedComponentsDescriptor() .getComponentContract(); } return (Class<T>) componentDescriptor.getComponentContract(); }
/** * {@inheritDoc} */ @Override public Class<?> getModelType() { return getReferencedDescriptor().getComponentContract(); }
/** * {@inheritDoc} */ @Override protected IComponent decorateReferent(IComponent referent, IComponentDescriptor<? extends IComponent> referentDescriptor) { if (Proxy.isProxyClass(referent.getClass()) && Proxy.getInvocationHandler(referent) instanceof AbstractComponentInvocationHandler) { return referent; } Class<? extends IComponent> componentContract = referentDescriptor.getComponentContract(); return componentFactory.createComponentInstance( componentContract, delegate); }
/** * Sets the viewDescriptors. * * @param viewDescriptors * the viewDescriptors to set. */ public void setViewDescriptors(List<IViewDescriptor> viewDescriptors) { Map<String, IViewDescriptor> classCardMapping = new LinkedHashMap<String, IViewDescriptor>(); for (IViewDescriptor entityViewDescriptor : viewDescriptors) { classCardMapping.put(((IComponentDescriptor<?>) entityViewDescriptor .getModelDescriptor()).getComponentContract().getName(), entityViewDescriptor); } setCardViewDescriptors(classCardMapping); }
if (extraInterfaces != null) { implementedClasses = new Class<?>[extraInterfaces.length + 2]; implementedClasses[0] = componentDescriptor.getComponentContract(); implementedClasses[1] = ILifecycleCapable.class; System.arraycopy(extraInterfaces, 0, implementedClasses, 2, extraInterfaces.length); } else { implementedClasses = new Class<?>[2]; implementedClasses[0] = componentDescriptor.getComponentContract(); implementedClasses[1] = ILifecycleCapable.class;
@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; } }
private boolean invokeLifecycleAnnotatedServices(Object proxy, IComponentDescriptor<? extends IComponent> compDesc, Class<? extends Annotation> lifecycleAnnotation, Object[] args) { boolean interceptorResults = false; if (lifecycleAnnotation != null) { for (Class<?> interfaces : compDesc.getComponentContract().getInterfaces()) { for (Method serviceMethod : interfaces.getDeclaredMethods()) { Annotation annotation = serviceMethod.getAnnotation(lifecycleAnnotation); if (annotation != null) { try { Class<?>[] parameterTypes = serviceMethod.getParameterTypes(); Object[] reducedArgs = Arrays.copyOfRange(args, 0, parameterTypes.length); Object interceptorResult = MethodUtils.invokeMethod(proxy, serviceMethod.getName(), reducedArgs, parameterTypes); if (interceptorResult instanceof Boolean) { interceptorResults = interceptorResults || (Boolean) interceptorResult; } } 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()); } } } } } return interceptorResults; }
/** * Is sub module sticky. Never consider a bean module sticky if it holds a component that is a detail of the * collection module. * * @param subModule * the sub module * @return the boolean */ @Override public boolean isSubModuleSticky(Module subModule) { if (!isStarted()) { if (subModule instanceof BeanModule) { IComponentDescriptor<?> subModuleComponentDescriptor = ((BeanModule) subModule).getComponentDescriptor(); IComponentDescriptor<?> elementComponentDescriptor = getElementComponentDescriptor(); if (subModuleComponentDescriptor != null && elementComponentDescriptor != null && subModuleComponentDescriptor .getComponentContract().isAssignableFrom(elementComponentDescriptor.getComponentContract())) { return false; } } } return super.isSubModuleSticky(subModule); }
/** * Creates and registers an extension instance. * * @param extensionClass * the extension class. * @param proxy * the proxy to register the extension on. * @return the component extension. */ protected synchronized IComponentExtension<? extends IComponent> getExtensionInstance( Class<IComponentExtension<IComponent>> extensionClass, IComponent proxy) { IComponentExtension<IComponent> extension; if (componentExtensions == null) { componentExtensions = new THashMap<>(1, 1.0f); extension = null; } else { extension = componentExtensions.get(extensionClass); } if (extension == null) { extension = extensionFactory.createComponentExtension(extensionClass, componentDescriptor.getComponentContract(), proxy); componentExtensions.put(extensionClass, extension); configureExtension(extension); } return extension; }
/** * 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()); } }
/** * Gets the new entity to add. It is created using the information contained * in the context. * * @param context * the action context. * @return the entity to add to the collection. */ @SuppressWarnings("unchecked") @Override protected List<?> getAddedComponents(Map<String, Object> context) { IComponentDescriptor<?> elementDescriptor = getAddedElementDescriptor(context); IComponent newElement; if (elementDescriptor.isEntity()) { newElement = getEntityFactory(context).createEntityInstance( (Class<? extends IEntity>) elementDescriptor.getComponentContract()); } else { newElement = getEntityFactory(context).createComponentInstance( (Class<? extends IComponent>) elementDescriptor .getComponentContract()); } return Collections.singletonList(newElement); }
private Icon computeIcon(Class<?> modelClass) { Icon icon = null; for (IComponentDescriptor<?> componentDescriptor : componentDescriptors) { if (modelClass.equals(componentDescriptor.getComponentContract()) && componentDescriptor.getIcon() != null) { icon = componentDescriptor.getIcon(); } } if (icon == null) { Class<?>[] superInterfaces = modelClass.getInterfaces(); for (int i = superInterfaces.length - 1; i >= 0 && icon == null; i--) { icon = computeIcon(superInterfaces[i]); } if (icon == null && modelClass.getSuperclass() != null) { icon = computeIcon(modelClass.getSuperclass()); } } if (icon != null && icon.getDimension() == null) { icon.setDimension(defaultDimension); } return icon; } }
/** * 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); } }
/** * Creates a new entity to add to the projected object collection. * * @param actionHandler * the action handler (generally the controller). * @param context * the action context. * @return the created entity. */ @SuppressWarnings("unchecked") protected Object createNewModuleObject(IActionHandler actionHandler, Map<String, Object> context) { IComponentDescriptor projectedComponentDescriptor = ((ICollectionDescriptorProvider<?>) getModelDescriptor(context)) .getCollectionDescriptor().getElementDescriptor(); return getEntityFactory(context).createEntityInstance( (Class<? extends IEntity>) projectedComponentDescriptor .getComponentContract()); } }
/** * Creates a new entity to add to the projected object collection. * * @param actionHandler * the action handler (generally the controller). * @param context * the action context. * @return the created entity. */ @SuppressWarnings({"unchecked", "UnusedParameters"}) protected Object createNewModuleObject(IActionHandler actionHandler, Map<String, Object> context) { IComponentDescriptor<? extends IEntity> projectedDesc = ((ICollectionDescriptorProvider<IEntity>) getModelDescriptor(context)) .getCollectionDescriptor().getElementDescriptor(); Class<? extends IEntity> componentContract = projectedDesc.getComponentContract(); return getEntityFactory(context).createEntityInstance( componentContract); } }
try { String rawPropertyName = propertyDescriptor.getName() + IComponentDescriptor.RAW_SUFFIX; getAccessorFactory().createPropertyAccessor(rawPropertyName, getComponentDescriptor().getComponentContract()) .setValue(proxy, translatedValue); } catch (IllegalAccessException | NoSuchMethodException ex) {
private IValueConnector createColumnConnector(String columnId, IComponentDescriptor<?> descriptor) { IPropertyDescriptor propertyDescriptor = descriptor .getPropertyDescriptor(columnId); if (propertyDescriptor == null) { throw new ViewException("No property " + columnId + " defined for " + descriptor.getComponentContract()); } if (propertyDescriptor instanceof IReferencePropertyDescriptor) { return connectorFactory.createCompositeValueConnector(columnId, ((IReferencePropertyDescriptor<?>) propertyDescriptor) .getReferencedDescriptor().getToStringProperty()); } return connectorFactory.createValueConnector(propertyDescriptor.getName()); }
private IValueConnector createColumnConnector(String columnId, IComponentDescriptor<?> descriptor) { IPropertyDescriptor propertyDescriptor = descriptor .getPropertyDescriptor(columnId); if (propertyDescriptor == null) { throw new ViewException("No property " + columnId + " defined for " + descriptor.getComponentContract()); } if (propertyDescriptor instanceof IReferencePropertyDescriptor) { return connectorFactory.createCompositeValueConnector(columnId, ((IReferencePropertyDescriptor<?>) propertyDescriptor) .getReferencedDescriptor().getToStringProperty()); } return connectorFactory.createValueConnector(propertyDescriptor.getName()); }
private IValueConnector createColumnConnector(String columnId, IComponentDescriptor<?> descriptor) { IPropertyDescriptor propertyDescriptor = descriptor .getPropertyDescriptor(columnId); if (propertyDescriptor == null) { throw new ViewException("No property " + columnId + " defined for " + descriptor.getComponentContract()); } if (propertyDescriptor instanceof IReferencePropertyDescriptor) { return connectorFactory.createCompositeValueConnector(columnId, ((IReferencePropertyDescriptor<?>) propertyDescriptor) .getReferencedDescriptor().getToStringProperty()); } return connectorFactory.createValueConnector(propertyDescriptor.getName()); }