KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > model > Control


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.core.model;
22
23
24 import java.io.Serializable JavaDoc;
25
26 import org.apache.directory.ldapstudio.browser.core.model.ldif.lines.LdifControlLine;
27
28
29 /**
30  * The Control class represents a LDAP control as defined in RFC 4511
31  * <pre>
32  * Control ::= SEQUENCE {
33  * controlType LDAPOID,
34  * criticality BOOLEAN DEFAULT FALSE,
35  * controlValue OCTET STRING OPTIONAL }
36  * </pre>
37  *
38  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
39  * @version $Rev$, $Date$
40  */

41 public class Control implements Serializable JavaDoc
42 {
43
44     /** The serialVersionUID. */
45     private static final long serialVersionUID = -1289018814649849178L;
46
47     /**
48      * The subentries control as defined in RFC 3672.
49      */

50     public static final Control SUBENTRIES_CONTROL = new Control( "Subentries Control", "1.3.6.1.4.1.4203.1.10.1",
51         false, new byte[]
52             { 0x01, 0x01, ( byte ) 0xFF } );
53
54     /** The symbolic name. */
55     private String JavaDoc name;
56
57     /** The oid. */
58     private String JavaDoc oid;
59
60     /** The critical. */
61     private boolean critical;
62
63     /** The control value. */
64     private transient byte[] controlValue;
65
66
67     /**
68      * Creates a new instance of Control.
69      */

70     public Control()
71     {
72     }
73
74
75     /**
76      * Creates a new instance of Control.
77      *
78      * @param name the symbolic name
79      * @param oid the oid
80      * @param critical the criticality
81      * @param controlValue the control value
82      */

83     public Control( String JavaDoc name, String JavaDoc oid, boolean critical, byte[] controlValue )
84     {
85         super();
86         this.name = name == null ? "" : name;
87         this.oid = oid;
88         this.critical = critical;
89         this.controlValue = controlValue;
90     }
91
92
93     /**
94      * Gets the control value.
95      *
96      * @return the control value
97      */

98     public byte[] getControlValue()
99     {
100         return controlValue;
101     }
102
103
104     /**
105      * Gets the oid.
106      *
107      * @return the oid
108      */

109     public String JavaDoc getOid()
110     {
111         return oid;
112     }
113
114
115     /**
116      * Checks if is critical.
117      *
118      * @return true, if is critical
119      */

120     public boolean isCritical()
121     {
122         return critical;
123     }
124
125
126     /**
127      * Gets the symbolic name.
128      *
129      * @return the name
130      */

131     public String JavaDoc getName()
132     {
133         return name;
134     }
135
136
137     /**
138      * {@inheritDoc}
139      */

140     public String JavaDoc toString()
141     {
142
143         if ( oid == null )
144         {
145             return "";
146         }
147
148         LdifControlLine line = LdifControlLine.create( getOid(), isCritical() ? " true" : " false", getControlValue() );
149         String JavaDoc s = line.toRawString();
150         s = s.substring( line.getRawControlSpec().length(), s.length() );
151         s = s.substring( line.getRawControlType().length(), s.length() );
152         s = s.substring( 0, s.length() - line.getRawNewLine().length() );
153
154         // System.out.println(s);
155

156         return s;
157     }
158
159
160     /**
161      * Sets the control value.
162      *
163      * @param controlValue the control value
164      */

165     public void setControlValue( byte[] controlValue )
166     {
167         this.controlValue = controlValue;
168     }
169
170
171     /**
172      * Sets the critical.
173      *
174      * @param critical the critical
175      */

176     public void setCritical( boolean critical )
177     {
178         this.critical = critical;
179     }
180
181
182     /**
183      * Sets the symbolic name.
184      *
185      * @param name the name
186      */

187     public void setName( String JavaDoc name )
188     {
189         this.name = name;
190     }
191
192
193     /**
194      * Sets the oid.
195      *
196      * @param oid the oid
197      */

198     public void setOid( String JavaDoc oid )
199     {
200         this.oid = oid;
201     }
202
203
204     /**
205      * {@inheritDoc}
206      */

207     public boolean equals( Object JavaDoc obj )
208     {
209         if ( obj == null || !( obj instanceof Control ) )
210         {
211             return false;
212         }
213         Control other = ( Control ) obj;
214
215         return this.toString().equals( other.toString() );
216     }
217
218 }
219
Popular Tags