use of org.eclipse.linuxtools.internal.oprofile.core.opxml.AbstractDataAdapter in project linuxtools by eclipse.
the class OpxmlRunner method run.
/**
* Runs opxml with the given arguments.
*
* @param args
* the arguments to pass to opxml
* @param callData
* any callData to pass to the processor
* @return boolean indicating the success/failure of opxml
*/
public boolean run(String[] args, Object callData) {
XMLReader reader = null;
OprofileSAXHandler handler = OprofileSAXHandler.getInstance(callData);
// Create XMLReader
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
reader = factory.newSAXParser().getXMLReader();
} catch (Exception e) {
e.printStackTrace();
return false;
}
// Set content/error handlers
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
// Check for timer support
InfoAdapter.checkTimerSupport();
// Run opxml
try {
File file = constructFile(args);
// handle the opxml_session file
if (args[0].equals(SessionManager.SESSIONS)) {
SessionManager sessManNew = new SessionManager(SessionManager.SESSION_LOCATION);
populateWithCurrentSession(sessManNew);
sessManNew.write();
FileReader fr = new FileReader(file);
reader.parse(new InputSource(fr));
// file has not been saved
} else if (!file.exists()) {
AbstractDataAdapter aea;
if (args[0].equals(CheckEventAdapter.CHECK_EVENTS)) {
aea = new CheckEventAdapter(args[1], args[2], args[3]);
aea.process();
BufferedReader bi = new BufferedReader(new InputStreamReader(aea.getInputStream()));
reader.parse(new InputSource(bi));
} else if (args[0].equals(InfoAdapter.INFO)) {
aea = new InfoAdapter();
aea.process();
BufferedReader bi = new BufferedReader(new InputStreamReader(aea.getInputStream()));
reader.parse(new InputSource(bi));
} else if (args[0].equals(ModelDataAdapter.MODEL_DATA)) {
// has not been generated
if (!handleModelData(args)) {
return false;
}
FileReader fr = new FileReader(file);
reader.parse(new InputSource(fr));
} else {
// $NON-NLS-1$
throw new RuntimeException("Unrecognized argument encountered");
}
} else {
// always regenerate the 'current' session file
if (args.length == 3 && args[0].equals(SessionManager.MODEL_DATA) && args[2].equals(SessionManager.CURRENT)) {
if (!handleModelData(args)) {
return false;
}
}
FileReader fr = new FileReader(file);
reader.parse(new InputSource(fr));
}
return true;
} catch (SAXException e) {
e.printStackTrace();
// $NON-NLS-1$
OprofileCorePlugin.showErrorDialog("opxmlSAXParseException", null);
} catch (IOException e) {
e.printStackTrace();
// $NON-NLS-1$
OprofileCorePlugin.showErrorDialog("opxmlParse", null);
}
return false;
}
Aggregations