Home | History | Annotate | Download | only in rrlp_components
      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_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 android.location.cts.asn1.supl2.map_extensiondatatypes.ExtensionContainer;
     33 import com.google.common.collect.ImmutableList;
     34 import java.util.Collection;
     35 import javax.annotation.Nullable;
     36 
     37 
     38 /**
     39 */
     40 public  class ProtocolError extends Asn1Sequence {
     41   //
     42 
     43   private static final Asn1Tag TAG_ProtocolError
     44       = Asn1Tag.fromClassAndNumber(-1, -1);
     45 
     46   public ProtocolError() {
     47     super();
     48   }
     49 
     50   @Override
     51   @Nullable
     52   protected Asn1Tag getTag() {
     53     return TAG_ProtocolError;
     54   }
     55 
     56   @Override
     57   protected boolean isTagImplicit() {
     58     return true;
     59   }
     60 
     61   public static Collection<Asn1Tag> getPossibleFirstTags() {
     62     if (TAG_ProtocolError != null) {
     63       return ImmutableList.of(TAG_ProtocolError);
     64     } else {
     65       return Asn1Sequence.getPossibleFirstTags();
     66     }
     67   }
     68 
     69   /**
     70    * Creates a new ProtocolError from encoded stream.
     71    */
     72   public static ProtocolError fromPerUnaligned(byte[] encodedBytes) {
     73     ProtocolError result = new ProtocolError();
     74     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
     75     return result;
     76   }
     77 
     78   /**
     79    * Creates a new ProtocolError from encoded stream.
     80    */
     81   public static ProtocolError fromPerAligned(byte[] encodedBytes) {
     82     ProtocolError result = new ProtocolError();
     83     result.decodePerAligned(new BitStreamReader(encodedBytes));
     84     return result;
     85   }
     86 
     87 
     88 
     89   @Override protected boolean isExtensible() {
     90     return true;
     91   }
     92 
     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 ErrorCodes errorCause_;
    102   public ErrorCodes getErrorCause() {
    103     return errorCause_;
    104   }
    105   /**
    106    * @throws ClassCastException if value is not a ErrorCodes
    107    */
    108   public void setErrorCause(Asn1Object value) {
    109     this.errorCause_ = (ErrorCodes) value;
    110   }
    111   public ErrorCodes setErrorCauseToNewInstance() {
    112     errorCause_ = new ErrorCodes();
    113     return errorCause_;
    114   }
    115 
    116   private ExtensionContainer extensionContainer_;
    117   public ExtensionContainer getExtensionContainer() {
    118     return extensionContainer_;
    119   }
    120   /**
    121    * @throws ClassCastException if value is not a ExtensionContainer
    122    */
    123   public void setExtensionContainer(Asn1Object value) {
    124     this.extensionContainer_ = (ExtensionContainer) value;
    125   }
    126   public ExtensionContainer setExtensionContainerToNewInstance() {
    127     extensionContainer_ = new ExtensionContainer();
    128     return extensionContainer_;
    129   }
    130 
    131 
    132 
    133   private Rel_5_ProtocolError_Extension  extensionRel_5_ProtocolError_Extension;
    134   public Rel_5_ProtocolError_Extension getExtensionRel_5_ProtocolError_Extension() {
    135     return extensionRel_5_ProtocolError_Extension;
    136   }
    137   /**
    138    * @throws ClassCastException if value is not a Rel_5_ProtocolError_Extension
    139    */
    140   public void setExtensionRel_5_ProtocolError_Extension(Asn1Object value) {
    141     extensionRel_5_ProtocolError_Extension = (Rel_5_ProtocolError_Extension) value;
    142   }
    143   public void setExtensionRel_5_ProtocolError_ExtensionToNewInstance() {
    144     extensionRel_5_ProtocolError_Extension = new Rel_5_ProtocolError_Extension();
    145   }
    146 
    147 
    148 
    149 
    150   @Override public Iterable<? extends SequenceComponent> getComponents() {
    151     ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder();
    152 
    153     builder.add(new SequenceComponent() {
    154           Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 0);
    155 
    156           @Override public boolean isExplicitlySet() {
    157             return getErrorCause() != null;
    158           }
    159 
    160           @Override public boolean hasDefaultValue() {
    161             return false;
    162           }
    163 
    164           @Override public boolean isOptional() {
    165             return false;
    166           }
    167 
    168           @Override public Asn1Object getComponentValue() {
    169             return getErrorCause();
    170           }
    171 
    172           @Override public void setToNewInstance() {
    173             setErrorCauseToNewInstance();
    174           }
    175 
    176           @Override public Collection<Asn1Tag> getPossibleFirstTags() {
    177             return tag == null ? ErrorCodes.getPossibleFirstTags() : ImmutableList.of(tag);
    178           }
    179 
    180           @Override
    181           public Asn1Tag getTag() {
    182             return tag;
    183           }
    184 
    185           @Override
    186           public boolean isImplicitTagging() {
    187             return true;
    188           }
    189 
    190           @Override public String toIndentedString(String indent) {
    191                 return "errorCause : "
    192                     + getErrorCause().toIndentedString(indent);
    193               }
    194         });
    195 
    196     builder.add(new SequenceComponent() {
    197           Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 1);
    198 
    199           @Override public boolean isExplicitlySet() {
    200             return getExtensionContainer() != null;
    201           }
    202 
    203           @Override public boolean hasDefaultValue() {
    204             return false;
    205           }
    206 
    207           @Override public boolean isOptional() {
    208             return true;
    209           }
    210 
    211           @Override public Asn1Object getComponentValue() {
    212             return getExtensionContainer();
    213           }
    214 
    215           @Override public void setToNewInstance() {
    216             setExtensionContainerToNewInstance();
    217           }
    218 
    219           @Override public Collection<Asn1Tag> getPossibleFirstTags() {
    220             return tag == null ? ExtensionContainer.getPossibleFirstTags() : ImmutableList.of(tag);
    221           }
    222 
    223           @Override
    224           public Asn1Tag getTag() {
    225             return tag;
    226           }
    227 
    228           @Override
    229           public boolean isImplicitTagging() {
    230             return true;
    231           }
    232 
    233           @Override public String toIndentedString(String indent) {
    234                 return "extensionContainer : "
    235                     + getExtensionContainer().toIndentedString(indent);
    236               }
    237         });
    238 
    239     return builder.build();
    240   }
    241 
    242   @Override public Iterable<? extends SequenceComponent>
    243                                                     getExtensionComponents() {
    244     ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder();
    245 
    246       builder.add(new SequenceComponent() {
    247             @Override public boolean isExplicitlySet() {
    248               return getExtensionRel_5_ProtocolError_Extension() != null;
    249             }
    250 
    251             @Override public boolean hasDefaultValue() {
    252               return false;
    253             }
    254 
    255             @Override public boolean isOptional() {
    256               return true;
    257             }
    258 
    259             @Override public Asn1Object getComponentValue() {
    260               return getExtensionRel_5_ProtocolError_Extension();
    261             }
    262 
    263             @Override public void setToNewInstance() {
    264               setExtensionRel_5_ProtocolError_ExtensionToNewInstance();
    265             }
    266 
    267             @Override public Collection<Asn1Tag> getPossibleFirstTags() {
    268               throw new UnsupportedOperationException(
    269                   "BER decoding not supported for extension elements");
    270             }
    271 
    272             @Override
    273             public Asn1Tag getTag() {
    274               throw new UnsupportedOperationException(
    275                   "BER is not supported for extension elements");
    276             }
    277 
    278             @Override
    279             public boolean isImplicitTagging() {
    280               throw new UnsupportedOperationException(
    281                   "BER is not supported for extension elements");
    282             }
    283 
    284             @Override public String toIndentedString(String indent) {
    285               return "rel_5_ProtocolError_Extension : "
    286                   + getExtensionRel_5_ProtocolError_Extension().toIndentedString(indent);
    287             }
    288       });
    289 
    290       return builder.build();
    291     }
    292 
    293 
    294 
    295 
    296 
    297 
    298 
    299 
    300 
    301 
    302 
    303   @Override public Iterable<BitStream> encodePerUnaligned() {
    304     return super.encodePerUnaligned();
    305   }
    306 
    307   @Override public Iterable<BitStream> encodePerAligned() {
    308     return super.encodePerAligned();
    309   }
    310 
    311   @Override public void decodePerUnaligned(BitStreamReader reader) {
    312     super.decodePerUnaligned(reader);
    313   }
    314 
    315   @Override public void decodePerAligned(BitStreamReader reader) {
    316     super.decodePerAligned(reader);
    317   }
    318 
    319   @Override public String toString() {
    320     return toIndentedString("");
    321   }
    322 
    323   public String toIndentedString(String indent) {
    324     StringBuilder builder = new StringBuilder();
    325     builder.append("ProtocolError = {\n");
    326     final String internalIndent = indent + "  ";
    327     for (SequenceComponent component : getComponents()) {
    328       if (component.isExplicitlySet()) {
    329         builder.append(internalIndent)
    330             .append(component.toIndentedString(internalIndent));
    331       }
    332     }
    333     if (isExtensible()) {
    334       builder.append(internalIndent).append("...\n");
    335       for (SequenceComponent component : getExtensionComponents()) {
    336         if (component.isExplicitlySet()) {
    337           builder.append(internalIndent)
    338               .append(component.toIndentedString(internalIndent));
    339         }
    340       }
    341     }
    342     builder.append(indent).append("};\n");
    343     return builder.toString();
    344   }
    345 }
    346