Methods Summary |
---|
public static synchronized void | Initialize(java.lang.String fileName)Initialize the singleton instance.
logger.logp(Level.FINE, myClsName, "Initialize", fileName); // NOI18N
//Pl refer to bug#6174887
// assert(me==null);
// if(me==null){
me = new APIRepository(fileName);
// }else throw new RuntimeException("Already Initialized");
|
public static com.sun.enterprise.tools.verifier.apiscan.stdapis.APIRepository | Instance()Return the singleton instance.
assert(me != null);
return me;
|
protected java.util.Collection | getClassesFor(java.lang.String api_name_version)
return ((API) apis.get(api_name_version)).getClasses();
|
private javax.xml.parsers.DocumentBuilder | getDocumentBuilder()
DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
bf.setValidating(true);
bf.setIgnoringComments(false);
bf.setIgnoringElementContentWhitespace(true);
bf.setCoalescing(true);
bf.setNamespaceAware(true);
bf.setAttribute(
"http://java.sun.com/xml/jaxp/properties/schemaLanguage", // NOI18N
"http://www.w3.org/2001/XMLSchema"); // NOI18N
DocumentBuilder builder = bf.newDocumentBuilder();
builder.setErrorHandler(new DefaultHandler() {
public void error(SAXParseException e) throws SAXException {
throw e;
}
});
return builder;
|
private static java.lang.String | getPackageName(java.lang.String externalClassName)
int idx = externalClassName.lastIndexOf('.");
if (idx != -1) {
return externalClassName.substring(0, idx);
} else
return "";
|
protected java.util.Collection | getPackagesFor(java.lang.String api_name_version)
return ((API) apis.get(api_name_version)).getPackages();
|
protected java.util.Collection | getPatternsFor(java.lang.String api_name_version)
return ((API) apis.get(api_name_version)).getPatterns();
|
public boolean | isClassPartOf(java.lang.String class_name, java.lang.String api_name_version)This method is used to find out if a particular class is part of
a standard API or not. e.g. to find out if an EJB 2.0 application is
allowed to use javax.ejb.Timer.class, call this method as
isClassPartOf("javax.ejb.Timer","ejb_jar_2.0")
if (getClassesFor(api_name_version).contains(class_name)) {
return true;
} else if (getPackagesFor(api_name_version).
contains(getPackageName(class_name))) {
return true;
} else {
for (String pattern : getPatternsFor(api_name_version)) {
if (class_name.startsWith(pattern)) {
return true;
}
}
}
return false;
|
public boolean | isPackagePartOf(java.lang.String pkg_name, java.lang.String api_name_version)This method is used to find out if a particular package is part of
a standard API or not. e.g. to find out if an appclient (v 1.4) is
allowed to import javax.persistence.* , call this method as
isPackagePartOf("javax.persistence","appclient_1.4")
if (getPackagesFor(api_name_version).contains(pkg_name)) {
return true;
} else {
for (String pattern : getPatternsFor(api_name_version)) {
if (pkg_name.startsWith(pattern)) {
return true;
}
}
}
return false;
|
public static void | main(java.lang.String[] args)
if (args.length < 1) {
usage();
}
Logger logger = Logger.getLogger("apiscan.stdapis"); // NOI18N
try {
APIRepository.Initialize(args[0]);
APIRepository apiRep = APIRepository.Instance();
switch(args.length) {
case 1:
System.out.println(apiRep);
break;
case 2:
System.out.println(apiRep.apis.get(args[1]));
break;
case 3:
System.out.println(apiRep.isClassPartOf(args[2], args[1]));
break;
default:
usage();
}
} catch (Exception e) {
e.printStackTrace();
}
|
public java.lang.String | toString()
StringBuffer sb = new StringBuffer();
for (Iterator i = apis.values().iterator(); i.hasNext();) {
sb.append("\n").append(i.next().toString()); // NOI18N
}
return sb.toString();
|
private void | traverseTree(org.w3c.dom.Node node)
if (node == null) {
return;
}
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element e = (Element) node;
String tagName = e.getTagName();
if (tagName.equals("api")) { // NOI18N
API a = new API(e);
apis.put(a.name_version, a);
}
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
traverseTree(childNodes.item(i));
}
}
|
private static void | usage()
System.out.println(
"Usage: java " + APIRepository.class.getName() + // NOI18N
" <file_name> [api_name_version] [class_name]"); // NOI18N
System.out.println("\nExamples:\n"); // NOI18N
System.out.println(
"java " + APIRepository.class.getName() + // NOI18N
" src/standard-apis.xml ejb_jar_2.0 javax.ejb.Timer"); // NOI18N
System.out.println("The above command prints true if javax.ejb.Timer is part of ejb_api_2.0 API.\n"); // NOI18N
System.out.println(
"java " + APIRepository.class.getName() + // NOI18N
" src/standard-apis.xml ejb_jar_2.0"); // NOI18N
System.out.println("The above command prints details about all classes and packages for ejb_api_2.0 API.\n"); // NOI18N
System.out.println(
"java " + APIRepository.class.getName() + // NOI18N
" src/standard-apis.xml"); // NOI18N
System.out.println("The above command prints details about all APIs.\n"); // NOI18N
System.exit(1);
|