/** * Create a Bean binding configuration. * * @param beanClass The bean runtime class. * @param beanId The bean ID. * @param createOnElement The element selector used to create the bean instance. * @param createOnElementNS The namespace for the element selector used to create the bean instance. */ public static Bean newBean(Class<?> beanClass, String beanId, String createOnElement, String createOnElementNS) { return new Bean(beanClass, beanId, createOnElement, createOnElementNS); }
/** * 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. * @return <code>this</code> Bean configuration instance. */ public Bean bindTo(String dataSelector) { return bindTo(dataSelector, (DataDecoder) null); }
public void addVisitors(VisitorConfigMap visitorMap) { if(bindBeanId != null && bindBeanClass != null) { Bean bean; if(bindingType == CSVBindingType.LIST) { Bean listBean = new Bean(ArrayList.class, bindBeanId, "$document"); bean = listBean.newBean(bindBeanClass, recordElementName); listBean.bindTo(bean); addFieldBindings(bean); listBean.addVisitors(visitorMap); } else if(bindingType == CSVBindingType.MAP) { if(bindMapKeyField == null) { throw new SmooksConfigurationException("CSV 'MAP' Binding must specify a 'keyField' property on the binding configuration."); } assertValidFieldName(bindMapKeyField); Bean mapBean = new Bean(LinkedHashMap.class, bindBeanId, "$document"); Bean recordBean = new Bean(bindBeanClass, RECORD_BEAN, recordElementName); MapBindingWiringVisitor wiringVisitor = new MapBindingWiringVisitor(bindMapKeyField, bindBeanId); addFieldBindings(recordBean); mapBean.addVisitors(visitorMap); recordBean.addVisitors(visitorMap); visitorMap.addVisitor(wiringVisitor, recordElementName, null, false); } else { bean = new Bean(bindBeanClass, bindBeanId, recordElementName); addFieldBindings(bean); bean.addVisitors(visitorMap); } } }
/** * Add the visitors, associated with this Bean instance, to the visitor map. * @param visitorMap The visitor Map. */ public void addVisitors(VisitorConfigMap visitorMap) { // Need to protect against multiple calls. This can happen where e.g. beans are // wired together in 2-way relationships, or the creating code doesn't use the // fluent interface and calls Smooks.addVisitor to each bean instance. if(processed) { return; } processed = true; // Add the create bean visitor... SmooksResourceConfiguration creatorConfig = visitorMap.addVisitor(beanInstanceCreator, createOnElement, targetNamespace, true); creatorConfig.setParameter("beanId", getBeanId()); creatorConfig.setParameter("beanClass", beanClass.getName()); // Recurse down the wired beans... for(Bean bean : wirings) { bean.addVisitors(visitorMap); } // Add the populate bean visitors... for(Binding binding : bindings) { SmooksResourceConfiguration populatorConfig = visitorMap.addVisitor(binding.beanInstancePopulator, binding.selector, targetNamespace, true); populatorConfig.setParameter("beanId", getBeanId()); if(binding.assertTargetIsCollection) { assertBeanClassIsCollection(); } } }
assertNotProcessed(); AssertArgument.isNotNull(bindingMember, "bindingMember"); AssertArgument.isNotNull(bean, "bean"); beanInstancePopulator.setBeanId(getBeanId()); beanInstancePopulator.setWireBeanId(bean.getBeanId()); Method bindingMethod = getBindingMethod(bindingMember, beanClass);
/** * 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; }
/** * 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 addVisitors(VisitorConfigMap visitorMap) { initialize(); if(bindBeanId != null && bindBeanClass != null) { Bean bean; if(bindingType == FixedLengthBindingType.LIST) { Bean listBean = new Bean(ArrayList.class, bindBeanId, "$document"); bean = listBean.newBean(bindBeanClass, recordElementName); listBean.bindTo(bean); addFieldBindings(bean); listBean.addVisitors(visitorMap); } else if(bindingType == FixedLengthBindingType.MAP) { if(bindMapKeyField == null) { throw new SmooksConfigurationException("FixedLenght 'MAP' Binding must specify a 'keyField' property on the binding configuration."); } assertValidFieldName(bindMapKeyField); Bean mapBean = new Bean(LinkedHashMap.class, bindBeanId, "$document"); Bean recordBean = new Bean(bindBeanClass, RECORD_BEAN, recordElementName); MapBindingWiringVisitor wiringVisitor = new MapBindingWiringVisitor(bindMapKeyField, bindBeanId); addFieldBindings(recordBean); mapBean.addVisitors(visitorMap); recordBean.addVisitors(visitorMap); visitorMap.addVisitor(wiringVisitor, recordElementName, null, false); } else { bean = new Bean(bindBeanClass, bindBeanId, recordElementName); addFieldBindings(bean); bean.addVisitors(visitorMap); } } }
assertNotProcessed(); AssertArgument.isNotNull(bindingMember, "bindingMember"); AssertArgument.isNotNull(dataSelector, "dataSelector"); beanInstancePopulator.setBeanId(getBeanId()); beanInstancePopulator.setValueAttributeName(populatorConfig.getStringParameter(BeanInstancePopulator.VALUE_ATTRIBUTE_NAME)); beanInstancePopulator.setValueAttributePrefix(populatorConfig.getStringParameter(BeanInstancePopulator.VALUE_ATTRIBUTE_PREFIX)); Method bindingMethod = getBindingMethod(bindingMember, beanClass); if (bindingMethod != null) { if (dataDecoder == null) {
/** * 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; }
Bean listBean = new Bean(ArrayList.class, bindBeanId, SmooksResourceConfiguration.DOCUMENT_FRAGMENT_SELECTOR); bean = listBean.newBean(bindBeanClass, recordElementName); listBean.bindTo(bean); addFieldBindings(bean); listBean.addVisitors(visitorMap); } else if (bindingType == BindingType.MAP) { if (bindMapKeyField == null) { Bean mapBean = new Bean(LinkedHashMap.class, bindBeanId, SmooksResourceConfiguration.DOCUMENT_FRAGMENT_SELECTOR); Bean recordBean = new Bean(bindBeanClass, RECORD_BEAN, recordElementName); MapBindingWiringVisitor wiringVisitor = new MapBindingWiringVisitor(bindMapKeyField, bindBeanId); mapBean.addVisitors(visitorMap); recordBean.addVisitors(visitorMap); visitorMap.addVisitor(wiringVisitor, recordElementName, null, false); } else { bean = new Bean(bindBeanClass, bindBeanId, recordElementName); addFieldBindings(bean); bean.addVisitors(visitorMap);
/** * Create a Bean binding configuration. * * @param beanClass The bean runtime class. * @param beanId The bean ID. * @param createOnElement The element selector used to create the bean instance. * @param createOnElementNS The namespace for the element selector used to create the bean instance. * @param factory The factory that will create the runtime object */ public static <T> Bean newBean(Class<T> beanClass, String beanId, String createOnElement, String createOnElementNS, Factory<T> factory) { return new Bean(beanClass, beanId, createOnElement, createOnElementNS, factory); }
/** * Create a binding configuration to bind the data, selected from the message by the * dataSelector, to the specified bindingMember (field/method). * <p/> * Discovers the {@link org.dhatim.javabean.DataDecoder} through the specified * bindingMember. * * @param bindingMember The name of the binding member. This is a bean property (field) * or method name. * @param dataSelector The data selector for the data value to be bound. * @return The Bean configuration instance. */ public Bean bindTo(String bindingMember, String dataSelector) { return bindTo(bindingMember, dataSelector, null); }
/** * Create a Bean binding configuration. * <p/> * This method binds the configuration to the same {@link Smooks} instance * supplied in the constructor. * * @param beanClass The bean runtime class. * @param beanId The beanId. * @param createOnElement The element selector used to create the bean instance. * @return <code>this</code> Bean configuration instance. */ public Bean newBean(Class<?> beanClass, String beanId, String createOnElement) { return new Bean(beanClass, beanId, createOnElement); }
private void addFieldBindings(Bean bean) { for (Field field1 : fields) { String field = field1.getName(); if (!field.equals(IGNORE_FIELD)) { bean.bindTo(field, recordElementName + "/" + field); } } }
/** * Create a Bean binding configuration. * <p/> * This method binds the configuration to the same {@link Smooks} instance * supplied in the constructor. * * @param beanClass The bean runtime class. * @param beanId The beanId. * @param createOnElement The element selector used to create the bean instance. * @param factory The factory that will create the runtime object * @return <code>this</code> Bean configuration instance. */ public <T> Bean newBean(Class<T> beanClass, String beanId, String createOnElement, Factory<T> factory) { return new Bean(beanClass, beanId, createOnElement, factory); }
private void addFieldBindings(Bean bean) { for(Field field : fields) { if(!field.ignore()) { bean.bindTo(field.getName(), recordElementName + "/" + field.getName()); } } }
/** * Create a Bean binding configuration. * <p/> * This method binds the configuration to the same {@link Smooks} instance * supplied in the constructor. The beanId is generated. * * @param beanClass The bean runtime class. * @param createOnElement The element selector used to create the bean instance. * @return <code>this</code> Bean configuration instance. */ public Bean newBean(Class<?> beanClass, String createOnElement) { String randomBeanId = UUID.randomUUID().toString(); return new Bean(beanClass, randomBeanId, createOnElement); }
private void addFieldBindings(Bean bean) { for (FieldMetaData fieldMetaData : vfRecordMetaData.getRecordMetaData().getFields()) { if (!fieldMetaData.ignore()) { bean.bindTo(fieldMetaData.getName(), recordElementName + "/" + fieldMetaData.getName()); } } }
/** * Create a Bean binding configuration. * <p/> * This method binds the configuration to the same {@link Smooks} instance * supplied in the constructor. The beanId is generated. * * @param beanClass The bean runtime class. * @param createOnElement The element selector used to create the bean instance. * @return <code>this</code> Bean configuration instance. * @param factory The factory that will create the runtime object */ public <T> Bean newBean(Class<T> beanClass, String createOnElement, Factory<T> factory) { String randomBeanId = UUID.randomUUID().toString(); return new Bean(beanClass, randomBeanId, createOnElement, factory); }