*/
public void begin(String name, String namespace, Attributes attributes)
throws SAXException {
String nameAttributeValue = attributes.getValue("name");
ElementDescriptor descriptor = new ElementDescriptor();
descriptor.setLocalName(nameAttributeValue);
String uri = attributes.getValue("uri");
String qName = nameAttributeValue;
if (uri != null && nameAttributeValue != null) {
descriptor.setURI(uri);
String prefix = getXMLIntrospector().getConfiguration()
.getPrefixMapper().getPrefix(uri);
qName = prefix + ":" + nameAttributeValue;
}
descriptor.setQualifiedName(qName);
String propertyName = attributes.getValue("property");
descriptor.setPropertyName(propertyName);
String propertyType = attributes.getValue("type");
if (log.isTraceEnabled()) {
log.trace("(BEGIN) name=" + nameAttributeValue + " uri=" + uri
+ " property=" + propertyName + " type=" + propertyType);
}
// set mapping derivation
String mappingDerivation = attributes.getValue("mappingDerivation");
if ("introspection".equals(mappingDerivation)) {
descriptor.setUseBindTimeTypeForMapping(false);
} else if ("bind".equals(mappingDerivation)) {
descriptor.setUseBindTimeTypeForMapping(true);
}
// set the property type using reflection
descriptor.setPropertyType(getPropertyType(propertyType, beanClass,
propertyName));
boolean isCollective = getXMLIntrospector().getConfiguration()
.isLoopType(descriptor.getPropertyType());
descriptor.setCollective(isCollective);
// check that the name attribute is present
if (!isCollective
&& (nameAttributeValue == null || nameAttributeValue.trim()
.equals(""))) {
// allow polymorphic mappings but log note for user
log
.info("No name attribute has been specified. This element will be polymorphic.");
}
// check that name is well formed
if (nameAttributeValue != null
&& !XMLUtils.isWellFormedXMLName(nameAttributeValue)) {
throw new SAXException("'" + nameAttributeValue
+ "' would not be a well formed xml element name.");
}
String implementationClass = attributes.getValue("class");
if (log.isTraceEnabled()) {
log.trace("'class' attribute=" + implementationClass);
}
if (implementationClass != null) {
try {
Class clazz = Class.forName(implementationClass);
descriptor.setImplementationClass(clazz);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug(
"Cannot load class named: " + implementationClass,
e);
}
throw new SAXException("Cannot load class named: "
+ implementationClass);
}
}
if (propertyName != null && propertyName.length() > 0) {
boolean forceAccessible = "true".equals(attributes
.getValue("forceAccessible"));
configureDescriptor(descriptor, attributes.getValue("updater"),
forceAccessible);
} else {
String value = attributes.getValue("value");
if (value != null) {
descriptor.setTextExpression(new ConstantExpression(value));
}
}
Object top = digester.peek();
if (top instanceof XMLBeanInfo) {
XMLBeanInfo beanInfo = (XMLBeanInfo) top;
beanInfo.setElementDescriptor(descriptor);
beanClass = beanInfo.getBeanClass();
descriptor.setPropertyType(beanClass);
} else if (top instanceof ElementDescriptor) {
ElementDescriptor parent = (ElementDescriptor) top;
parent.addElementDescriptor(descriptor);
} else {
throw new SAXException("Invalid use of <element>. It should "
+ "be nested inside <info> or other <element> nodes");
}