FileDocCategorySizeDatePackage
EmployeeLister.javaAPI DocExample5157Thu Mar 07 09:58:32 GMT 2002javajaxb

EmployeeLister

public class EmployeeLister extends Object

Fields Summary
private File
descriptor
The descriptor to read in
private File
outputFile
The output file to write to
private File
convertFile
The converted output file
private Employees
employees
The object tree read in
private static final String
MAPPING_FILENAME
Change this for your location!
Constructors Summary
public EmployeeLister(File descriptor, File outputFile, File convertFile)

This takes in the descriptor to be processed.

param
descriptor the file for the hr.xml to process
param
outputFile the file to write changes to.
param
convertFile the file to write the conversion to.

    
                                              
           
        employees = null;
        this.descriptor = descriptor;
        this.outputFile = outputFile;
        this.convertFile = convertFile;
    
Methods Summary
public voidconvert()

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 voidlist(boolean validate)

This will list some basic information about the hr.xml deployment descriptor.

param
validate whether or not to validate the descriptor when processing

        
        // 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 voidmain(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 voidmodify()

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));