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.rrlp_messages;
18 
19 /*
20  */
21 
22 
23 //
24 //
25 import android.location.cts.asn1.base.Asn1Choice;
26 import android.location.cts.asn1.base.Asn1Null;
27 import android.location.cts.asn1.base.Asn1Object;
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.ChoiceComponent;
32 import android.location.cts.asn1.supl2.rrlp_components.AssistanceData;
33 import android.location.cts.asn1.supl2.rrlp_components.MsrPosition_Req;
34 import android.location.cts.asn1.supl2.rrlp_components.MsrPosition_Rsp;
35 import android.location.cts.asn1.supl2.rrlp_components.PosCapability_Req;
36 import android.location.cts.asn1.supl2.rrlp_components.PosCapability_Rsp;
37 import android.location.cts.asn1.supl2.rrlp_components.ProtocolError;
38 import com.google.common.collect.ImmutableList;
39 import java.nio.ByteBuffer;
40 import java.util.Collection;
41 import java.util.HashMap;
42 import java.util.Map;
43 import javax.annotation.Nullable;
44 
45 
46 /**
47  */
48 public  class RRLP_Component extends Asn1Choice {
49   //
50 
51   private static final Asn1Tag TAG_RRLP_Component
52       = Asn1Tag.fromClassAndNumber(-1, -1);
53 
54   private static final Map<Asn1Tag, Select> tagToSelection = new HashMap<>();
55 
56   private boolean extension;
57   private ChoiceComponent selection;
58   private Asn1Object element;
59 
60   static {
61     for (Select select : Select.values()) {
62       for (Asn1Tag tag : select.getPossibleFirstTags()) {
63         Select select0;
64         if ((select0 = tagToSelection.put(tag, select)) != null) {
65           throw new IllegalStateException(
66             "RRLP_Component: " + tag + " maps to both " + select0 + " and " + select);
67         }
68       }
69     }
70   }
71 
RRLP_Component()72   public RRLP_Component() {
73     super();
74   }
75 
76   @Override
77   @Nullable
getTag()78   protected Asn1Tag getTag() {
79     return TAG_RRLP_Component;
80   }
81 
82   @Override
isTagImplicit()83   protected boolean isTagImplicit() {
84     return true;
85   }
86 
getPossibleFirstTags()87   public static Collection<Asn1Tag> getPossibleFirstTags() {
88     if (TAG_RRLP_Component != null) {
89       return ImmutableList.of(TAG_RRLP_Component);
90     } else {
91       return tagToSelection.keySet();
92     }
93   }
94 
95   /**
96    * Creates a new RRLP_Component from encoded stream.
97    */
fromPerUnaligned(byte[] encodedBytes)98   public static RRLP_Component fromPerUnaligned(byte[] encodedBytes) {
99     RRLP_Component result = new RRLP_Component();
100     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
101     return result;
102   }
103 
104   /**
105    * Creates a new RRLP_Component from encoded stream.
106    */
fromPerAligned(byte[] encodedBytes)107   public static RRLP_Component fromPerAligned(byte[] encodedBytes) {
108     RRLP_Component result = new RRLP_Component();
109     result.decodePerAligned(new BitStreamReader(encodedBytes));
110     return result;
111   }
112 
113 
114 
hasExtensionValue()115   @Override protected boolean hasExtensionValue() {
116     return extension;
117   }
118 
getSelectionOrdinal()119   @Override protected Integer getSelectionOrdinal() {
120     return selection.ordinal();
121   }
122 
123   @Nullable
124   @Override
getSelectedComponent()125   protected ChoiceComponent getSelectedComponent() {
126     return selection;
127   }
128 
getOptionCount()129   @Override protected int getOptionCount() {
130     if (hasExtensionValue()) {
131       return Extend.values().length;
132     }
133     return Select.values().length;
134   }
135 
createAndSetValue(boolean isExtensionValue, int ordinal)136   protected Asn1Object createAndSetValue(boolean isExtensionValue,
137                                          int ordinal) {
138     extension = isExtensionValue;
139     if (isExtensionValue) {
140       selection = Extend.values()[ordinal];
141     } else {
142       selection = Select.values()[ordinal];
143     }
144     element = selection.createElement();
145     return element;
146   }
147 
createAndSetValue(Asn1Tag tag)148   @Override protected ChoiceComponent createAndSetValue(Asn1Tag tag) {
149     Select select = tagToSelection.get(tag);
150     if (select == null) {
151       throw new IllegalArgumentException("Unknown selection tag: " + tag);
152     }
153     element = select.createElement();
154     selection = select;
155     extension = false;
156     return select;
157   }
158 
isExtensible()159   @Override protected boolean isExtensible() {
160     return true;
161   }
162 
getValue()163   @Override protected Asn1Object getValue() {
164     return element;
165   }
166 
167 
168   private static enum Select implements ChoiceComponent {
169 
170     $MsrPositionReq(Asn1Tag.fromClassAndNumber(2, 0),
171         true) {
172       @Override
createElement()173       public Asn1Object createElement() {
174         return new MsrPosition_Req();
175       }
176 
177       @Override
getPossibleFirstTags()178       Collection<Asn1Tag> getPossibleFirstTags() {
179         return tag == null ? MsrPosition_Req.getPossibleFirstTags() : ImmutableList.of(tag);
180       }
181 
182       @Override
elementIndentedString(Asn1Object element, String indent)183       String elementIndentedString(Asn1Object element, String indent) {
184         return toString() + " : " + element.toIndentedString(indent);
185       }
186     },
187 
188     $MsrPositionRsp(Asn1Tag.fromClassAndNumber(2, 1),
189         true) {
190       @Override
createElement()191       public Asn1Object createElement() {
192         return new MsrPosition_Rsp();
193       }
194 
195       @Override
getPossibleFirstTags()196       Collection<Asn1Tag> getPossibleFirstTags() {
197         return tag == null ? MsrPosition_Rsp.getPossibleFirstTags() : ImmutableList.of(tag);
198       }
199 
200       @Override
elementIndentedString(Asn1Object element, String indent)201       String elementIndentedString(Asn1Object element, String indent) {
202         return toString() + " : " + element.toIndentedString(indent);
203       }
204     },
205 
206     $AssistanceData(Asn1Tag.fromClassAndNumber(2, 2),
207         true) {
208       @Override
createElement()209       public Asn1Object createElement() {
210         return new AssistanceData();
211       }
212 
213       @Override
getPossibleFirstTags()214       Collection<Asn1Tag> getPossibleFirstTags() {
215         return tag == null ? AssistanceData.getPossibleFirstTags() : ImmutableList.of(tag);
216       }
217 
218       @Override
elementIndentedString(Asn1Object element, String indent)219       String elementIndentedString(Asn1Object element, String indent) {
220         return toString() + " : " + element.toIndentedString(indent);
221       }
222     },
223 
224     $AssistanceDataAck(Asn1Tag.fromClassAndNumber(2, 3),
225         true) {
226       @Override
createElement()227       public Asn1Object createElement() {
228         return new RRLP_Component.assistanceDataAckType();
229       }
230 
231       @Override
getPossibleFirstTags()232       Collection<Asn1Tag> getPossibleFirstTags() {
233         return tag == null ? RRLP_Component.assistanceDataAckType.getPossibleFirstTags() : ImmutableList.of(tag);
234       }
235 
236       @Override
elementIndentedString(Asn1Object element, String indent)237       String elementIndentedString(Asn1Object element, String indent) {
238         return toString() + " : " + element.toIndentedString(indent);
239       }
240     },
241 
242     $ProtocolError(Asn1Tag.fromClassAndNumber(2, 4),
243         true) {
244       @Override
createElement()245       public Asn1Object createElement() {
246         return new ProtocolError();
247       }
248 
249       @Override
getPossibleFirstTags()250       Collection<Asn1Tag> getPossibleFirstTags() {
251         return tag == null ? ProtocolError.getPossibleFirstTags() : ImmutableList.of(tag);
252       }
253 
254       @Override
elementIndentedString(Asn1Object element, String indent)255       String elementIndentedString(Asn1Object element, String indent) {
256         return toString() + " : " + element.toIndentedString(indent);
257       }
258     },
259 
260     ;
261 
262     @Nullable final Asn1Tag tag;
263     final boolean isImplicitTagging;
264 
Select(@ullable Asn1Tag tag, boolean isImplicitTagging)265     Select(@Nullable Asn1Tag tag, boolean isImplicitTagging) {
266       this.tag = tag;
267       this.isImplicitTagging = isImplicitTagging;
268     }
269 
270     @Override
createElement()271     public Asn1Object createElement() {
272       throw new IllegalStateException("Select template error");
273     }
274 
275     @Override
276     @Nullable
getTag()277     public Asn1Tag getTag() {
278       return tag;
279     }
280 
281     @Override
isImplicitTagging()282     public boolean isImplicitTagging() {
283       return isImplicitTagging;
284     }
285 
getPossibleFirstTags()286     abstract Collection<Asn1Tag> getPossibleFirstTags();
287 
elementIndentedString(Asn1Object element, String indent)288     abstract String elementIndentedString(Asn1Object element, String indent);
289   }
290 
291 
292 
isMsrPositionReq()293   public boolean isMsrPositionReq() {
294     return !hasExtensionValue() && Select.$MsrPositionReq == selection;
295   }
296 
297   /**
298    * @throws {@code IllegalStateException} if {@code !isMsrPositionReq}.
299    */
300   @SuppressWarnings("unchecked")
getMsrPositionReq()301   public MsrPosition_Req getMsrPositionReq() {
302     if (!isMsrPositionReq()) {
303       throw new IllegalStateException("RRLP_Component value not a MsrPositionReq");
304     }
305     return (MsrPosition_Req) element;
306   }
307 
setMsrPositionReq(MsrPosition_Req selected)308   public void setMsrPositionReq(MsrPosition_Req selected) {
309     selection = Select.$MsrPositionReq;
310     extension = false;
311     element = selected;
312   }
313 
setMsrPositionReqToNewInstance()314   public MsrPosition_Req setMsrPositionReqToNewInstance() {
315       MsrPosition_Req element = new MsrPosition_Req();
316       setMsrPositionReq(element);
317       return element;
318   }
319 
320 
321 
isMsrPositionRsp()322   public boolean isMsrPositionRsp() {
323     return !hasExtensionValue() && Select.$MsrPositionRsp == selection;
324   }
325 
326   /**
327    * @throws {@code IllegalStateException} if {@code !isMsrPositionRsp}.
328    */
329   @SuppressWarnings("unchecked")
getMsrPositionRsp()330   public MsrPosition_Rsp getMsrPositionRsp() {
331     if (!isMsrPositionRsp()) {
332       throw new IllegalStateException("RRLP_Component value not a MsrPositionRsp");
333     }
334     return (MsrPosition_Rsp) element;
335   }
336 
setMsrPositionRsp(MsrPosition_Rsp selected)337   public void setMsrPositionRsp(MsrPosition_Rsp selected) {
338     selection = Select.$MsrPositionRsp;
339     extension = false;
340     element = selected;
341   }
342 
setMsrPositionRspToNewInstance()343   public MsrPosition_Rsp setMsrPositionRspToNewInstance() {
344       MsrPosition_Rsp element = new MsrPosition_Rsp();
345       setMsrPositionRsp(element);
346       return element;
347   }
348 
349 
350 
isAssistanceData()351   public boolean isAssistanceData() {
352     return !hasExtensionValue() && Select.$AssistanceData == selection;
353   }
354 
355   /**
356    * @throws {@code IllegalStateException} if {@code !isAssistanceData}.
357    */
358   @SuppressWarnings("unchecked")
getAssistanceData()359   public AssistanceData getAssistanceData() {
360     if (!isAssistanceData()) {
361       throw new IllegalStateException("RRLP_Component value not a AssistanceData");
362     }
363     return (AssistanceData) element;
364   }
365 
setAssistanceData(AssistanceData selected)366   public void setAssistanceData(AssistanceData selected) {
367     selection = Select.$AssistanceData;
368     extension = false;
369     element = selected;
370   }
371 
setAssistanceDataToNewInstance()372   public AssistanceData setAssistanceDataToNewInstance() {
373       AssistanceData element = new AssistanceData();
374       setAssistanceData(element);
375       return element;
376   }
377 
378 /*
379  */
380 
381 
382 //
383 
384 /**
385  */
386 public static class assistanceDataAckType extends Asn1Null {
387   //
388 
389   private static final Asn1Tag TAG_assistanceDataAckType
390       = Asn1Tag.fromClassAndNumber(-1, -1);
391 
assistanceDataAckType()392   public assistanceDataAckType() {
393     super();
394   }
395 
396   @Override
397   @Nullable
getTag()398   protected Asn1Tag getTag() {
399     return TAG_assistanceDataAckType;
400   }
401 
402   @Override
isTagImplicit()403   protected boolean isTagImplicit() {
404     return true;
405   }
406 
getPossibleFirstTags()407   public static Collection<Asn1Tag> getPossibleFirstTags() {
408     if (TAG_assistanceDataAckType != null) {
409       return ImmutableList.of(TAG_assistanceDataAckType);
410     } else {
411       return Asn1Null.getPossibleFirstTags();
412     }
413   }
414 
415   /**
416    * Creates a new assistanceDataAckType from encoded stream.
417    */
fromPerUnaligned(byte[] encodedBytes)418   public static assistanceDataAckType fromPerUnaligned(byte[] encodedBytes) {
419     assistanceDataAckType result = new assistanceDataAckType();
420     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
421     return result;
422   }
423 
424   /**
425    * Creates a new assistanceDataAckType from encoded stream.
426    */
fromPerAligned(byte[] encodedBytes)427   public static assistanceDataAckType fromPerAligned(byte[] encodedBytes) {
428     assistanceDataAckType result = new assistanceDataAckType();
429     result.decodePerAligned(new BitStreamReader(encodedBytes));
430     return result;
431   }
432 
encodePerUnaligned()433   @Override public Iterable<BitStream> encodePerUnaligned() {
434     return super.encodePerUnaligned();
435   }
436 
encodePerAligned()437   @Override public Iterable<BitStream> encodePerAligned() {
438     return super.encodePerAligned();
439   }
440 
decodePerUnaligned(BitStreamReader reader)441   @Override public void decodePerUnaligned(BitStreamReader reader) {
442     super.decodePerUnaligned(reader);
443   }
444 
decodePerAligned(BitStreamReader reader)445   @Override public void decodePerAligned(BitStreamReader reader) {
446     super.decodePerAligned(reader);
447   }
448 
toString()449   @Override public String toString() {
450     return toIndentedString("");
451   }
452 
toIndentedString(String indent)453   public String toIndentedString(String indent) {
454     return "assistanceDataAckType (null value);\n";
455   }
456 }
457 
458 
isAssistanceDataAck()459   public boolean isAssistanceDataAck() {
460     return !hasExtensionValue() && Select.$AssistanceDataAck == selection;
461   }
462 
463   /**
464    * @throws {@code IllegalStateException} if {@code !isAssistanceDataAck}.
465    */
466   @SuppressWarnings("unchecked")
getAssistanceDataAck()467   public RRLP_Component.assistanceDataAckType getAssistanceDataAck() {
468     if (!isAssistanceDataAck()) {
469       throw new IllegalStateException("RRLP_Component value not a AssistanceDataAck");
470     }
471     return (RRLP_Component.assistanceDataAckType) element;
472   }
473 
setAssistanceDataAck(RRLP_Component.assistanceDataAckType selected)474   public void setAssistanceDataAck(RRLP_Component.assistanceDataAckType selected) {
475     selection = Select.$AssistanceDataAck;
476     extension = false;
477     element = selected;
478   }
479 
setAssistanceDataAckToNewInstance()480   public RRLP_Component.assistanceDataAckType setAssistanceDataAckToNewInstance() {
481       RRLP_Component.assistanceDataAckType element = new RRLP_Component.assistanceDataAckType();
482       setAssistanceDataAck(element);
483       return element;
484   }
485 
486 
487 
isProtocolError()488   public boolean isProtocolError() {
489     return !hasExtensionValue() && Select.$ProtocolError == selection;
490   }
491 
492   /**
493    * @throws {@code IllegalStateException} if {@code !isProtocolError}.
494    */
495   @SuppressWarnings("unchecked")
getProtocolError()496   public ProtocolError getProtocolError() {
497     if (!isProtocolError()) {
498       throw new IllegalStateException("RRLP_Component value not a ProtocolError");
499     }
500     return (ProtocolError) element;
501   }
502 
setProtocolError(ProtocolError selected)503   public void setProtocolError(ProtocolError selected) {
504     selection = Select.$ProtocolError;
505     extension = false;
506     element = selected;
507   }
508 
setProtocolErrorToNewInstance()509   public ProtocolError setProtocolErrorToNewInstance() {
510       ProtocolError element = new ProtocolError();
511       setProtocolError(element);
512       return element;
513   }
514 
515 
516   private static enum Extend implements ChoiceComponent {
517 
518     $PosCapabilityReq(Asn1Tag.fromClassAndNumber(2, 5),
519         true) {
520       @Override
createElement()521       public Asn1Object createElement() {
522         return new PosCapability_Req();
523       }
524 
525       @Override
526       @SuppressWarnings("unchecked")
elementIndentedString(Asn1Object element, String indent)527       String elementIndentedString(Asn1Object element, String indent) {
528         return toString() + " : " + ((PosCapability_Req) element).toIndentedString(indent);
529       }
530     },
531 
532     $PosCapabilityRsp(Asn1Tag.fromClassAndNumber(2, 6),
533         true) {
534       @Override
createElement()535       public Asn1Object createElement() {
536         return new PosCapability_Rsp();
537       }
538 
539       @Override
540       @SuppressWarnings("unchecked")
elementIndentedString(Asn1Object element, String indent)541       String elementIndentedString(Asn1Object element, String indent) {
542         return toString() + " : " + ((PosCapability_Rsp) element).toIndentedString(indent);
543       }
544     },
545 
546     ;
547     @Nullable private final Asn1Tag tag;
548     private final boolean isImplicitTagging;
549 
Extend(@ullable Asn1Tag tag, boolean isImplicitTagging)550     Extend(@Nullable Asn1Tag tag, boolean isImplicitTagging) {
551       this.tag = tag;
552       this.isImplicitTagging = isImplicitTagging;
553     }
554 
createElement()555     public Asn1Object createElement() {
556       throw new IllegalStateException("Extend template error");
557     }
558 
559     @Override
560     @Nullable
getTag()561     public Asn1Tag getTag() {
562       return tag;
563     }
564 
565     @Override
isImplicitTagging()566     public boolean isImplicitTagging() {
567       return isImplicitTagging;
568     }
569 
elementIndentedString(Asn1Object element, String indent)570     String elementIndentedString(Asn1Object element, String indent) {
571       throw new IllegalStateException("Extend template error");
572     }
573   }
574 
575 
576 
isExtensionPosCapabilityReq()577   public boolean isExtensionPosCapabilityReq() {
578     return hasExtensionValue() && Extend.$PosCapabilityReq == selection;
579   }
580 
581   /**
582    * @throws {@code IllegalStateException} if {@code !isPosCapabilityReq}.
583    */
584   @SuppressWarnings("unchecked")
getExtensionPosCapabilityReq()585   public PosCapability_Req getExtensionPosCapabilityReq() {
586     if (!isExtensionPosCapabilityReq()) {
587       throw new IllegalStateException("RRLP_Component value not a PosCapabilityReq");
588     }
589     return (PosCapability_Req) element;
590   }
591 
setExtensionPosCapabilityReq(PosCapability_Req selected)592   public void setExtensionPosCapabilityReq(PosCapability_Req selected) {
593     selection = Extend.$PosCapabilityReq;
594     extension = true;
595     element = selected;
596   }
597 
setExtensionPosCapabilityReqToNewInstance()598   public void setExtensionPosCapabilityReqToNewInstance() {
599       PosCapability_Req element = new PosCapability_Req();
600       setExtensionPosCapabilityReq(element);
601   }
602 
603 
604 
isExtensionPosCapabilityRsp()605   public boolean isExtensionPosCapabilityRsp() {
606     return hasExtensionValue() && Extend.$PosCapabilityRsp == selection;
607   }
608 
609   /**
610    * @throws {@code IllegalStateException} if {@code !isPosCapabilityRsp}.
611    */
612   @SuppressWarnings("unchecked")
getExtensionPosCapabilityRsp()613   public PosCapability_Rsp getExtensionPosCapabilityRsp() {
614     if (!isExtensionPosCapabilityRsp()) {
615       throw new IllegalStateException("RRLP_Component value not a PosCapabilityRsp");
616     }
617     return (PosCapability_Rsp) element;
618   }
619 
setExtensionPosCapabilityRsp(PosCapability_Rsp selected)620   public void setExtensionPosCapabilityRsp(PosCapability_Rsp selected) {
621     selection = Extend.$PosCapabilityRsp;
622     extension = true;
623     element = selected;
624   }
625 
setExtensionPosCapabilityRspToNewInstance()626   public void setExtensionPosCapabilityRspToNewInstance() {
627       PosCapability_Rsp element = new PosCapability_Rsp();
628       setExtensionPosCapabilityRsp(element);
629   }
630 
631 
encodePerUnaligned()632   @Override public Iterable<BitStream> encodePerUnaligned() {
633     return super.encodePerUnaligned();
634   }
635 
encodePerAligned()636   @Override public Iterable<BitStream> encodePerAligned() {
637     return super.encodePerAligned();
638   }
639 
decodePerUnaligned(BitStreamReader reader)640   @Override public void decodePerUnaligned(BitStreamReader reader) {
641     super.decodePerUnaligned(reader);
642   }
643 
decodePerAligned(BitStreamReader reader)644   @Override public void decodePerAligned(BitStreamReader reader) {
645     super.decodePerAligned(reader);
646   }
647 
toString()648   @Override public String toString() {
649     return toIndentedString("");
650   }
651 
elementIndentedString(String indent)652   private String elementIndentedString(String indent) {
653     if (element == null) {
654       return "null;\n";
655     }
656     if (extension) {
657       return Extend.values()[selection.ordinal()]
658           .elementIndentedString(element, indent + "  ");
659     } else {
660       return Select.values()[selection.ordinal()]
661           .elementIndentedString(element, indent + "  ");
662     }
663   }
664 
toIndentedString(String indent)665   public String toIndentedString(String indent) {
666     return "RRLP_Component = " + elementIndentedString(indent) + indent + ";\n";
667   }
668 }
669