11/*
22 Copyright 2006-2011 Abdulla Abdurakhmanov ([email protected] ) 3- Original sources are available at www.latestbit.com
4-
3+
54 Licensed under the Apache License, Version 2.0 (the "License");
65 you may not use this file except in compliance with the License.
76 You may obtain a copy of the License at
@@ -19,10 +18,9 @@ limitations under the License.
1918
2019namespace org . bn
2120{
22-
2321 public class CoderFactory
2422 {
25- private static CoderFactory instance = new CoderFactory ( ) ;
23+ private static readonly CoderFactory instance = new CoderFactory ( ) ;
2624
2725 public static CoderFactory getInstance ( ) {
2826 return instance ;
@@ -33,65 +31,64 @@ public IEncoder newEncoder() {
3331 }
3432
3533 public IEncoder newEncoder ( String encodingSchema ) {
36- if ( encodingSchema . Equals ( "BER" , StringComparison . CurrentCultureIgnoreCase ) ) {
34+ if ( encodingSchema . Equals ( "BER" , StringComparison . CurrentCultureIgnoreCase ) )
35+ {
3736 return new org . bn . coders . ber . BEREncoder ( ) ;
3837 }
39- else
40- if ( encodingSchema . Equals ( "PER" , StringComparison . CurrentCultureIgnoreCase ) ||
38+ else if ( encodingSchema . Equals ( "PER" , StringComparison . CurrentCultureIgnoreCase ) ||
4139 encodingSchema . Equals ( "PER/Aligned" , StringComparison . CurrentCultureIgnoreCase ) ||
4240 encodingSchema . Equals ( "PER/A" , StringComparison . CurrentCultureIgnoreCase ) )
4341 {
4442 return new org . bn . coders . per . PERAlignedEncoder ( ) ;
4543 }
46- else
47- if ( encodingSchema . Equals ( "PER/Unaligned" , StringComparison . CurrentCultureIgnoreCase ) ||
44+ else if ( encodingSchema . Equals ( "PER/Unaligned" , StringComparison . CurrentCultureIgnoreCase ) ||
4845 encodingSchema . Equals ( "PER/U" , StringComparison . CurrentCultureIgnoreCase ) )
4946 {
5047 return new org . bn . coders . per . PERUnalignedEncoder ( ) ;
5148 }
52- else
53- if ( encodingSchema . Equals ( "DER" , StringComparison . CurrentCultureIgnoreCase ) )
49+ else if ( encodingSchema . Equals ( "DER" , StringComparison . CurrentCultureIgnoreCase ) )
5450 {
5551 return new org . bn . coders . der . DEREncoder ( ) ;
5652 }
5753 else
58- return null ;
54+ {
55+ throw new ArgumentException ( "Unknown encoding schema '" + encodingSchema + "'" , "encodingSchema" ) ;
56+ }
5957 }
6058
6159 public IDecoder newDecoder ( ) {
6260 return newDecoder ( "BER" ) ;
6361 }
6462
6563 public IDecoder newDecoder ( String encodingSchema ) {
66- if ( encodingSchema . Equals ( "BER" , StringComparison . CurrentCultureIgnoreCase ) ) {
64+ if ( encodingSchema . Equals ( "BER" , StringComparison . CurrentCultureIgnoreCase ) )
65+ {
6766 return new org . bn . coders . ber . BERDecoder ( ) ;
6867 }
69- else
70- if ( encodingSchema . Equals ( "PER" , StringComparison . CurrentCultureIgnoreCase ) ||
68+ else if ( encodingSchema . Equals ( "PER" , StringComparison . CurrentCultureIgnoreCase ) ||
7169 encodingSchema . Equals ( "PER/Aligned" , StringComparison . CurrentCultureIgnoreCase ) ||
7270 encodingSchema . Equals ( "PER/A" , StringComparison . CurrentCultureIgnoreCase ) )
7371 {
7472 return new org . bn . coders . per . PERAlignedDecoder ( ) ;
7573 }
76- else
77- if ( encodingSchema . Equals ( "PER/Unaligned" , StringComparison . CurrentCultureIgnoreCase ) ||
74+ else if ( encodingSchema . Equals ( "PER/Unaligned" , StringComparison . CurrentCultureIgnoreCase ) ||
7875 encodingSchema . Equals ( "PER/U" , StringComparison . CurrentCultureIgnoreCase ) )
7976 {
8077 return new org . bn . coders . per . PERUnalignedDecoder ( ) ;
8178 }
82- else
83- if ( encodingSchema . Equals ( "DER" , StringComparison . CurrentCultureIgnoreCase ) )
79+ else if ( encodingSchema . Equals ( "DER" , StringComparison . CurrentCultureIgnoreCase ) )
8480 {
8581 return new org . bn . coders . der . DERDecoder ( ) ;
8682 }
8783 else
88- return null ;
84+ {
85+ throw new ArgumentException ( "Unknown encoding schema '" + encodingSchema + "'" , "encodingSchema" ) ;
86+ }
8987 }
9088
9189 public IASN1PreparedElementData newPreparedElementData ( Type typeInfo )
9290 {
9391 return new ASN1PreparedElementData ( typeInfo ) ;
9492 }
95-
9693 }
9794}
0 commit comments