2
* Copyright 2005-2012 Restlet S.A.S.
4
* The contents of this file are subject to the terms of one of the following
5
* open source licenses: Apache 2.0 or LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL
6
* 1.0 (the "Licenses"). You can select the license that you prefer but you may
7
* not use this file except in compliance with one of these Licenses.
9
* You can obtain a copy of the Apache 2.0 license at
10
* http://www.opensource.org/licenses/apache-2.0
12
* You can obtain a copy of the LGPL 3.0 license at
13
* http://www.opensource.org/licenses/lgpl-3.0
15
* You can obtain a copy of the LGPL 2.1 license at
16
* http://www.opensource.org/licenses/lgpl-2.1
18
* You can obtain a copy of the CDDL 1.0 license at
19
* http://www.opensource.org/licenses/cddl1
21
* You can obtain a copy of the EPL 1.0 license at
22
* http://www.opensource.org/licenses/eclipse-1.0
24
* See the Licenses for the specific language governing permissions and
25
* limitations under the Licenses.
27
* Alternatively, you can obtain a royalty free commercial license with less
28
* limitations, transferable or non-transferable, directly at
29
* http://www.restlet.com/products/restlet-framework
31
* Restlet is a registered trademark of Restlet S.A.S.
34
package org.restlet.ext.wadl;
36
import static org.restlet.ext.wadl.WadlRepresentation.APP_NAMESPACE;
38
import java.util.ArrayList;
39
import java.util.List;
42
import org.restlet.ext.xml.XmlWriter;
43
import org.xml.sax.SAXException;
46
* Describes the grammars used by representation descriptions. This is
47
* especially useful to formally describe XML representations using XML Schema
48
* or Relax NG standards.
50
* @author Jerome Louvel
52
public class GrammarsInfo extends DocumentedInfo {
54
/** Definitions of data format descriptions to be included by reference. */
55
private List<IncludeInfo> includes;
60
public GrammarsInfo() {
65
* Constructor with a single documentation element.
67
* @param documentation
68
* A single documentation element.
70
public GrammarsInfo(DocumentationInfo documentation) {
75
* Constructor with a list of documentation elements.
77
* @param documentations
78
* The list of documentation elements.
80
public GrammarsInfo(List<DocumentationInfo> documentations) {
81
super(documentations);
85
* Constructor with a single documentation element.
87
* @param documentation
88
* A single documentation element.
90
public GrammarsInfo(String documentation) {
95
* Returns the list of include elements.
97
* @return The list of include elements.
99
public List<IncludeInfo> getIncludes() {
100
// Lazy initialization with double-check.
101
List<IncludeInfo> i = this.includes;
103
synchronized (this) {
106
this.includes = i = new ArrayList<IncludeInfo>();
114
* Sets the list of include elements.
117
* The list of include elements.
119
public void setIncludes(List<IncludeInfo> includes) {
120
this.includes = includes;
124
public void updateNamespaces(Map<String, String> namespaces) {
125
namespaces.putAll(resolveNamespaces());
127
for (final IncludeInfo includeInfo : getIncludes()) {
128
includeInfo.updateNamespaces(namespaces);
133
* Writes the current object as an XML element using the given SAX writer.
137
* @throws SAXException
139
public void writeElement(XmlWriter writer) throws SAXException {
141
if (getDocumentations().isEmpty() && getIncludes().isEmpty()) {
142
writer.emptyElement(APP_NAMESPACE, "grammars");
144
writer.startElement(APP_NAMESPACE, "grammars");
146
for (final DocumentationInfo documentationInfo : getDocumentations()) {
147
documentationInfo.writeElement(writer);
150
for (final IncludeInfo includeInfo : getIncludes()) {
151
includeInfo.writeElement(writer);
154
writer.endElement(APP_NAMESPACE, "grammars");