Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;

public class Main {
    public static void main(String[] args) throws Exception {
        JAXBContext context = JAXBContext.newInstance(Disk.class, MyStatus.class, MyDisk.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        Disk disk = new Disk();
        disk.setStatus("attached");
        disk.setSize(10000000000L);
        disk.setFreeSpace(25600000L);
        disk.setId("1");

        m.marshal(disk, System.out);
        m.marshal(new MyStatus(disk), System.out);
        m.marshal(new MyDisk(disk), System.out);
    }

}

@XmlRootElement
class Disk {
    private String status;
    private long size;
    private long freeSpace;
    private String id;

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public long getFreeSpace() {
        return freeSpace;
    }

    public void setFreeSpace(long freeSpace) {
        this.freeSpace = freeSpace;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Disk [status=" + status + ", size=" + size + ", freeSpace=" + freeSpace + ", id=" + id + "]";
    }
}

@XmlRootElement(name = "Disk")
class MyStatus {
    private Disk disk;

    public MyStatus() {
    }

    public MyStatus(Disk disk) {
        this.disk = disk;
    }

    public String getStatus() {
        return disk.getStatus();
    }

    public void setStatus(String status) {
    }
}

@XmlRootElement(name = "Disk")
class MyDisk {
    private Disk disk;

    public MyDisk() {
    }

    public MyDisk(Disk disk) {
        this.disk = disk;
    }

    public long getFreeSpace() {
        return disk.getFreeSpace();
    }

    public void setFreeSpace(long freeSpace) {
    }
}