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