Methods Summary |
---|
public void | convert()
This will make some simple changes to the descriptor and write it back
out to a new file, in a converted form.
// Load up the mapping information
Mapping mapping = new Mapping();
mapping.loadMapping(MAPPING_FILENAME);
// Marshall using that information
Marshaller marshaller = new Marshaller(new FileWriter(convertFile));
marshaller.setMapping(mapping);
marshaller.marshal(employees);
|
public void | list(boolean validate)
This will list some basic information about the
hr.xml deployment descriptor.
// Unmarshall
employees = Employees.unmarshal(new FileReader(descriptor));
// Do some basic printing
System.out.println("--- Employee Listing ---\n");
Employee[] employeeList = employees.getEmployee();
for (int i=0; i<employeeList.length; i++) {
Employee employee = employeeList[i];
System.out.println("Employee: " + employee.getName());
System.out.println("Organization: " +
employee.getOrganization().getName());
System.out.println("Office: " +
employee.getOffice().getAddress().getCity() + ", " +
employee.getOffice().getAddress().getState() + "\n");
}
|
public static void | main(java.lang.String[] args)
try {
if (args.length != 3) {
System.out.println("Usage: java javajaxb.EmployeeLister " +
"[web.xml filename] [output.xml filename] [convert.xml filename]");
return;
}
EmployeeLister lister =
new EmployeeLister(new File(args[0]), new File(args[1]), new File(args[2]));
lister.list(true);
lister.modify();
lister.convert();
} catch (Exception e) {
e.printStackTrace();
}
|
public void | modify()
This will make some simple changes to the descriptor and write it back
out to a new file.
// Add a new employee
Employee employee = new Employee();
employee.setName("Ben Rochester");
Address address = new Address();
address.setStreet1("708 Teakwood Drive");
address.setCity("Flower Mound");
address.setState("TX");
address.setZipCode("75028");
employee.addAddress(address);
Organization organization = new Organization();
organization.setId(43);
organization.setName("Technical Services");
employee.setOrganization(organization);
Office office = new Office();
office.setId(241);
Address officeAddress = new Address();
officeAddress.setStreet1("1202 Business Square");
officeAddress.setStreet2("Suite 302");
officeAddress.setCity("Dallas");
officeAddress.setState("TX");
officeAddress.setZipCode("75218-8921");
office.setAddress(officeAddress);
employee.setOffice(office);
// Add employee to list
employees.addEmployee(employee);
// marshal
employees.marshal(new FileWriter(outputFile));
|