}
return typesDescriptor;
}
protected TypeMapping parseTypeMapping(Element element, Parse parse, Parser parser) {
TypeMapping typeMapping = new TypeMapping();
Type type = new Type();
typeMapping.setType(type);
// type name
if (element.hasAttribute("name")) {
type.setName(element.getAttribute("name"));
}
String hibernateSessionFactoryName = XmlUtil.attribute(element, "hibernate-session-factory");
// first we get the matcher
Matcher matcher = null;
if (element.hasAttribute("class")) {
String className = element.getAttribute("class");
// if type="serializable"
if ("serializable".equals(className)) {
matcher = new SerializableMatcher();
// if type="hibernatable"
} else if ("hibernatable".equals(className)) {
if (element.hasAttribute("id-type")) {
String idType = element.getAttribute("id-type");
if ("long".equalsIgnoreCase(idType)) {
matcher = new HibernateLongIdMatcher(hibernateSessionFactoryName);
} else if ("string".equalsIgnoreCase(idType)) {
matcher = new HibernateStringIdMatcher(hibernateSessionFactoryName);
} else {
parse.addProblem("id-type was not 'long' or 'string': "+idType, element);
}
} else {
parse.addProblem("id-type is required in a persistable type", element);
}
// otherwise, we expect type="some.java.ClassName"
} else {
matcher = new ClassNameMatcher(className);
}
} else {
// look for the matcher element
Element matcherElement = XmlUtil.element(element, "matcher");
Element matcherObjectElement = XmlUtil.element(matcherElement);
if (matcherObjectElement!=null) {
try {
Descriptor descriptor = (Descriptor) parser.parseElement(matcherObjectElement, parse);
matcher = (Matcher) WireContext.create(descriptor);
} catch (ClassCastException e) {
parse.addProblem("matcher is not a "+Matcher.class.getName()+": "+(matcher!=null ? matcher.getClass().getName() : "null"), element);
}
} else {
parse.addProblem("no matcher specified in "+XmlUtil.toString(element), element);
}
}
typeMapping.setMatcher(matcher);
// parsing the converter
Converter converter = null;
if (element.hasAttribute("converter")) {
String converterClassName = element.getAttribute("converter");