mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

matthew_swift
04.05.2009 efc16df69299f061fdaadd03397fa3fd395af194
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package org.opends.sdk.controls;
 
 
 
import static com.sun.opends.sdk.messages.Messages.*;
import static com.sun.opends.sdk.util.StaticUtils.*;
 
import java.io.IOException;
 
import org.opends.sdk.ByteString;
import org.opends.sdk.DecodeException;
import org.opends.sdk.asn1.ASN1Reader;
import org.opends.sdk.asn1.ASN1Writer;
 
import com.sun.opends.sdk.util.Message;
import com.sun.opends.sdk.util.Validator;
 
 
 
/**
 * Created by IntelliJ IDEA. User: boli Date: Jun 30, 2009 Time: 5:40:28
 * PM To change this template use File | Settings | File Templates.
 */
public abstract class VLVTarget
{
  public static final class ByOffset extends VLVTarget
  {
    private final int offset;
 
    private final int contentCount;
 
 
 
    private ByOffset(int offset, int contentCount)
    {
      this.offset = offset;
      this.contentCount = contentCount;
    }
 
 
 
    public int getContentCount()
    {
      return contentCount;
    }
 
 
 
    public int getOffset()
    {
      return offset;
    }
 
 
 
    @Override
    public void toString(StringBuilder buffer)
    {
      buffer.append("byOffset(offset=");
      buffer.append(offset);
      buffer.append(", contentCount=");
      buffer.append(contentCount);
      buffer.append(")");
    }
 
 
 
    @Override
    void encode(ASN1Writer writer) throws IOException
    {
      writer.writeStartSequence(TYPE_TARGET_BYOFFSET);
      writer.writeInteger(offset);
      writer.writeInteger(contentCount);
      writer.writeEndSequence();
    }
  }
 
 
 
  public static final class GreaterThanOrEqual extends VLVTarget
  {
    private final ByteString assertionValue;
 
 
 
    private GreaterThanOrEqual(ByteString assertionValue)
    {
      this.assertionValue = assertionValue;
    }
 
 
 
    public ByteString getAssertionValue()
    {
      return assertionValue;
    }
 
 
 
    @Override
    public void toString(StringBuilder buffer)
    {
      buffer.append("greaterThanOrEqual(assertionValue=");
      buffer.append(assertionValue);
      buffer.append(")");
    }
 
 
 
    @Override
    void encode(ASN1Writer writer) throws IOException
    {
      writer.writeOctetString(TYPE_TARGET_GREATERTHANOREQUAL,
          assertionValue);
    }
  }
 
 
 
  /**
   * The BER type to use when encoding the byOffset target element.
   */
  private static final byte TYPE_TARGET_BYOFFSET = (byte) 0xA0;
 
  /**
   * The BER type to use when encoding the greaterThanOrEqual target
   * element.
   */
  private static final byte TYPE_TARGET_GREATERTHANOREQUAL = (byte) 0x81;
 
 
 
  static VLVTarget byOffset(int offset, int contentCount)
  {
    return new ByOffset(offset, contentCount);
  }
 
 
 
  static VLVTarget decode(ASN1Reader reader) throws IOException,
      DecodeException
  {
    byte targetType = reader.peekType();
    switch (targetType)
    {
    case TYPE_TARGET_BYOFFSET:
      reader.readStartSequence();
      int offset = (int) reader.readInteger();
      int contentCount = (int) reader.readInteger();
      reader.readEndSequence();
      return new ByOffset(offset, contentCount);
 
    case TYPE_TARGET_GREATERTHANOREQUAL:
      ByteString assertionValue = reader.readOctetString();
      return new GreaterThanOrEqual(assertionValue);
 
    default:
      Message message = INFO_VLVREQ_CONTROL_INVALID_TARGET_TYPE
          .get(byteToHex(targetType));
      throw DecodeException.error(message);
    }
  }
 
 
 
  static VLVTarget greaterThanOrEqual(ByteString assertionValue)
  {
    Validator.ensureNotNull(assertionValue);
    return new GreaterThanOrEqual(assertionValue);
  }
 
 
 
  /**
   * {@inheritDoc}
   */
  @Override
  public String toString()
  {
    StringBuilder buffer = new StringBuilder();
    toString(buffer);
    return buffer.toString();
  }
 
 
 
  public abstract void toString(StringBuilder buffer);
 
 
 
  abstract void encode(ASN1Writer writer) throws IOException;
}