1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.location.cts.asn1.supl2.ulp_components; 18 19 /* 20 */ 21 22 23 // 24 // 25 import android.location.cts.asn1.base.Asn1Null; 26 import android.location.cts.asn1.base.Asn1Object; 27 import android.location.cts.asn1.base.Asn1Sequence; 28 import android.location.cts.asn1.base.Asn1Tag; 29 import android.location.cts.asn1.base.BitStream; 30 import android.location.cts.asn1.base.BitStreamReader; 31 import android.location.cts.asn1.base.SequenceComponent; 32 import com.google.common.collect.ImmutableList; 33 import java.util.Collection; 34 import javax.annotation.Nullable; 35 36 37 /** 38 */ 39 public class SessionID extends Asn1Sequence { 40 // 41 42 private static final Asn1Tag TAG_SessionID 43 = Asn1Tag.fromClassAndNumber(-1, -1); 44 SessionID()45 public SessionID() { 46 super(); 47 } 48 49 @Override 50 @Nullable getTag()51 protected Asn1Tag getTag() { 52 return TAG_SessionID; 53 } 54 55 @Override isTagImplicit()56 protected boolean isTagImplicit() { 57 return true; 58 } 59 getPossibleFirstTags()60 public static Collection<Asn1Tag> getPossibleFirstTags() { 61 if (TAG_SessionID != null) { 62 return ImmutableList.of(TAG_SessionID); 63 } else { 64 return Asn1Sequence.getPossibleFirstTags(); 65 } 66 } 67 68 /** 69 * Creates a new SessionID from encoded stream. 70 */ fromPerUnaligned(byte[] encodedBytes)71 public static SessionID fromPerUnaligned(byte[] encodedBytes) { 72 SessionID result = new SessionID(); 73 result.decodePerUnaligned(new BitStreamReader(encodedBytes)); 74 return result; 75 } 76 77 /** 78 * Creates a new SessionID from encoded stream. 79 */ fromPerAligned(byte[] encodedBytes)80 public static SessionID fromPerAligned(byte[] encodedBytes) { 81 SessionID result = new SessionID(); 82 result.decodePerAligned(new BitStreamReader(encodedBytes)); 83 return result; 84 } 85 86 87 isExtensible()88 @Override protected boolean isExtensible() { 89 return false; 90 } 91 containsExtensionValues()92 @Override public boolean containsExtensionValues() { 93 for (SequenceComponent extensionComponent : getExtensionComponents()) { 94 if (extensionComponent.isExplicitlySet()) return true; 95 } 96 return false; 97 } 98 99 100 private SetSessionID setSessionID_; getSetSessionID()101 public SetSessionID getSetSessionID() { 102 return setSessionID_; 103 } 104 /** 105 * @throws ClassCastException if value is not a SetSessionID 106 */ setSetSessionID(Asn1Object value)107 public void setSetSessionID(Asn1Object value) { 108 this.setSessionID_ = (SetSessionID) value; 109 } setSetSessionIDToNewInstance()110 public SetSessionID setSetSessionIDToNewInstance() { 111 setSessionID_ = new SetSessionID(); 112 return setSessionID_; 113 } 114 115 private SlpSessionID slpSessionID_; getSlpSessionID()116 public SlpSessionID getSlpSessionID() { 117 return slpSessionID_; 118 } 119 /** 120 * @throws ClassCastException if value is not a SlpSessionID 121 */ setSlpSessionID(Asn1Object value)122 public void setSlpSessionID(Asn1Object value) { 123 this.slpSessionID_ = (SlpSessionID) value; 124 } setSlpSessionIDToNewInstance()125 public SlpSessionID setSlpSessionIDToNewInstance() { 126 slpSessionID_ = new SlpSessionID(); 127 return slpSessionID_; 128 } 129 130 131 132 133 134 getComponents()135 @Override public Iterable<? extends SequenceComponent> getComponents() { 136 ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder(); 137 138 builder.add(new SequenceComponent() { 139 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 0); 140 141 @Override public boolean isExplicitlySet() { 142 return getSetSessionID() != null; 143 } 144 145 @Override public boolean hasDefaultValue() { 146 return false; 147 } 148 149 @Override public boolean isOptional() { 150 return true; 151 } 152 153 @Override public Asn1Object getComponentValue() { 154 return getSetSessionID(); 155 } 156 157 @Override public void setToNewInstance() { 158 setSetSessionIDToNewInstance(); 159 } 160 161 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 162 return tag == null ? SetSessionID.getPossibleFirstTags() : ImmutableList.of(tag); 163 } 164 165 @Override 166 public Asn1Tag getTag() { 167 return tag; 168 } 169 170 @Override 171 public boolean isImplicitTagging() { 172 return true; 173 } 174 175 @Override public String toIndentedString(String indent) { 176 return "setSessionID : " 177 + getSetSessionID().toIndentedString(indent); 178 } 179 }); 180 181 builder.add(new SequenceComponent() { 182 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 1); 183 184 @Override public boolean isExplicitlySet() { 185 return getSlpSessionID() != null; 186 } 187 188 @Override public boolean hasDefaultValue() { 189 return false; 190 } 191 192 @Override public boolean isOptional() { 193 return true; 194 } 195 196 @Override public Asn1Object getComponentValue() { 197 return getSlpSessionID(); 198 } 199 200 @Override public void setToNewInstance() { 201 setSlpSessionIDToNewInstance(); 202 } 203 204 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 205 return tag == null ? SlpSessionID.getPossibleFirstTags() : ImmutableList.of(tag); 206 } 207 208 @Override 209 public Asn1Tag getTag() { 210 return tag; 211 } 212 213 @Override 214 public boolean isImplicitTagging() { 215 return true; 216 } 217 218 @Override public String toIndentedString(String indent) { 219 return "slpSessionID : " 220 + getSlpSessionID().toIndentedString(indent); 221 } 222 }); 223 224 return builder.build(); 225 } 226 227 @Override public Iterable<? extends SequenceComponent> getExtensionComponents()228 getExtensionComponents() { 229 ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder(); 230 231 return builder.build(); 232 } 233 234 235 236 237 238 239 240 241 encodePerUnaligned()242 @Override public Iterable<BitStream> encodePerUnaligned() { 243 return super.encodePerUnaligned(); 244 } 245 encodePerAligned()246 @Override public Iterable<BitStream> encodePerAligned() { 247 return super.encodePerAligned(); 248 } 249 decodePerUnaligned(BitStreamReader reader)250 @Override public void decodePerUnaligned(BitStreamReader reader) { 251 super.decodePerUnaligned(reader); 252 } 253 decodePerAligned(BitStreamReader reader)254 @Override public void decodePerAligned(BitStreamReader reader) { 255 super.decodePerAligned(reader); 256 } 257 toString()258 @Override public String toString() { 259 return toIndentedString(""); 260 } 261 toIndentedString(String indent)262 public String toIndentedString(String indent) { 263 StringBuilder builder = new StringBuilder(); 264 builder.append("SessionID = {\n"); 265 final String internalIndent = indent + " "; 266 for (SequenceComponent component : getComponents()) { 267 if (component.isExplicitlySet()) { 268 builder.append(internalIndent) 269 .append(component.toIndentedString(internalIndent)); 270 } 271 } 272 if (isExtensible()) { 273 builder.append(internalIndent).append("...\n"); 274 for (SequenceComponent component : getExtensionComponents()) { 275 if (component.isExplicitlySet()) { 276 builder.append(internalIndent) 277 .append(component.toIndentedString(internalIndent)); 278 } 279 } 280 } 281 builder.append(indent).append("};\n"); 282 return builder.toString(); 283 } 284 } 285