private BeanRuntimeInfo getWiredBeanRuntimeInfo() { if(wiredBeanRuntimeInfo == null) { // Don't need to synchronize this. Worse thing that can happen is we initialize it // more than once... no biggie... wiredBeanRuntimeInfo = BeanRuntimeInfo.getBeanRuntimeInfo(wireBeanIdName, appContext); } return wiredBeanRuntimeInfo; }
@Override public boolean equals(Object obj) { if(obj == null) { return false; } if(obj == this) { return true; } if(!(obj instanceof BeanRuntimeInfo)) { return false; } BeanRuntimeInfo beanInfo = (BeanRuntimeInfo) obj; if(beanInfo.getArrayType() != getArrayType()) { return false; } if(beanInfo.getClassification() != getClassification()) { return false; } if(beanInfo.getPopulateType() != getPopulateType()) { return false; } return true; }
public static BeanRuntimeInfo getBeanRuntimeInfo(String beanId, String beanClassName, ApplicationContext appContext) { Map<String, BeanRuntimeInfo> runtimeInfoMap = getRuntimeInfoMap(appContext); BeanRuntimeInfo beanRuntimeInfo = runtimeInfoMap.get(beanId); if(beanRuntimeInfo == null) { beanRuntimeInfo = new BeanRuntimeInfo(beanClassName); recordBeanRuntimeInfo(beanId, beanRuntimeInfo, appContext); } return beanRuntimeInfo; }
private Class<?> resolveBindTypeReflectively() throws DataDecodeException { String bindingMember = (setterMethod != null? setterMethod : property); if(bindingMember != null && beanRuntimeInfo.getClassification() == Classification.NON_COLLECTION) { Method bindingMethod = Bean.getBindingMethod(bindingMember, beanRuntimeInfo.getPopulateType()); if(bindingMethod != null) { return bindingMethod.getParameterTypes()[0]; } } return null; }
buildId(); beanRuntimeInfo = BeanRuntimeInfo.getBeanRuntimeInfo(beanIdName, appContext); isBeanWiring = (wireBeanIdName != null || wireBeanType != null || wireBeanAnnotation != null); isAttribute = (valueAttributeName != null); if(isBeanWiring && (beanRuntimeInfo.getClassification() == Classification.NON_COLLECTION || beanRuntimeInfo.getClassification() == Classification.MAP_COLLECTION)) { } else if(beanRuntimeInfo.getClassification() == Classification.NON_COLLECTION){ throw new SmooksConfigurationException("Binding configuration for beanIdName='" + beanIdName + "' must contain " + "either a 'property' or 'setterMethod' attribute definition, unless the target bean is a Collection/Array." + " Bean is type '" + beanRuntimeInfo.getPopulateType().getName() + "'."); if(beanRuntimeInfo.getClassification() == Classification.MAP_COLLECTION && property != null) { property = property.trim(); if(property.length() > 1 && property.charAt(0) == '@') {
Classification beanType = beanRuntimeInfo.getClassification(); } else if(propertySetterMethod == null) { if(setterMethod != null) { throw new SmooksConfigurationException("Bean [" + beanIdName + "] configuration invalid. Bean setter method [" + setterMethod + "(" + dataObject.getClass().getName() + ")] not found on type [" + beanRuntimeInfo.getPopulateType().getName() + "]. You may need to set a 'decoder' on the binding config."); } else if(property != null) { boolean throwException = true; if (beanRuntimeInfo.isJAXBType() && getWiredBeanRuntimeInfo().getClassification() != BeanRuntimeInfo.Classification.NON_COLLECTION) { throw new SmooksConfigurationException("Bean [" + beanIdName + "] configuration invalid. Bean setter method [" + ClassUtil.toSetterName(property) + "(" + dataObject.getClass().getName() + ")] not found on type [" + beanRuntimeInfo.getPopulateType().getName() + "]. You may need to set a 'decoder' on the binding config.");
beanRuntimeInfo = BeanRuntimeInfo.getBeanRuntimeInfo(beanIdName, beanClassName, appContext); } else if (beanRuntimeInfo.getClassification() == Classification.ARRAY_COLLECTION) { throw new SmooksConfigurationException("Using a factory with an array is not supported");
public boolean isCollection() { BeanRuntimeInfo.Classification classification = creator.getBeanRuntimeInfo().getClassification(); return (classification == Classification.COLLECTION_COLLECTION || classification == Classification.ARRAY_COLLECTION); }
public static void recordBeanRuntimeInfo(String beanId, BeanRuntimeInfo beanRuntimeInfo, ApplicationContext appContext) { Map<String, BeanRuntimeInfo> runtimeInfoMap = getRuntimeInfoMap(appContext); BeanRuntimeInfo existingBeanConfig = runtimeInfoMap.get(beanId); if(existingBeanConfig != null && !beanRuntimeInfo.equals(existingBeanConfig)) { throw new SmooksConfigurationException("Multiple configurations present with beanId='" + beanId + "', but the bean runtime infos are not equal i.e bean classes etc are different. Use a different beanId and the 'setOnMethod' config if needed."); } runtimeInfoMap.put(beanId, beanRuntimeInfo); }
/** * Checks if the class has a default constructor */ private void checkForDefaultConstructor() { try { beanRuntimeInfo.getPopulateType().getConstructor(); } catch (NoSuchMethodException e) { throw new SmooksConfigurationException("Invalid Smooks bean configuration. Bean class " + beanRuntimeInfo.getPopulateType().getName() + " doesn't have a public default constructor."); } }
public BeanRuntimeInfo(Class<?> clazz) { resolveBeanRuntimeInfo(clazz); }
public static BeanRuntimeInfo getBeanRuntimeInfo(String beanId, ApplicationContext appContext) { Map<String, BeanRuntimeInfo> runtimeInfoMap = getRuntimeInfoMap(appContext); return runtimeInfoMap.get(beanId); }
private Object convert(ExecutionContext executionContext, Object bean, Fragment source) { bean = BeanUtils.convertListToArray((List<?>)bean, beanRuntimeInfo.getArrayType()); executionContext.getBeanContext().changeBean(beanId, bean, source); return bean; }
/** * Assert that the beanClass associated with this configuration is an array or Collection. */ private void assertBeanClassIsCollection() { BeanRuntimeInfo beanRuntimeInfo = beanInstanceCreator.getBeanRuntimeInfo(); if (beanRuntimeInfo.getClassification() != BeanRuntimeInfo.Classification.COLLECTION_COLLECTION && beanRuntimeInfo.getClassification() != BeanRuntimeInfo.Classification.ARRAY_COLLECTION) { throw new IllegalArgumentException("Invalid call to a Collection/array Bean.bindTo method for a non Collection/Array target. Binding target type '" + beanRuntimeInfo.getPopulateType().getName() + "' (beanId '" + getBeanId() + "'). Use one of the Bean.bindTo methods that specify a 'bindingMember' argument."); } }
public void visitAfter(ExecutionContext executionContext, Fragment source) { Classification thisBeanType = beanRuntimeInfo.getClassification(); boolean isBeanTypeArray = (thisBeanType == Classification.ARRAY_COLLECTION); BeanContext beanContext = executionContext.getBeanContext(); beanContext.setBeanInContext(beanId, false); if(isBeanTypeArray) { Object bean = beanContext.getBean(beanId); if(logger.isDebugEnabled()) { logger.debug("Converting bean [" + beanIdName + "] to an array and rebinding to context."); } bean = convert(executionContext, bean, source); } }
public Class<?> getBeanClass() { return creator.getBeanRuntimeInfo().getPopulateType(); }
public BeanRuntimeInfo(String classname) { resolveBeanRuntimeInfo(classname); }
public void populateAndSetPropertyValue(Object bean, BeanContext beanContext, BeanId targetBeanId, final ExecutionContext executionContext, Fragment source) { BeanRuntimeInfo wiredBeanRI = getWiredBeanRuntimeInfo(); // When this observer is triggered then we look if we got something we can set immediately or that we got an array collection. // For an array collection, we need the array representation and not the list representation, so we register and observer that // listens for the change from the list to the array... if(wiredBeanRI != null && wiredBeanRI.getClassification() == Classification.ARRAY_COLLECTION ) { if(logger.isDebugEnabled()) { logger.debug("Registering bean CHANGE wiring observer for wiring bean '" + targetBeanId + "' onto target bean '" + beanId.getName() + "' after it has been converted from a List to an array."); } // Register an observer which looks for the change that the mutable list of the selected bean gets converted to an array. We // can then set this array beanContext.addObserver(listToArrayChangeObserver); } else { setPropertyValue(property, bean, executionContext, source); } }
private BeanRuntimeInfo getWiredBeanRuntimeInfo() { if(wiredBeanRuntimeInfo == null) { // Don't need to synchronize this. Worse thing that can happen is we initialize it // more than once... wiredBeanRuntimeInfo = BeanRuntimeInfo.getBeanRuntimeInfo(wireBeanIdName, appContext); } return wiredBeanRuntimeInfo; }
public Bean getModel(Class<?> beanType) { for(Bean model : models.values()) { if(model.getCreator().getBeanRuntimeInfo().getPopulateType() == beanType) { return model; } } return null; }