public void visitBefore(Element element, ExecutionContext executionContext) throws SmooksException { if(!beanExists(executionContext)) { logger.debug("Cannot bind data onto bean '" + beanId + "' as bean does not exist in BeanContext."); return; } if(isBeanWiring) { bindBeanValue(executionContext, new Fragment(element)); } else if(isAttribute) { // Bind attribute (i.e. selectors with '@' prefix) values on the visitBefore... bindDomDataValue(element, executionContext); } }
public void visitBefore(SAXElement element, ExecutionContext executionContext) throws SmooksException, IOException { if(!beanExists(executionContext)) { logger.debug("Cannot bind data onto bean '" + beanId + "' as bean does not exist in BeanContext."); return; } if(isBeanWiring) { bindBeanValue(executionContext, new Fragment(element)); } else if(isAttribute) { // Bind attribute (i.e. selectors with '@' prefix) values on the visitBefore... bindSaxDataValue(element, executionContext); } else if(expressionEvaluator == null || expressionHasDataVariable) { // It's not a wiring, attribute or expression binding => it's the element's text. // Turn on Text Accumulation... element.accumulateText(); } }
private void createPropertySetterMethod(Object bean, Class<?> parameter) { if (!checkedForSetterMethod && propertySetterMethod == null) { String methodName = null; if(setterMethod != null && !setterMethod.trim().equals("")) { methodName = setterMethod; } else if(property != null && !property.trim().equals("")) { methodName = ClassUtil.toSetterName(property); } if(methodName != null) { propertySetterMethod = createPropertySetterMethod(bean, methodName, parameter); } checkedForSetterMethod = true; } }
private void decodeAndSetPropertyValue(String mapPropertyName, Object dataObject, ExecutionContext executionContext, Fragment source) { if(dataObject instanceof String) { setPropertyValue(mapPropertyName, decodeDataString((String) dataObject, executionContext), executionContext, source); } else { setPropertyValue(mapPropertyName, dataObject, executionContext, source); } }
public void visitAfter(SAXElement element, ExecutionContext executionContext) throws SmooksException, IOException { if(!beanExists(executionContext)) { logger.debug("Cannot bind data onto bean '" + beanId + "' as bean does not exist in BeanContext."); return; } if(!isBeanWiring && !isAttribute) { bindSaxDataValue(element, executionContext); } }
public void visitAfter(Element element, ExecutionContext executionContext) throws SmooksException { if(!beanExists(executionContext)) { logger.debug("Cannot bind data onto bean '" + beanId + "' as bean does not exist in BeanContext."); return; } if(!isBeanWiring && !isAttribute) { bindDomDataValue(element, executionContext); } }
BeanInstancePopulator beanInstancePopulator = new BeanInstancePopulator(); SmooksResourceConfiguration populatorConfig = new SmooksResourceConfiguration(dataSelector); beanInstancePopulator.setBeanId(getBeanId()); beanInstancePopulator.setValueAttributeName(populatorConfig.getStringParameter(BeanInstancePopulator.VALUE_ATTRIBUTE_NAME)); beanInstancePopulator.setValueAttributePrefix(populatorConfig.getStringParameter(BeanInstancePopulator.VALUE_ATTRIBUTE_PREFIX)); beanInstancePopulator.setSetterMethod(bindingMethod.getName()); } else { beanInstancePopulator.setProperty(bindingMember); beanInstancePopulator.setProperty(bindingMember); beanInstancePopulator.setDecoder(dataDecoder);
AssertArgument.isNotNull(bean, "bean"); BeanInstancePopulator beanInstancePopulator = new BeanInstancePopulator(); beanInstancePopulator.setBeanId(getBeanId()); beanInstancePopulator.setWireBeanId(bean.getBeanId()); Method bindingMethod = getBindingMethod(bindingMember, beanClass); beanInstancePopulator.setSetterMethod(bindingMethod.getName()); } else { beanInstancePopulator.setProperty(bindingMember); beanInstancePopulator.setProperty(bindingMember);
/** * Create a binding configuration to bind the data, selected from the message by the * dataSelector, to the target Collection/array Bean beanclass instance. * * @param dataSelector The data selector for the data value to be bound. * @param dataDecoder The {@link org.dhatim.javabean.DataDecoder} to be used for decoding * the data value. * @return <code>this</code> Bean configuration instance. */ public Bean bindTo(String dataSelector, DataDecoder dataDecoder) { assertNotProcessed(); AssertArgument.isNotNull(dataSelector, "dataSelector"); // dataDecoder can be null BeanInstancePopulator beanInstancePopulator = new BeanInstancePopulator(); SmooksResourceConfiguration populatorConfig = new SmooksResourceConfiguration(dataSelector); SelectorPropertyResolver.resolveSelectorTokens(populatorConfig); // Configure the populator visitor... beanInstancePopulator.setBeanId(getBeanId()); beanInstancePopulator.setValueAttributeName(populatorConfig.getStringParameter(BeanInstancePopulator.VALUE_ATTRIBUTE_NAME)); beanInstancePopulator.setValueAttributePrefix(populatorConfig.getStringParameter(BeanInstancePopulator.VALUE_ATTRIBUTE_PREFIX)); beanInstancePopulator.setDecoder(dataDecoder); bindings.add(new Binding(populatorConfig.getSelector(), beanInstancePopulator, true)); return this; }
/** * Add a bean binding configuration to this Collection/array bean binding config. * <p/> * This method checks that this bean's beanClass is a Collection/array, generating an * {@link IllegalArgumentException} if the check fails. * * @param bean The Bean instance to be bound * @return <code>this</code> Bean configuration instance. * @throws IllegalArgumentException <u><code>this</code></u> Bean's beanClass (not the supplied bean!) is * not a Collection/array. You cannot call this method on Bean configurations whose beanClass is not a * Collection/array. For non Collection/array types, you must use one of the bindTo meths that specify a * 'bindingMember'. */ public Bean bindTo(Bean bean) throws IllegalArgumentException { assertNotProcessed(); AssertArgument.isNotNull(bean, "bean"); BeanInstancePopulator beanInstancePopulator = new BeanInstancePopulator(); // Configure the populator visitor... beanInstancePopulator.setBeanId(getBeanId()); beanInstancePopulator.setWireBeanId(bean.getBeanId()); bindings.add(new Binding(createOnElement, beanInstancePopulator, true)); wirings.add(bean); return this; }
private void bindDomDataValue(Element element, ExecutionContext executionContext) { String dataString; if (isAttribute) { if(valueAttributeNS != null) { dataString = DomUtils.getAttributeValue(element, valueAttributeName, valueAttributeNS); } else { dataString = DomUtils.getAttributeValue(element, valueAttributeName); } } else { dataString = DomUtils.getAllText(element, false); } String propertyName; if(mapKeyAttribute != null) { propertyName = DomUtils.getAttributeValue(element, mapKeyAttribute); if(propertyName == null) { propertyName = DomUtils.getName(element); } } else if(property != null) { propertyName = property; } else { propertyName = DomUtils.getName(element); } if(expressionEvaluator != null) { bindExpressionValue(propertyName, dataString, executionContext, new Fragment(element)); } else { decodeAndSetPropertyValue(propertyName, dataString, executionContext, new Fragment(element)); } }
createPropertySetterMethod(bean, dataObject.getClass()); boolean throwException = true; if (beanRuntimeInfo.isJAXBType() && getWiredBeanRuntimeInfo().getClassification() != BeanRuntimeInfo.Classification.NON_COLLECTION) {
buildId(); Class<?> bindingType = resolveBindTypeReflectively(); if(bindingType != null) { if(typeAlias != null) {
private void bindExpressionValue(String mapPropertyName, String dataString, ExecutionContext executionContext, Fragment source) { Map<String, Object> beanMap = executionContext.getBeanContext().getBeanMap(); Map<String, Object> variables = new HashMap<String, Object>(); if(expressionHasDataVariable) { variables.put(EXPRESSION_VALUE_VARIABLE_NAME, dataString); } Object dataObject = expressionEvaluator.exec(beanMap, variables); decodeAndSetPropertyValue(mapPropertyName, dataObject, executionContext, source); }
private void bindSaxDataValue(SAXElement element, ExecutionContext executionContext) { String propertyName; if(mapKeyAttribute != null) { propertyName = SAXUtil.getAttribute(mapKeyAttribute, element.getAttributes(), null); if(propertyName == null) { propertyName = element.getName().getLocalPart(); } } else if(property != null) { propertyName = property; } else { propertyName = element.getName().getLocalPart(); } String dataString = null; if(expressionEvaluator == null || expressionHasDataVariable) { if (isAttribute) { if(valueAttributeNS != null) { dataString = SAXUtil.getAttribute(valueAttributeNS, valueAttributeName, element.getAttributes(), null); } else { dataString = SAXUtil.getAttribute(valueAttributeName, element.getAttributes(), null); } } else { dataString = element.getTextContent(); } } if(expressionEvaluator != null) { bindExpressionValue(propertyName, dataString, executionContext, new Fragment(element)); } else { decodeAndSetPropertyValue(propertyName, dataString, executionContext, new Fragment(element)); } }