class SchedulerAdapter {

	public XmlBuilder getJobGroupNamesWithJobsToXml(Scheduler theScheduler, IbisManager ibisManager) {
		XmlBuilder xbRoot = new XmlBuilder("jobGroups");

		try {
			// process groups
			List<String> jgnames = theScheduler.getJobGroupNames();

			for (int i = 0; i < jgnames.size(); i++) {
				XmlBuilder el = new XmlBuilder("jobGroup");
				String jobGroupName = jgnames.get(i);
				el.addAttribute("name", jobGroupName);

				// process jobs within group
				XmlBuilder jb = new XmlBuilder("jobs");
				Set<JobKey> jobKeys = theScheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroupName));

				for (JobKey jobKey : jobKeys) {
					XmlBuilder jn = new XmlBuilder("job");
					String jobName = jobKey.getName();
					jn.addAttribute("name", jobName);

					// details for job
					JobDetail jobDetail = theScheduler.getJobDetail(jobKey);
					XmlBuilder jd = jobDetailToXmlBuilder(jobDetail);
					jn.addSubElement(jd);

					// get the triggers for this job
					List<? extends Trigger> triggers = theScheduler.getTriggersOfJob(jobKey);
					XmlBuilder tr = getJobTriggers(triggers);
					jn.addSubElement(tr);


					JobDataMap jobDataMap = jobDetail.getJobDataMap();
					XmlBuilder datamap = jobDataMapToXmlBuilder(jobDataMap);
					jn.addSubElement(datamap);
					jb.addSubElement(jn);

					JobDef jobDef = null;
					if(ibisManager != null) {
						for (Configuration configuration : ibisManager.getConfigurations()) {
							jobDef = configuration.getScheduledJob(jobName);
							if (jobDef != null) {
								break;
							}
						}
					}
					XmlBuilder ms = getJobMessages(jobDef);
					jn.addSubElement(ms);
					XmlBuilder jrs= getJobRunStatistics(jobDef);
					jn.addSubElement(jrs);
				}
				el.addSubElement(jb);
				xbRoot.addSubElement(el);
			}
		} catch (SchedulerException se) {
			log.error(se);
		}

		return xbRoot;
	}

}