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.supl_start; 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 android.location.cts.asn1.supl2.ulp_version_2_parameter_extensions.Ver2_SETCapabilities_extension; 33 import com.google.common.collect.ImmutableList; 34 import java.util.Collection; 35 import javax.annotation.Nullable; 36 37 38 /** 39 */ 40 public class SETCapabilities extends Asn1Sequence { 41 // 42 43 private static final Asn1Tag TAG_SETCapabilities 44 = Asn1Tag.fromClassAndNumber(-1, -1); 45 SETCapabilities()46 public SETCapabilities() { 47 super(); 48 } 49 50 @Override 51 @Nullable getTag()52 protected Asn1Tag getTag() { 53 return TAG_SETCapabilities; 54 } 55 56 @Override isTagImplicit()57 protected boolean isTagImplicit() { 58 return true; 59 } 60 getPossibleFirstTags()61 public static Collection<Asn1Tag> getPossibleFirstTags() { 62 if (TAG_SETCapabilities != null) { 63 return ImmutableList.of(TAG_SETCapabilities); 64 } else { 65 return Asn1Sequence.getPossibleFirstTags(); 66 } 67 } 68 69 /** 70 * Creates a new SETCapabilities from encoded stream. 71 */ fromPerUnaligned(byte[] encodedBytes)72 public static SETCapabilities fromPerUnaligned(byte[] encodedBytes) { 73 SETCapabilities result = new SETCapabilities(); 74 result.decodePerUnaligned(new BitStreamReader(encodedBytes)); 75 return result; 76 } 77 78 /** 79 * Creates a new SETCapabilities from encoded stream. 80 */ fromPerAligned(byte[] encodedBytes)81 public static SETCapabilities fromPerAligned(byte[] encodedBytes) { 82 SETCapabilities result = new SETCapabilities(); 83 result.decodePerAligned(new BitStreamReader(encodedBytes)); 84 return result; 85 } 86 87 88 isExtensible()89 @Override protected boolean isExtensible() { 90 return true; 91 } 92 containsExtensionValues()93 @Override public boolean containsExtensionValues() { 94 for (SequenceComponent extensionComponent : getExtensionComponents()) { 95 if (extensionComponent.isExplicitlySet()) return true; 96 } 97 return false; 98 } 99 100 101 private PosTechnology posTechnology_; getPosTechnology()102 public PosTechnology getPosTechnology() { 103 return posTechnology_; 104 } 105 /** 106 * @throws ClassCastException if value is not a PosTechnology 107 */ setPosTechnology(Asn1Object value)108 public void setPosTechnology(Asn1Object value) { 109 this.posTechnology_ = (PosTechnology) value; 110 } setPosTechnologyToNewInstance()111 public PosTechnology setPosTechnologyToNewInstance() { 112 posTechnology_ = new PosTechnology(); 113 return posTechnology_; 114 } 115 116 private PrefMethod prefMethod_; getPrefMethod()117 public PrefMethod getPrefMethod() { 118 return prefMethod_; 119 } 120 /** 121 * @throws ClassCastException if value is not a PrefMethod 122 */ setPrefMethod(Asn1Object value)123 public void setPrefMethod(Asn1Object value) { 124 this.prefMethod_ = (PrefMethod) value; 125 } setPrefMethodToNewInstance()126 public PrefMethod setPrefMethodToNewInstance() { 127 prefMethod_ = new PrefMethod(); 128 return prefMethod_; 129 } 130 131 private PosProtocol posProtocol_; getPosProtocol()132 public PosProtocol getPosProtocol() { 133 return posProtocol_; 134 } 135 /** 136 * @throws ClassCastException if value is not a PosProtocol 137 */ setPosProtocol(Asn1Object value)138 public void setPosProtocol(Asn1Object value) { 139 this.posProtocol_ = (PosProtocol) value; 140 } setPosProtocolToNewInstance()141 public PosProtocol setPosProtocolToNewInstance() { 142 posProtocol_ = new PosProtocol(); 143 return posProtocol_; 144 } 145 146 147 148 private Ver2_SETCapabilities_extension extensionVer2_SETCapabilities_extension; getExtensionVer2_SETCapabilities_extension()149 public Ver2_SETCapabilities_extension getExtensionVer2_SETCapabilities_extension() { 150 return extensionVer2_SETCapabilities_extension; 151 } 152 /** 153 * @throws ClassCastException if value is not a Ver2_SETCapabilities_extension 154 */ setExtensionVer2_SETCapabilities_extension(Asn1Object value)155 public void setExtensionVer2_SETCapabilities_extension(Asn1Object value) { 156 extensionVer2_SETCapabilities_extension = (Ver2_SETCapabilities_extension) value; 157 } setExtensionVer2_SETCapabilities_extensionToNewInstance()158 public void setExtensionVer2_SETCapabilities_extensionToNewInstance() { 159 extensionVer2_SETCapabilities_extension = new Ver2_SETCapabilities_extension(); 160 } 161 162 163 164 getComponents()165 @Override public Iterable<? extends SequenceComponent> getComponents() { 166 ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder(); 167 168 builder.add(new SequenceComponent() { 169 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 0); 170 171 @Override public boolean isExplicitlySet() { 172 return getPosTechnology() != null; 173 } 174 175 @Override public boolean hasDefaultValue() { 176 return false; 177 } 178 179 @Override public boolean isOptional() { 180 return false; 181 } 182 183 @Override public Asn1Object getComponentValue() { 184 return getPosTechnology(); 185 } 186 187 @Override public void setToNewInstance() { 188 setPosTechnologyToNewInstance(); 189 } 190 191 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 192 return tag == null ? PosTechnology.getPossibleFirstTags() : ImmutableList.of(tag); 193 } 194 195 @Override 196 public Asn1Tag getTag() { 197 return tag; 198 } 199 200 @Override 201 public boolean isImplicitTagging() { 202 return true; 203 } 204 205 @Override public String toIndentedString(String indent) { 206 return "posTechnology : " 207 + getPosTechnology().toIndentedString(indent); 208 } 209 }); 210 211 builder.add(new SequenceComponent() { 212 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 1); 213 214 @Override public boolean isExplicitlySet() { 215 return getPrefMethod() != null; 216 } 217 218 @Override public boolean hasDefaultValue() { 219 return false; 220 } 221 222 @Override public boolean isOptional() { 223 return false; 224 } 225 226 @Override public Asn1Object getComponentValue() { 227 return getPrefMethod(); 228 } 229 230 @Override public void setToNewInstance() { 231 setPrefMethodToNewInstance(); 232 } 233 234 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 235 return tag == null ? PrefMethod.getPossibleFirstTags() : ImmutableList.of(tag); 236 } 237 238 @Override 239 public Asn1Tag getTag() { 240 return tag; 241 } 242 243 @Override 244 public boolean isImplicitTagging() { 245 return true; 246 } 247 248 @Override public String toIndentedString(String indent) { 249 return "prefMethod : " 250 + getPrefMethod().toIndentedString(indent); 251 } 252 }); 253 254 builder.add(new SequenceComponent() { 255 Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 2); 256 257 @Override public boolean isExplicitlySet() { 258 return getPosProtocol() != null; 259 } 260 261 @Override public boolean hasDefaultValue() { 262 return false; 263 } 264 265 @Override public boolean isOptional() { 266 return false; 267 } 268 269 @Override public Asn1Object getComponentValue() { 270 return getPosProtocol(); 271 } 272 273 @Override public void setToNewInstance() { 274 setPosProtocolToNewInstance(); 275 } 276 277 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 278 return tag == null ? PosProtocol.getPossibleFirstTags() : ImmutableList.of(tag); 279 } 280 281 @Override 282 public Asn1Tag getTag() { 283 return tag; 284 } 285 286 @Override 287 public boolean isImplicitTagging() { 288 return true; 289 } 290 291 @Override public String toIndentedString(String indent) { 292 return "posProtocol : " 293 + getPosProtocol().toIndentedString(indent); 294 } 295 }); 296 297 return builder.build(); 298 } 299 300 @Override public Iterable<? extends SequenceComponent> getExtensionComponents()301 getExtensionComponents() { 302 ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder(); 303 304 builder.add(new SequenceComponent() { 305 @Override public boolean isExplicitlySet() { 306 return getExtensionVer2_SETCapabilities_extension() != null; 307 } 308 309 @Override public boolean hasDefaultValue() { 310 return false; 311 } 312 313 @Override public boolean isOptional() { 314 return true; 315 } 316 317 @Override public Asn1Object getComponentValue() { 318 return getExtensionVer2_SETCapabilities_extension(); 319 } 320 321 @Override public void setToNewInstance() { 322 setExtensionVer2_SETCapabilities_extensionToNewInstance(); 323 } 324 325 @Override public Collection<Asn1Tag> getPossibleFirstTags() { 326 throw new UnsupportedOperationException( 327 "BER decoding not supported for extension elements"); 328 } 329 330 @Override 331 public Asn1Tag getTag() { 332 throw new UnsupportedOperationException( 333 "BER is not supported for extension elements"); 334 } 335 336 @Override 337 public boolean isImplicitTagging() { 338 throw new UnsupportedOperationException( 339 "BER is not supported for extension elements"); 340 } 341 342 @Override public String toIndentedString(String indent) { 343 return "ver2_SETCapabilities_extension : " 344 + getExtensionVer2_SETCapabilities_extension().toIndentedString(indent); 345 } 346 }); 347 348 return builder.build(); 349 } 350 351 352 353 354 355 356 357 358 359 360 361 362 encodePerUnaligned()363 @Override public Iterable<BitStream> encodePerUnaligned() { 364 return super.encodePerUnaligned(); 365 } 366 encodePerAligned()367 @Override public Iterable<BitStream> encodePerAligned() { 368 return super.encodePerAligned(); 369 } 370 decodePerUnaligned(BitStreamReader reader)371 @Override public void decodePerUnaligned(BitStreamReader reader) { 372 super.decodePerUnaligned(reader); 373 } 374 decodePerAligned(BitStreamReader reader)375 @Override public void decodePerAligned(BitStreamReader reader) { 376 super.decodePerAligned(reader); 377 } 378 toString()379 @Override public String toString() { 380 return toIndentedString(""); 381 } 382 toIndentedString(String indent)383 public String toIndentedString(String indent) { 384 StringBuilder builder = new StringBuilder(); 385 builder.append("SETCapabilities = {\n"); 386 final String internalIndent = indent + " "; 387 for (SequenceComponent component : getComponents()) { 388 if (component.isExplicitlySet()) { 389 builder.append(internalIndent) 390 .append(component.toIndentedString(internalIndent)); 391 } 392 } 393 if (isExtensible()) { 394 builder.append(internalIndent).append("...\n"); 395 for (SequenceComponent component : getExtensionComponents()) { 396 if (component.isExplicitlySet()) { 397 builder.append(internalIndent) 398 .append(component.toIndentedString(internalIndent)); 399 } 400 } 401 } 402 builder.append(indent).append("};\n"); 403 return builder.toString(); 404 } 405 } 406