2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.netconf.nettyutil.handler.exi;
10 import org.opendaylight.controller.netconf.api.NetconfMessage;
11 import org.opendaylight.controller.netconf.util.xml.XmlElement;
12 import org.openexi.proc.common.AlignmentType;
13 import org.openexi.proc.common.EXIOptions;
14 import org.openexi.proc.common.EXIOptionsException;
16 import com.google.common.base.Preconditions;
18 public final class EXIParameters {
19 private static final String EXI_PARAMETER_ALIGNMENT = "alignment";
20 private static final String EXI_PARAMETER_BYTE_ALIGNED = "byte-aligned";
21 private static final String EXI_PARAMETER_BIT_PACKED = "bit-packed";
22 private static final String EXI_PARAMETER_COMPRESSED = "compressed";
23 private static final String EXI_PARAMETER_PRE_COMPRESSION = "pre-compression";
25 private static final String EXI_PARAMETER_FIDELITY = "fidelity";
26 private static final String EXI_FIDELITY_DTD = "dtd";
27 private static final String EXI_FIDELITY_LEXICAL_VALUES = "lexical-values";
28 private static final String EXI_FIDELITY_COMMENTS = "comments";
29 private static final String EXI_FIDELITY_PIS = "pis";
30 private static final String EXI_FIDELITY_PREFIXES = "prefixes";
32 private static final String EXI_PARAMETER_SCHEMA = "schema";
33 private static final String EXI_PARAMETER_SCHEMA_NONE = "none";
34 private static final String EXI_PARAMETER_SCHEMA_BUILT_IN = "builtin";
35 private static final String EXI_PARAMETER_SCHEMA_BASE_1_1 = "base:1.1";
37 private final EXIOptions options;
39 private EXIParameters(final EXIOptions options) {
40 this.options = Preconditions.checkNotNull(options);
43 public static EXIParameters fromNetconfMessage(final NetconfMessage root) throws EXIOptionsException {
44 return fromXmlElement(XmlElement.fromDomDocument(root.getDocument()));
47 public static EXIParameters fromXmlElement(final XmlElement root) throws EXIOptionsException {
48 final EXIOptions options = new EXIOptions();
50 options.setAlignmentType(AlignmentType.bitPacked);
51 if (root.getElementsByTagName(EXI_PARAMETER_ALIGNMENT).getLength() > 0) {
52 if (root.getElementsByTagName(EXI_PARAMETER_BIT_PACKED).getLength() > 0) {
53 options.setAlignmentType(AlignmentType.bitPacked);
54 } else if (root.getElementsByTagName(EXI_PARAMETER_BYTE_ALIGNED).getLength() > 0) {
55 options.setAlignmentType(AlignmentType.byteAligned);
56 } else if (root.getElementsByTagName(EXI_PARAMETER_COMPRESSED).getLength() > 0) {
57 options.setAlignmentType(AlignmentType.compress);
58 } else if (root.getElementsByTagName(EXI_PARAMETER_PRE_COMPRESSION).getLength() > 0) {
59 options.setAlignmentType(AlignmentType.preCompress);
63 if (root.getElementsByTagName(EXI_PARAMETER_FIDELITY).getLength() > 0) {
64 if (root.getElementsByTagName(EXI_FIDELITY_DTD).getLength() > 0) {
65 options.setPreserveDTD(true);
67 if (root.getElementsByTagName(EXI_FIDELITY_LEXICAL_VALUES).getLength() > 0) {
68 options.setPreserveLexicalValues(true);
70 if (root.getElementsByTagName(EXI_FIDELITY_COMMENTS).getLength() > 0) {
71 options.setPreserveComments(true);
73 if (root.getElementsByTagName(EXI_FIDELITY_PIS).getLength() > 0) {
74 options.setPreservePIs(true);
76 if (root.getElementsByTagName(EXI_FIDELITY_PREFIXES).getLength() > 0) {
77 options.setPreserveNS(true);
81 if (root.getElementsByTagName(EXI_PARAMETER_SCHEMA).getLength() > 0) {
83 GrammarFactory grammarFactory = GrammarFactory.newInstance();
85 .getElementsByTagName(EXI_PARAMETER_SCHEMA_NONE)
87 this.grammars = grammarFactory.createSchemaLessGrammars();
90 if (operationElement.getElementsByTagName(
91 EXI_PARAMETER_SCHEMA_BUILT_IN).getLength() > 0) {
92 this.grammars = grammarFactory.createXSDTypesOnlyGrammars();
95 if (operationElement.getElementsByTagName(
96 EXI_PARAMETER_SCHEMA_BASE_1_1).getLength() > 0) {
97 this.grammars = grammarFactory
98 .createGrammars(NETCONF_XSD_LOCATION);
104 return new EXIParameters(options);
107 public final EXIOptions getOptions() {