Parser used to resolve arguments into java classes.
Interprets command-line args as either class names, .class files or
resources, .java files or resources, or metadata files or resources
conforming to the common format defined by
instances.
Note that when parsing .java files, only the main class in the file
is detected. Other classes defined in the file, such as inner classes,
are not added to the returned classes list.
| Method from org.apache.openjpa.lib.meta.ClassArgParser Detail: |
public ClassLoader getClassLoader() {
return _loader;
}
The class loader with which to load parsed classes. |
public Map mapTypeNames(MetaDataIterator itr) {
if (itr == null)
return Collections.EMPTY_MAP;
Map map = new HashMap();
Object source = null;
List names = new ArrayList();
try {
while (itr.hasNext()) {
source = itr.next();
appendTypeNames(source, itr.getInputStream(), names);
if (!names.isEmpty())
map.put(source, (String[]) names.toArray
(new String[names.size()]));
names.clear();
}
} catch (Exception e) {
throw new NestableRuntimeException(
_loc.get("class-arg", source).getMessage(), e);
}
return map;
}
Return a mapping of each metadata resource to an array of its contained
class names. |
public Map mapTypes(MetaDataIterator itr) {
Map map = mapTypeNames(itr);
Map.Entry entry;
String[] names;
Class[] objs;
for (Iterator i = map.entrySet().iterator(); i.hasNext();) {
entry = (Map.Entry) i.next();
names = (String[]) entry.getValue();
objs = new Class[names.length];
for (int j = 0; j < names.length; j++)
objs[j] = Strings.toClass(names[j], _loader);
entry.setValue(objs);
}
return map;
}
Return a mapping of each metadata resource to an array of its
contained classes. |
public String[] parseTypeNames(String arg) {
if (arg == null)
return new String[0];
try {
File file = Files.getFile(arg, _loader);
if (arg.endsWith(".class"))
return new String[]{ getFromClassFile(file) };
if (arg.endsWith(".java"))
return new String[]{ getFromJavaFile(file) };
if (((Boolean) AccessController.doPrivileged(
J2DoPrivHelper.existsAction(file))).booleanValue()) {
Collection col = getFromMetaDataFile(file);
return (String[]) col.toArray(new String[col.size()]);
}
} catch (Exception e) {
throw new NestableRuntimeException(
_loc.get("class-arg", arg).getMessage(), e);
}
// must be a class name
return new String[]{ arg };
}
Return the names of the class(es) from the given arg. |
public String[] parseTypeNames(MetaDataIterator itr) {
if (itr == null)
return new String[0];
List names = new ArrayList();
Object source = null;
try {
while (itr.hasNext()) {
source = itr.next();
appendTypeNames(source, itr.getInputStream(), names);
}
} catch (Exception e) {
throw new NestableRuntimeException(
_loc.get("class-arg", source).getMessage(), e);
}
return (String[]) names.toArray(new String[names.size()]);
}
Return the names of the class(es) from the given metadatas. |
public Class[] parseTypes(String arg) {
String[] names = parseTypeNames(arg);
Class[] objs = new Class[names.length];
for (int i = 0; i < names.length; i++)
objs[i] = Strings.toClass(names[i], _loader);
return objs;
}
Return the Class representation of the class(es) named in the
given arg. |
public Class[] parseTypes(MetaDataIterator itr) {
String[] names = parseTypeNames(itr);
Class[] objs = new Class[names.length];
for (int i = 0; i < names.length; i++)
objs[i] = Strings.toClass(names[i], _loader);
return objs;
}
Return the Class representation of the class(es) named in the
given metadatas. |
public void setClassLoader(ClassLoader loader) {
_loader = loader;
}
The class loader with which to load parsed classes. |
public void setMetaDataStructure(String packageElementName,
String packageAttributeName,
String[] classElementNames,
String classAttributeName) {
// calculate how many chars deep we have to go to identify each element
// name as unique. this is extremely inefficient for large N, but
// should never be called for more than a few elements
char[] buf = new char[classElementNames.length + 1];
int charIdx = 0;
for (; true; charIdx++) {
for (int i = 0; i < buf.length; i++) {
if (i == 0) {
if (charIdx == packageElementName.length())
throw new UnsupportedOperationException(_loc.get
("cant-diff-elems").getMessage());
buf[i] = packageElementName.charAt(charIdx);
} else {
if (charIdx == classElementNames[i - 1].length())
throw new UnsupportedOperationException(_loc.get
("cant-diff-elems").getMessage());
buf[i] = classElementNames[i - 1].charAt(charIdx);
}
}
if (charsUnique(buf))
break;
}
_packageAttr = (packageAttributeName == null) ? null
: packageAttributeName.toCharArray();
_classAttr = (classAttributeName == null) ? null
: classAttributeName.toCharArray();
_beginElements = new char[classElementNames.length + 1][];
_endElements = new char[classElementNames.length + 1][];
_beginElements[0] = packageElementName.substring(0, charIdx + 1).
toCharArray();
_endElements[0] = packageElementName.substring(charIdx + 1).
toCharArray();
for (int i = 0; i < classElementNames.length; i++) {
_beginElements[i + 1] = classElementNames[i].
substring(0, charIdx + 1).toCharArray();
_endElements[i + 1] = classElementNames[i].
substring(charIdx + 1).toCharArray();
}
}
Set the the relevant metadata file structure so that metadata files
containing class names can be parsed. Null attribute names indicate
that the text content of the element contains the data. |