001: /*
002: * $Id: BeanAssembler.java 10494 2008-01-23 21:09:56Z acooke $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.config.spring.parsers.assembly;
012:
013: import org.springframework.beans.factory.config.BeanDefinition;
014: import org.springframework.beans.factory.support.BeanDefinitionBuilder;
015: import org.w3c.dom.Attr;
016:
017: /**
018: * Bean Assembler provides a high-level interface to constructing beans. It encapsulates all
019: * the "smart" logic about collections, maps, references, etc.
020: *
021: * <p>A bean assembly contains a bean (the thing we are constructing), a target (where we put the
022: * bean once it is ready) and appropriate configuration information (there is a configuration
023: * for both bean and target, but currently they are set to the same instance by the classes that
024: * use this).
025: */
026: public interface BeanAssembler {
027:
028: public BeanDefinitionBuilder getBean();
029:
030: public BeanDefinition getTarget();
031:
032: /**
033: * Add a property defined by an attribute to the bean we are constructing.
034: *
035: * <p>Since an attribute value is always a string, we don't have to deal with complex types
036: * here - the only issue is whether or not we have a reference. References are detected
037: * by explicit annotation or by the "-ref" at the end of an attribute name. We do not
038: * check the Spring repo to see if a name already exists since that could lead to
039: * unpredictable behaviour.
040: * (see {@link org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration})
041: * @param attribute The attribute to add
042: */
043: void extendBean(Attr attribute);
044:
045: /**
046: * Allow direct access to bean for more complex cases
047: *
048: * @param newName The property name to add
049: * @param newValue The property value to add
050: * @param isReference If true, a bean reference is added (and newValue must be a String)
051: */
052: void extendBean(String newName, Object newValue, boolean isReference);
053:
054: /**
055: * Add a property defined by an attribute to the parent of the bean we are constructing.
056: *
057: * <p>This is unusual. Normally you want {@link #extendBean(org.w3c.dom.Attr)}.
058: * @param attribute The attribute to add
059: */
060: void extendTarget(Attr attribute);
061:
062: /**
063: * Allow direct access to target for more complex cases
064: *
065: * @param newName The property name to add
066: * @param newValue The property value to add
067: * @param isReference If true, a bean reference is added (and newValue must be a String)
068: */
069: void extendTarget(String newName, Object newValue,
070: boolean isReference);
071:
072: void extendTarget(String oldName, String newName, Object newValue);
073:
074: /**
075: * Insert the bean we have built into the target (typically the parent bean).
076: *
077: * <p>This is the most complex case because the bean can have an aribtrary type.
078: * @param oldName The identifying the bean (typically element name).
079: */
080: void insertBeanInTarget(String oldName);
081:
082: /**
083: * Copy the properties from the bean we have been building into the target (typically
084: * the parent bean). In other words, the bean is a facade for the target.
085: *
086: * <p>This assumes that the source bean has been constructed correctly (ie the decisions about
087: * what is ignored, a map, a list, etc) have already been made. All it does (apart from a
088: * direct copy) is merge collections with those on the target when necessary.
089: */
090: void copyBeanToTarget();
091:
092: /**
093: * Set a flag on the bean - this is used to communicate with
094: * {@link org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate}
095: *
096: * @param flag The flag to set
097: */
098: void setBeanFlag(String flag);
099:
100: }
|