New tests.
[mono.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap.Rfc2251 / RfcLdapSuperDN.cs
1 //
2 // Novell.Directory.Ldap.Rfc2251.RfcLdapSuperDN.cs
3 //
4 // Author:
5 //   Boris Kirzner (borisk@mainsoft.com)
6 //
7
8 using System;
9 using Novell.Directory.Ldap.Asn1;
10
11 namespace Novell.Directory.Ldap.Rfc2251\r
12 {\r
13         ///<summary>Represents an [0] LDAP DN OPTIONAL used as newSuperior attribute of\r
14         /// ModifyDNRequest (For more detail on this Syntax refer to rfc2251).\r
15         /// </summary>\r
16         public class RfcLdapSuperDN : Asn1Tagged\r
17         {\r
18                 private sbyte[] content;\r
19         \r
20                 /// <summary>\r
21                 /// ASN.1 [0] LDAP DN OPTIONAL tag definition.\r
22                 /// </summary>\r
23                 public static readonly int TAG = 0x00;\r
24 \r
25                 /// <summary> ID is added for Optimization.\r
26                 /// Id needs only be one Value for every instance, thus we create it only once.\r
27                 /// </summary>\r
28                 protected static readonly Asn1Identifier ID = new Asn1Identifier(Asn1Identifier.CONTEXT, false, TAG);\r
29            \r
30                 /// <summary> Constructs an RfcLDAPSuperDN object from a String object.\r
31                 /// </summary>\r
32                 /// <param name="content"> A string value that will be contained in the this RfcLDAPSuperDN object </param>\r
33                 public RfcLdapSuperDN(String s) : base(ID, new Asn1OctetString(s), false) //type is encoded IMPLICITLY \r
34                 {                       \r
35                         try {\r
36                                 System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("utf-8"); 
37                                 byte[] ibytes = encoder.GetBytes(s);
38                                 sbyte[] sbytes=SupportClass.ToSByteArray(ibytes);
39
40                                 this.content = sbytes;\r
41                         } \r
42                         catch(System.IO.IOException uee) {\r
43                                 throw new System.SystemException(uee.ToString());\r
44                         }\r
45                 }\r
46                 \r
47                 /// <summary> Constructs an RfcLDAPSuperDN object from a byte array. </summary>\r
48                 /// <param name="content"> A byte array representing the string that will be contained in the this RfcLDAPSuperDN object </param>\r
49                 [CLSCompliantAttribute(false)]\r
50                 public RfcLdapSuperDN(sbyte[] ba) : base(ID, new Asn1OctetString(ba), false) //type is encoded IMPLICITLY \r
51                 {                       \r
52                         this.content = ba;\r
53                 }\r
54         \r
55                 /// <summary> Encodes the current instance into the
56                 /// specified output stream using the specified encoder object.
57                 /// 
58                 /// </summary>
59                 /// <param name="enc">Encoder object to use when encoding self.
60                 /// 
61                 /// </param>
62                 /// <param name="out">The output stream onto which the encoded byte
63                 /// stream is written.
64                 /// </param>
65                 public override void  encode(Asn1Encoder enc, System.IO.Stream out_Renamed)
66                 {
67                         enc.encode(this, out_Renamed);
68                         return ;
69                 }\r
70 \r
71                 /// <summary> Returns the content of this RfcLdapSuperDN as a byte array.</summary>
72                 [CLSCompliantAttribute(false)]
73                 public sbyte[] byteValue()
74                 {
75                         return content;
76                 }
77                 
78                 
79                 /// <summary> Returns the content of this RfcLdapSuperDN as a String.</summary>
80                 public System.String stringValue()
81                 {
82                         System.String s = null;
83                         try {
84                                 System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("utf-8"); 
85                                 char[] dchar = encoder.GetChars(SupportClass.ToByteArray(content));
86                                 s = new String(dchar);
87                         }
88                         catch (System.IO.IOException uee) {
89                                 throw new System.SystemException(uee.ToString());
90                         }                       
91                         return s;
92                 }
93                 
94                 
95                 /// <summary> Return a String representation of this RfcLdapSuperDN.</summary>
96                 public override System.String ToString()
97                 {
98                         return base.ToString() + " " + stringValue();
99                 }\r
100 \r
101         }\r
102 }\r