/** * 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 Class<?> getBeanClass() { return creator.getBeanRuntimeInfo().getPopulateType(); }
public Bean getModel(Class<?> beanType) { for(Bean model : models.values()) { if(model.getCreator().getBeanRuntimeInfo().getPopulateType() == beanType) { return model; } } return null; }
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; }
/** * Create a new bean instance, generating relevant configuration exceptions. * * @return A new bean instance. */ private Object createBeanInstance(ExecutionContext executionContext) { Object bean; if(factory == null) { try { bean = beanRuntimeInfo.getPopulateType().newInstance(); } catch (InstantiationException e) { throw new SmooksConfigurationException("Unable to create bean instance [" + beanIdName + ":" + beanRuntimeInfo.getPopulateType().getName() + "].", e); } catch (IllegalAccessException e) { throw new SmooksConfigurationException("Unable to create bean instance [" + beanIdName + ":" + beanRuntimeInfo.getPopulateType().getName() + "].", e); } } else { try { bean = factory.create(executionContext); } catch (RuntimeException e) { throw new SmooksConfigurationException("The factory was unable to create the bean instance [" + beanIdName + "] using the factory '" + factory + "'.", e); } } 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."); } }
@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; }
} 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; 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.");
private void createRootSerializers(List<XMLElementSerializationNode> graphs) { Collection<Bean> beanModels = beanModelSet.getModels().values(); for(Bean model : beanModels) { BeanInstanceCreator creator = model.getCreator(); SelectorStep[] selectorSteps = creator.getConfig().getSelectorSteps(); XMLElementSerializationNode createNode = (XMLElementSerializationNode) findNode(graphs, selectorSteps); // Only create serializers for routed elements... if(rootElementNames.contains(createNode.getQName())) { createNode = ((XMLElementSerializationNode) createNode.clone()); createNode.setParent(null); Class<?> beanClass = creator.getBeanRuntimeInfo().getPopulateType(); if(!Collection.class.isAssignableFrom(beanClass)) { // Ignore Collections... don't allow them to be serialized.... not enough type info. serializers.put(beanClass, new RootNodeSerializer(creator.getBeanId(), createNode)); addNamespaceAttributes(createNode); } } } }
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() + "'.");