| Method from org.apache.openjpa.lib.meta.CFMetaDataParser Detail: |
protected Class classForName(String name,
boolean resolve) throws SAXException {
if (name == null)
return null;
Class cls = classForName(name, _package, resolve, currentClassLoader());
if (cls == null)
throw getException(_loc.get("invalid-class", name).getMessage());
return cls;
}
Helper method to create the Class for the given name,
taking into account the package currently being parsed for relative
class names. |
public static Class classForName(String name,
String pkg,
boolean resolve,
ClassLoader loader) {
if (StringUtils.isEmpty(name))
return null;
if (loader == null)
loader = (ClassLoader) AccessController.doPrivileged(
J2DoPrivHelper.getContextClassLoaderAction());
boolean fullName = name.indexOf('.") != -1;
boolean noPackage = StringUtils.isEmpty(pkg);
try {
if (fullName || noPackage)
return Strings.toClass(name, resolve, loader);
return Strings.toClass(pkg + "." + name, resolve, loader);
} catch (RuntimeException re) {
}
// if not a full name, now try the name without a package
if (!fullName && !noPackage) {
try {
return Strings.toClass(name, resolve, loader);
} catch (RuntimeException re) {
}
}
// try with standard packages
if (!fullName) {
for (int i = 0; i < PACKAGES.length; i++) {
try {
return Strings.toClass(PACKAGES[i] + name, resolve, loader);
} catch (RuntimeException re) {
}
}
}
return null;
}
Load the given class name against the given package and the set
of accepted standard packages. Return null if the class cannot be loaded. |
protected String currentClassName() {
return _class;
}
Return the current class being parsed; the returned name will
be fully qualified. |
protected String currentPackage() {
return _package;
}
Return the current package being parsed. |
protected void endClass(String elem) throws SAXException {
if (getClassAttributeName() != null)
_class = null;
else {
_class = currentText();
if (!StringUtils.isEmpty(_package) && _class.indexOf('.") == -1)
_class = _package + "." + _class;
}
}
End a class. Parses contained text by default. |
protected void endClassElement(String name) throws SAXException {
}
Override this method marking the end of an element within a declared
class. |
protected void endElement(String name) throws SAXException {
// skip root element
int depth = currentDepth();
if (depth == 0)
return;
try {
if (depth == getPackageElementDepth()
&& isPackageElementName(name))
endPackage(name);
else if (depth == getClassElementDepth()
&& isClassElementName(name))
endClass(name);
else if (depth > getClassElementDepth() && _class != null
&& getClassAttributeName() != null)
endClassElement(name);
else if (depth > getPackageElementDepth() && _package != null
&& getPackageAttributeName() != null)
endPackageElement(name);
else
endSystemElement(name);
} catch (SAXException se) {
throw se;
} catch (NullPointerException npe) {
throw getException(_loc.get("parse-error", name), npe);
}
}
|
protected void endPackage(String elem) {
if (getPackageAttributeName() != null)
_package = null;
else
_package = currentText();
}
End a package. Parses contained text by default. |
protected void endPackageElement(String name) throws SAXException {
}
Override this method marking the end of an element within a declared
package. |
protected void endSystemElement(String name) throws SAXException {
}
Override this method marking the end of an element outside of any
package or class. |
protected String getClassAttributeName() {
return "name";
}
The attribute of the class element that holds the name, or null to
use the element text. Defaults to "name". |
protected int getClassElementDepth() {
return 2;
}
The depth of the class element. Defaults to 2. |
protected String getPackageAttributeName() {
return "name";
}
The attribute of the package element that holds the name, or null to
use the element text. Defaults to "name". |
protected int getPackageElementDepth() {
return 1;
}
The depth of the package element. Defaults to 1. |
protected boolean isClassElementName(String name) {
return "class".equals(name);
}
The name of the class element. Defaults to "class". |
protected boolean isPackageElementName(String name) {
return "package".equals(name);
}
The name of the package element. Defaults to "package". |
protected void reset() {
super.reset();
_package = null;
_class = null;
}
Override this method to clear any state and ready the parser for
a new document. Subclasses should call
super.reset() to clear superclass state. |
protected boolean startClass(String elem,
Attributes attrs) throws SAXException {
if (getClassAttributeName() != null) {
_class = attrs.getValue(getClassAttributeName());
if (!StringUtils.isEmpty(_package) && _class.indexOf('.") == -1)
_class = _package + "." + _class;
}
return true;
}
Start a class. Parses out class name by default. Return
false to skip class element and its contents. |
protected boolean startClassElement(String name,
Attributes attrs) throws SAXException {
return false;
}
Override this method marking the start of an element within a declared
class. |
protected boolean startElement(String name,
Attributes attrs) throws SAXException {
// skip root element
int depth = currentDepth();
if (depth == 0)
return true;
try {
if (depth == getPackageElementDepth()
&& isPackageElementName(name))
return startPackage(name, attrs);
if (depth == getClassElementDepth() && isClassElementName(name))
return startClass(name, attrs);
if (depth > getClassElementDepth() && _class != null
&& getClassAttributeName() != null)
return startClassElement(name, attrs);
if (depth > getPackageElementDepth() && _package != null
&& getPackageAttributeName() != null)
return startPackageElement(name, attrs);
return startSystemElement(name, attrs);
} catch (SAXException se) {
throw se;
} catch (NullPointerException npe) {
throw getException(_loc.get("parse-error", name), npe);
}
}
|
protected boolean startPackage(String elem,
Attributes attrs) throws SAXException {
if (getPackageAttributeName() != null) {
_package = attrs.getValue(getPackageAttributeName());
if (_package == null)
_package = "";
}
return true;
}
Start a package. Parses out package attribute by default.
Return false to skip package element and its contents. |
protected boolean startPackageElement(String name,
Attributes attrs) throws SAXException {
return false;
}
Override this method marking the start of an element within a declared
package. |
protected boolean startSystemElement(String name,
Attributes attrs) throws SAXException {
return false;
}
Override this method marking the start of an element outside of any
package or class. |