public void visitBefore(Element element, ExecutionContext executionContext) throws SmooksException { createAndSetBean(executionContext, new Fragment(element)); }
public Bean(BeanInstanceCreator creator) { this.creator = creator; this.beanId = creator.getBeanId(); }
public boolean isCollection() { BeanRuntimeInfo.Classification classification = creator.getBeanRuntimeInfo().getClassification(); return (classification == Classification.COLLECTION_COLLECTION || classification == Classification.ARRAY_COLLECTION); }
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); } } } }
buildId(); checkForDefaultConstructor(); } else if (beanRuntimeInfo.getClassification() == Classification.ARRAY_COLLECTION) { throw new SmooksConfigurationException("Using a factory with an array is not supported");
public SmooksResourceConfiguration getConfig() { return creator.getConfig(); }
@Override public String toString() { return getId(); }
/** * 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 <T> Bean(Class<T> beanClass, String beanId, String createOnElement, String createOnElementNS, Factory<? extends T> factory) { super(beanId); AssertArgument.isNotNull(beanClass, "beanClass"); AssertArgument.isNotNull(createOnElement, "createOnElement"); this.beanClass = beanClass; this.createOnElement = createOnElement; this.targetNamespace = createOnElementNS; beanInstanceCreator = new BeanInstanceCreator(beanId, beanClass, factory); }
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); } }
private void createAndSetBean(ExecutionContext executionContext, Fragment source) { Object bean; BeanContext beanContext = executionContext.getBeanContext(); bean = createBeanInstance(executionContext); executionContext.getBeanContext().notifyObservers(new BeanContextLifecycleEvent(executionContext, source, BeanLifecycle.START_FRAGMENT, beanId, bean)); if(initValsExpression != null) { initValsExpression.exec(bean); } beanContext.setBeanInContext(beanId, false); beanContext.addBean(beanId, bean, source); beanContext.setBeanInContext(beanId, true); if (logger.isDebugEnabled()) { logger.debug("Bean [" + beanIdName + "] instance created."); } }
XMLElementSerializationNode node = (XMLElementSerializationNode) serializer.findNode(wiredBean.getCreator().getConfig().getSelectorSteps());
public Class<?> getBeanClass() { return creator.getBeanRuntimeInfo().getPopulateType(); }
public void visitBefore(SAXElement element, ExecutionContext executionContext) throws SmooksException, IOException { createAndSetBean(executionContext, new Fragment(element)); }
public Bean getModel(Class<?> beanType) { for(Bean model : models.values()) { if(model.getCreator().getBeanRuntimeInfo().getPopulateType() == beanType) { return model; } } return null; }
/** * 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."); } }