• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.hotspot2.omadm;
2 
3 import java.io.IOException;
4 import java.io.OutputStream;
5 import java.util.Collection;
6 import java.util.Iterator;
7 import java.util.Map;
8 
9 public class OMAScalar extends OMANode {
10     private final String mValue;
11 
OMAScalar(OMAConstructed parent, String name, String context, String value, String ... avps)12     public OMAScalar(OMAConstructed parent, String name, String context, String value,
13                      String ... avps) {
14         this(parent, name, context, value, buildAttributes(avps));
15     }
16 
OMAScalar(OMAConstructed parent, String name, String context, String value, Map<String, String> avps)17     public OMAScalar(OMAConstructed parent, String name, String context, String value,
18                      Map<String, String> avps) {
19         super(parent, name, context, avps);
20         mValue = value;
21     }
22 
23     @Override
reparent(OMAConstructed parent)24     public OMAScalar reparent(OMAConstructed parent) {
25         return new OMAScalar(parent, getName(), getContext(), mValue, getAttributes());
26     }
27 
getScalarValue(Iterator<String> path)28     public String getScalarValue(Iterator<String> path) throws OMAException {
29         return mValue;
30     }
31 
32     @Override
getListValue(Iterator<String> path)33     public OMANode getListValue(Iterator<String> path) throws OMAException {
34         throw new OMAException("Scalar encountered in list path: " + getPathString());
35     }
36 
37     @Override
isLeaf()38     public boolean isLeaf() {
39         return true;
40     }
41 
42     @Override
getChildren()43     public Collection<OMANode> getChildren() {
44         throw new UnsupportedOperationException();
45     }
46 
47     @Override
getValue()48     public String getValue() {
49         return mValue;
50     }
51 
52     @Override
getChild(String name)53     public OMANode getChild(String name) throws OMAException {
54         throw new OMAException("'" + getName() + "' is a scalar node");
55     }
56 
57     @Override
addChild(String name, String context, String value, String path)58     public OMANode addChild(String name, String context, String value, String path)
59             throws IOException {
60         throw new UnsupportedOperationException();
61     }
62 
63     @Override
toString(StringBuilder sb, int level)64     public void toString(StringBuilder sb, int level) {
65         sb.append(getPathString()).append('=').append(mValue);
66         if (getContext() != null) {
67             sb.append(" (").append(getContext()).append(')');
68         }
69         sb.append('\n');
70     }
71 
72     @Override
marshal(OutputStream out, int level)73     public void marshal(OutputStream out, int level) throws IOException {
74         OMAConstants.indent(level, out);
75         OMAConstants.serializeString(getName(), out);
76         out.write((byte) '=');
77         OMAConstants.serializeString(getValue(), out);
78         out.write((byte) '\n');
79     }
80 
81     @Override
fillPayload(StringBuilder sb)82     public void fillPayload(StringBuilder sb) {
83         sb.append('<').append(MOTree.ValueTag).append('>');
84         sb.append(mValue);
85         sb.append("</").append(MOTree.ValueTag).append(">\n");
86     }
87 }
88