}
try
{
if (localName.equals("entity-mappings"))
{
FileMetaData filemd = (FileMetaData)getStack();
filemd.setType(MetadataFileType.JPA_MAPPING_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("column-name"))
{
// Processed in endElement()
}
else if (localName.equals("sequence-generator"))
{
// Find the package for this sequence
PackageMetaData pmd = null;
FileMetaData filemd = (FileMetaData)metadata;
if (defaultPackageName != null)
{
pmd = filemd.getPackage(defaultPackageName);
}
else
{
if (filemd.getNoOfPackages() > 0)
{
pmd = filemd.getPackage(0);
}
else
{
// Add a dummy (root) package to hold our sequences since no default package name set
pmd = filemd.newPackageMetadata("");
}
}
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 = pmd.newSequenceMetadata(getAttr(attrs, "name"), null);
String datastoreSeqName = getAttr(attrs, "sequence-name");
if (StringUtils.isWhitespace(datastoreSeqName))
{
datastoreSeqName = seqmd.getName();
}
seqmd.setDatastoreSequence(datastoreSeqName);
seqmd.setInitialValue(initValue);
seqmd.setAllocationSize(allocSize);
}
else if (localName.equals("table-generator"))
{
// Find the package for this table generator
PackageMetaData pmd = null;
FileMetaData filemd = (FileMetaData)metadata;
if (defaultPackageName != null)
{
pmd = filemd.getPackage(defaultPackageName);
}
else
{
if (filemd.getNoOfPackages() > 0)
{
pmd = filemd.getPackage(0);
}
else
{
// Add a dummy (root) package to hold our sequences since no default package name set
pmd = filemd.newPackageMetadata("");
}
}
TableGeneratorMetaData tgmd = pmd.newTableGeneratorMetadata(getAttr(attrs, "name"));
tgmd.setTableName(getAttr(attrs, "table"));
tgmd.setCatalogName(getAttr(attrs, "catalog"));
tgmd.setSchemaName(getAttr(attrs, "schema"));
tgmd.setPKColumnName(getAttr(attrs, "pk-column-name"));
tgmd.setPKColumnValue(getAttr(attrs, "pk-column-value"));
tgmd.setValueColumnName(getAttr(attrs, "value-column-name"));
tgmd.setInitialValue(getAttr(attrs, "initial-value"));
tgmd.setAllocationSize(getAttr(attrs, "allocation-size"));
}
else if (localName.equals("named-query"))
{
// Named JPQL query
MetaData md = getStack();
if (md instanceof FileMetaData)
{
FileMetaData filemd = (FileMetaData)md;
QueryMetaData qmd = filemd.newQueryMetadata(getAttr(attrs, "name"));
qmd.setLanguage(QueryLanguage.JPQL.toString());
pushStack(qmd);
}
else if (md instanceof ClassMetaData)
{
ClassMetaData cmd = (ClassMetaData)md;
QueryMetaData qmd = new QueryMetaData(getAttr(attrs, "name"));
qmd.setLanguage(QueryLanguage.JPQL.toString());
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 = filemd.newQueryMetadata(getAttr(attrs, "name"));
qmd.setLanguage(QueryLanguage.SQL.toString());
qmd.setResultClass(getAttr(attrs, "result-class"));
qmd.setResultMetaDataName(getAttr(attrs, "result-set-mapping"));
pushStack(qmd);
}
else if (md instanceof ClassMetaData)
{
ClassMetaData cmd = (ClassMetaData)md;
QueryMetaData qmd = new QueryMetaData(getAttr(attrs, "name"));
qmd.setLanguage(QueryLanguage.SQL.toString());
qmd.setResultClass(getAttr(attrs, "result-class"));
qmd.setResultMetaDataName(getAttr(attrs, "result-set-mapping"));
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 = filemd.newQueryResultMetadata(getAttr(attrs, "name"));
pushStack(qrmd);
}
else if (md instanceof ClassMetaData)
{
ClassMetaData cmd = (ClassMetaData)md;
QueryResultMetaData qrmd = new QueryResultMetaData(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 = filemd.newPackageMetadata(packageName);
}
else if (defaultPackageName != null)
{
// Use default package for entity-mappings
pmd = filemd.getPackage(defaultPackageName);
}
else
{
// Add root package
pmd = filemd.newPackageMetadata("");
}
}
ClassMetaData cmd = newClassObject(pmd, attrs, false);
pmd.addClass(cmd);
// Set to use "subclass-table" since all subclasses inherit these fields
InheritanceMetaData inhmd = new InheritanceMetaData();
inhmd.setStrategy(InheritanceStrategy.SUBCLASS_TABLE);
cmd.setInheritanceMetaData(inhmd);
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 = filemd.newPackageMetadata(packageName);
}
else if (defaultPackageName != null)
{
// Use default package for entity-mappings
pmd = filemd.getPackage(defaultPackageName);
}
else
{
// Add root package
pmd = filemd.newPackageMetadata("");
}
}
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 = filemd.newPackageMetadata(packageName);
}
else if (defaultPackageName != null)
{
// Use default package for entity-mappings
pmd = filemd.getPackage(defaultPackageName);
}
else
{
// Add root package
pmd = filemd.newPackageMetadata("");
}
}
ClassMetaData cmd = newClassObject(pmd, attrs, true);
pmd.addClass(cmd);