commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Jakarta-commons Wiki] Update of "Betwixt/TipsAndHints/TypeBindingMappingStrategy" by JesseSweetland
Date Fri, 01 Sep 2006 15:55:50 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-commons Wiki" for change notification.

The following page has been changed by JesseSweetland:
http://wiki.apache.org/jakarta-commons/Betwixt/TipsAndHints/TypeBindingMappingStrategy

New page:
This ActionMappingStrategy runs the element type (singular property type) through the configured
TypeBindingStrategy to determine whether it is a COMPLEX or PRIMITIVE type.  If it is a PRIMITIVE
type, then a SimpleTypeBindAction is returned, which enables the correct unmarshalling of
elements with simple type content.  Otherwise, it defers to the default ActionMappingStrategy,
which is by default an instance of DefaultActionMappingStrategy but can be overridden with
a constructor argument.

{{{
import org.apache.commons.betwixt.*;
import org.apache.commons.betwixt.io.read.*;
import org.apache.commons.betwixt.strategy.*;
import org.apache.commons.logging.*;
import org.xml.sax.*;

/**
 *
 * @author Jesse Sweetland
 */
public class TypeBindingMappingStrategy extends ActionMappingStrategy {
    private Log _log = LogFactory.getLog(getClass());
    private ActionMappingStrategy _defaultActionMappingStrategy = new DefaultActionMappingStrategy();
    
    public TypeBindingMappingStrategy() {
    }
    
    public TypeBindingMappingStrategy(ActionMappingStrategy defaultActionMappingStrategy)
{
        if(defaultActionMappingStrategy != null) {
            _defaultActionMappingStrategy = defaultActionMappingStrategy;
        }
    }
    
    public MappingAction getMappingAction(String ns, String name, Attributes attributes, ReadContext
context) throws Exception {
        XMLIntrospector intro = context.getXMLIntrospector();
        IntrospectionConfiguration cfg = intro.getConfiguration();
        TypeBindingStrategy typeStrat = cfg.getTypeBindingStrategy();
        
        ElementDescriptor descr = context.getCurrentDescriptor();
        Class type = null;
        if(descr == null) {
            if(_log.isDebugEnabled()) _log.debug("Element {" + ns + "}:" + name + " has null
descriptor");
            type = null;
        } else {
            type = descr.getSingularPropertyType();
            if(_log.isDebugEnabled()) _log.debug("Element {" + ns + "}:" + name + " is a "
+ type);
        }
        
        MappingAction action = null;
        if((type != null) && (TypeBindingStrategy.BindingType.PRIMITIVE.equals(typeStrat.bindingType(type))))
{
            action = new SimpleTypeBindAction();
        } else {
            action = _defaultActionMappingStrategy.getMappingAction(ns, name, attributes,
context);
        }
        _log.debug("Element {" + ns + "}:" + name + " (" + type + ") mapped to " + action.getClass());
        return action;
    }
}
}}}

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message