summaryrefslogtreecommitdiff
path: root/src/main/java/com/p4square/ccbapi/model/CCBIDReference.java
blob: bc7636851c1b794659a361dd00f29d7ea7da1b10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.p4square.ccbapi.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlAdapter;

/**
 * Specialization of {@link Reference}.
 *
 * This class exists because CCB has two different names for the "id"
 * attribute of a reference.
 */
@XmlAccessorType(XmlAccessType.NONE)
/* package-private */ class CCBIDReference {
    @XmlAttribute(name="ccb_id")
    private int id;

    @XmlValue
    private String name;

    public CCBIDReference() {}

    public CCBIDReference(Reference r) {
        this.id = r.getId();
        this.name = r.getName();
    }

    public Reference toReference() {
        final Reference r = new Reference();
        r.setId(id);
        r.setName(name);
        return r;
    }

    public static final class Adapter extends XmlAdapter<CCBIDReference, Reference> {
        @Override
        public Reference unmarshal(CCBIDReference ccbidReference) throws Exception {
            return ccbidReference.toReference();
        }

        @Override
        public CCBIDReference marshal(Reference reference) throws Exception {
            return new CCBIDReference(reference);
        }
    }
}