}
try
{
if (localName.equals("entity-mappings"))
{
FileMetaData filemd = (FileMetaData)getStack();
filemd.setType(FileMetaData.JPA_FILE);
}
else if (localName.equals("description"))
{
// Of no practical use so ignored
}
else if (localName.equals("persistence-unit-metadata"))
{
// Nothing to do - we use subelements
}
else if (localName.equals("xml-mapping-metadata-complete"))
{
// All classes in the file are complete without any annotations
metaDataComplete = true;
}
else if (localName.equals("persistence-unit-defaults"))
{
// Nothing to do - we use subelements
}
else if (localName.equals("package"))
{
// Processed in endElement()
}
else if (localName.equals("schema"))
{
// Processed in endElement()
}
else if (localName.equals("catalog"))
{
// Processed in endElement()
}
else if (localName.equals("access"))
{
// Processed in endElement()
}
else if (localName.equals("sequence-generator"))
{
// Sequence generator (add to the default package whether they are specified there are not)
MetaData md = getStack();
String initValue = getAttr(attrs, "initial-value");
if (StringUtils.isWhitespace(initValue))
{
initValue = "1"; // JPA default
}
String allocSize = getAttr(attrs, "allocation-size");
if (StringUtils.isWhitespace(allocSize))
{
allocSize = "50"; // JPA default
}
SequenceMetaData seqmd = new SequenceMetaData(md, getAttr(attrs, "name"),
getAttr(attrs, "sequence-name"), null, null, initValue, allocSize);
PackageMetaData pmd = null;
if (defaultPackageName != null)
{
pmd = ((FileMetaData)metadata).getPackage(defaultPackageName);
}
else
{
if (((FileMetaData)metadata).getNoOfPackages() > 0)
{
pmd = ((FileMetaData)metadata).getPackage(0);
}
else
{
// Add a dummy (root) package to hold our sequences since no default package name set
pmd = new PackageMetaData((FileMetaData)metadata, "", null, null);
((FileMetaData)metadata).addPackage(pmd);
}
}
pmd.addSequence(seqmd);
}
else if (localName.equals("table-generator"))
{
// Table generator (add to the default package whether they are specified there or not)
MetaData md = getStack();
TableGeneratorMetaData tgmd = new TableGeneratorMetaData(md, getAttr(attrs, "name"),
getAttr(attrs, "table"), getAttr(attrs, "catalog"), getAttr(attrs, "schema"), getAttr(attrs, "pk-column-name"),
getAttr(attrs, "value-column-name"), getAttr(attrs, "pk-column-value"), getAttr(attrs, "initial-value"),
getAttr(attrs, "allocation-size"));
PackageMetaData pmd = null;
if (defaultPackageName != null)
{
pmd = ((FileMetaData)metadata).getPackage(defaultPackageName);
}
else
{
if (((FileMetaData)metadata).getNoOfPackages() > 0)
{
pmd = ((FileMetaData)metadata).getPackage(0);
}
else
{
// Add a dummy (root) package to hold our sequences since no default package name set
pmd = new PackageMetaData((FileMetaData)metadata, "", null, null);
((FileMetaData)metadata).addPackage(pmd);
}
}
pmd.addTableGenerator(tgmd);
}
else if (localName.equals("named-query"))
{
// Named JPQL query
MetaData md = getStack();
if (md instanceof FileMetaData)
{
FileMetaData filemd = (FileMetaData)md;
QueryMetaData qmd = new QueryMetaData(filemd, null, getAttr(attrs, "name"), "javax.jdo.query.JPQL",
null, null, null, null, null);
filemd.addQuery(qmd);
pushStack(qmd);
}
else if (md instanceof ClassMetaData)
{
ClassMetaData cmd = (ClassMetaData)md;
QueryMetaData qmd = new QueryMetaData(cmd, null, getAttr(attrs, "name"), "javax.jdo.query.JPQL",
null, null, null, null, null);
cmd.addQuery(qmd);
pushStack(qmd);
}
}
else if (localName.equals("named-native-query"))
{
// Named SQL query
MetaData md = getStack();
if (md instanceof FileMetaData)
{
FileMetaData filemd = (FileMetaData)md;
QueryMetaData qmd = new QueryMetaData(filemd, null, getAttr(attrs, "name"), "javax.jdo.query.SQL", null,
getAttr(attrs, "result-class"), getAttr(attrs, "result-set-mapping"), null, null);
filemd.addQuery(qmd);
pushStack(qmd);
}
else if (md instanceof ClassMetaData)
{
ClassMetaData cmd = (ClassMetaData)md;
QueryMetaData qmd = new QueryMetaData(cmd, null, getAttr(attrs, "name"), "javax.jdo.query.SQL", null,
getAttr(attrs, "result-class"), getAttr(attrs, "result-set-mapping"), null, null);
cmd.addQuery(qmd);
pushStack(qmd);
}
}
else if (localName.equals("sql-result-set-mapping"))
{
MetaData md = getStack();
if (md instanceof FileMetaData)
{
FileMetaData filemd = (FileMetaData)md;
QueryResultMetaData qrmd = new QueryResultMetaData(filemd, getAttr(attrs, "name"));
filemd.addQueryResultMetaData(qrmd);
pushStack(qrmd);
}
else if (md instanceof ClassMetaData)
{
ClassMetaData cmd = (ClassMetaData)md;
QueryResultMetaData qrmd = new QueryResultMetaData(cmd, getAttr(attrs, "name"));
cmd.addQueryResultMetaData(qrmd);
pushStack(qrmd);
}
}
else if (localName.equals("entity-result"))
{
// Add an entity (persistent class) mapping
QueryResultMetaData qrmd = (QueryResultMetaData)getStack();
queryResultEntityName = getAttr(attrs, "entity-class"); // Save this for any field-result that arrives
qrmd.addPersistentTypeMapping(queryResultEntityName,
null, // No field-column mappings info at this point
getAttr(attrs, "discriminator-column"));
}
else if (localName.equals("field-result"))
{
// Add a field-column mapping for the entity (persistent class)
QueryResultMetaData qrmd = (QueryResultMetaData)getStack();
qrmd.addMappingForPersistentTypeMapping(queryResultEntityName,
getAttr(attrs, "name"), getAttr(attrs, "column"));
}
else if (localName.equals("column-result"))
{
// Add a scalar column mapping
QueryResultMetaData qrmd = (QueryResultMetaData)getStack();
qrmd.addScalarColumn(getAttr(attrs, "name"));
}
else if (localName.equals("mapped-superclass"))
{
// New entity for this package
FileMetaData filemd = (FileMetaData)getStack();
String className = getAttr(attrs, "class");
String packageName = null;
if (className.indexOf('.') > 0)
{
// Fully-qualified so use package name from class
packageName = className.substring(0, className.lastIndexOf('.'));
}
PackageMetaData pmd = null;
if (packageName != null)
{
pmd = filemd.getPackage(packageName);
}
if (pmd == null)
{
if (packageName != null)
{
// Class fully qualified so add its package
pmd = new PackageMetaData(filemd, packageName, null, null);
}
else if (defaultPackageName != null)
{
// Use default package for entity-mappings
pmd = filemd.getPackage(defaultPackageName);
}
else
{
// Add root package
pmd = new PackageMetaData(filemd, "", null, null);
}
}
ClassMetaData cmd = newClassObject(pmd, attrs, false);
pmd.addClass(cmd);
// Set to use "subclass-table" since all subclasses inherit these fields
cmd.setInheritanceMetaData(new InheritanceMetaData(cmd, InheritanceStrategy.SUBCLASS_TABLE.toString()));
pushStack(cmd);
}
else if (localName.equals("query"))
{
// Processed in endElement()
}
else if (localName.equals("entity"))
{
// New entity for this package
FileMetaData filemd = (FileMetaData)getStack();
String className = getAttr(attrs, "class");
String packageName = null;
if (className.indexOf('.') > 0)
{
// Fully-qualified so use package name from class
packageName = className.substring(0, className.lastIndexOf('.'));
}
PackageMetaData pmd = null;
if (packageName != null)
{
pmd = filemd.getPackage(packageName);
}
if (pmd == null)
{
if (packageName != null)
{
// Class fully qualified so add its package
pmd = new PackageMetaData(filemd, packageName, null, null);
}
else if (defaultPackageName != null)
{
// Use default package for entity-mappings
pmd = filemd.getPackage(defaultPackageName);
}
else
{
// Add root package
pmd = new PackageMetaData(filemd, "", null, null);
}
}
ClassMetaData cmd = newClassObject(pmd, attrs, false);
pmd.addClass(cmd);
pushStack(cmd);
}
else if (localName.equals("embeddable"))
{
// New embedded-only entity for this package
FileMetaData filemd = (FileMetaData)getStack();
String className = getAttr(attrs, "class");
String packageName = null;
if (className.indexOf('.') > 0)
{
// Fully-qualified so use package name from class
packageName = className.substring(0, className.lastIndexOf('.'));
}
PackageMetaData pmd = null;
if (packageName != null)
{
pmd = filemd.getPackage(packageName);
}
if (pmd == null)
{
if (packageName != null)
{
// Class fully qualified so add its package
pmd = new PackageMetaData(filemd, packageName, null, null);
}
else if (defaultPackageName != null)
{
// Use default package for entity-mappings
pmd = filemd.getPackage(defaultPackageName);
}
else
{
// Add root package
pmd = new PackageMetaData(filemd, "", null, null);