aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/cliqset/xrd/XRD.java
blob: 393e977ba7e1804c1dbdfc723b701f8827e1cac1 (plain) (blame)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
	Copyright 2010 Cliqset Inc.
	
	Licensed under the Apache License, Version 2.0 (the "License"); 
	you may not use this file except in compliance with the License. 
	You may obtain a copy of the License at 
	
		http://www.apache.org/licenses/LICENSE-2.0 
	
	Unless required by applicable law or agreed to in writing, software 
	distributed under the License is distributed on an "AS IS" BASIS, 
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
	See the License for the specific language governing permissions and 
	limitations under the License.
*/

package com.cliqset.xrd;

import javax.xml.namespace.QName;
import javax.xml.bind.annotation.*;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import org.w3c.dom.Element;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

@XmlRootElement(name="XRD", namespace=XRDConstants.XRD_NAMESPACE)
@XmlAccessorType(XmlAccessType.FIELD)
public class XRD {

	@XmlAttribute(name="id", namespace=XRDConstants.XML_NAMESPACE)
	private String id;
	
	@XmlAnyAttribute
	private Map<QName, Object> unknownAttributes;
	
	@XmlElement(name="Expires", namespace=XRDConstants.XRD_NAMESPACE)
	private Expires expires;
	
	@XmlElement(name="Subject", namespace=XRDConstants.XRD_NAMESPACE)
	private Subject subject;
	
	@XmlElement(name="Alias", namespace=XRDConstants.XRD_NAMESPACE)
	private List<Alias> aliases;
	
	@XmlElement(name="Property", namespace=XRDConstants.XRD_NAMESPACE)
	private List<Property> properties;
	
	@XmlElement(name="Link", namespace=XRDConstants.XRD_NAMESPACE)
	private List<Link> links;
	
	@XmlElement(name="Signature", namespace=XRDConstants.XML_SIG_NAMESPACE)
	private List<Signature> signatures;

	@XmlAnyElement
	private List<Element> unknownElements;
	
	public void setExpires(Expires expires) {
		this.expires = expires;
	}

	public Expires getExpires() {
		return expires;
	}

	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	public Subject getSubject() {
		return subject;
	}

	public void setAliases(List<Alias> aliases) {
		this.aliases = aliases;
	}

	public List<Alias> getAliases() {
		return aliases;
	}

	public void setProperties(List<Property> properties) {
		this.properties = properties;
	}

	public List<Property> getProperties() {
		return properties;
	}

	public void setLinks(List<Link> links) {
		this.links = links;
	}

	public List<Link> getLinks() {
		return links;
	}

	public void setSignatures(List<Signature> signatures) {
		this.signatures = signatures;
	}

	public List<Signature> getSignatures() {
		return signatures;
	}

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

	public String getId() {
		return id;
	}

	public void setUnknownAttributes(Map<QName, Object> unknownAttributes) {
		this.unknownAttributes = unknownAttributes;
	}

	public Map<QName, Object> getUnknownAttributes() {
		return unknownAttributes;
	}

	public void setUnknownElements(List<Element> unknownElements) {
		this.unknownElements = unknownElements;
	}

	public List<Element> getUnknownElements() {
		return unknownElements;
	}
	
	public boolean hasId() {
		return null != this.id;
	}
	
	public boolean hasExpires() {
		return null != this.expires;
	}
	
	public boolean hasSubject() {
		return null != this.subject;
	}
	
	public boolean hasAliases() {
		return null != this.aliases;
	}
	
	public boolean hasProperties() {
		return null != this.properties;
	}
	
	public boolean hasLinks() {
		return null != this.links;
	}
	
	public static XRD fromStream(InputStream stream) throws XRDException {
		JAXBContext context;
		try {
			context = JAXBContext.newInstance(XRD.class);
			return (XRD)context.createUnmarshaller().unmarshal(stream);
		} catch (JAXBException e) {
			throw new XRDException("Unable to deserialize stream into XRD", e);
		}
	}
}