View Javadoc
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  package org.apache.directory.api.dsmlv2.request;
21  
22  
23  import org.apache.directory.api.asn1.util.Oid;
24  import org.apache.directory.api.dsmlv2.ParserUtils;
25  import org.apache.directory.api.ldap.codec.api.LdapApiService;
26  import org.apache.directory.api.ldap.model.message.Control;
27  import org.apache.directory.api.ldap.model.message.ExtendedRequest;
28  import org.apache.directory.api.ldap.model.message.ExtendedResponse;
29  import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
30  import org.dom4j.Element;
31  import org.dom4j.Namespace;
32  import org.dom4j.QName;
33  
34  
35  /**
36   * DSML Decorator for ExtendedRequest
37   * 
38   * @param <Q> The extended request type
39   * @param <P> The extended response type
40   *
41   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
42   */
43  public class ExtendedRequestDsml<Q extends ExtendedRequest, P extends ExtendedResponse>
44      extends AbstractResultResponseRequestDsml<Q, P>
45      implements ExtendedRequest
46  {
47      private byte[] requestValue;
48  
49  
50      /**
51       * Creates a new getDecoratedMessage() of ExtendedRequestDsml.
52       *
53       * @param codec The LDAP Service to use
54       * @param ldapMessage the message to decorate
55       */
56      public ExtendedRequestDsml( LdapApiService codec, Q ldapMessage )
57      {
58          super( codec, ldapMessage );
59      }
60  
61  
62      /**
63       * {@inheritDoc}
64       */
65      public MessageTypeEnum getType()
66      {
67          return getDecorated().getType();
68      }
69  
70  
71      /**
72       * {@inheritDoc}
73       */
74      public Element toDsml( Element root )
75      {
76          Element element = super.toDsml( root );
77  
78          // Request Name
79          if ( getDecorated().getRequestName() != null )
80          {
81              element.addElement( "requestName" ).setText(
82                  getDecorated().getRequestName() );
83          }
84  
85          // Request Value        
86          Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI );
87          Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI );
88          element.getDocument().getRootElement().add( xsdNamespace );
89          element.getDocument().getRootElement().add( xsiNamespace );
90  
91          Element valueElement = element.addElement( "requestValue" ).addText(
92              ParserUtils.base64Encode( getRequestValue() ) );
93          valueElement.addAttribute( new QName( "type", xsiNamespace ),
94              "xsd:" + ParserUtils.BASE64BINARY );
95  
96          return element;
97      }
98  
99  
100     /**
101      * Get the extended request name
102      * 
103      * @return Returns the request name.
104      */
105     public String getRequestName()
106     {
107         return getDecorated().getRequestName();
108     }
109 
110 
111     /**
112      * Set the extended request name
113      * 
114      * @param requestName The request name to set.
115      */
116     public void setRequestName( Oid requestName )
117     {
118         getDecorated().setRequestName( requestName.toString() );
119     }
120 
121 
122     /**
123      * Get the extended request value
124      * 
125      * @return Returns the request value.
126      */
127     public byte[] getRequestValue()
128     {
129         return this.requestValue;
130     }
131 
132 
133     /**
134      * Set the extended request value
135      * 
136      * @param requestValue The request value to set.
137      */
138     public void setRequestValue( byte[] requestValue )
139     {
140         this.requestValue = requestValue;
141     }
142 
143 
144     /**
145      * {@inheritDoc}
146      */
147     public MessageTypeEnum getResponseType()
148     {
149         return getDecorated().getResponseType();
150     }
151 
152 
153     /**
154      * {@inheritDoc}
155      */
156     public ExtendedRequest setRequestName( String oid )
157     {
158         getDecorated().setRequestName( oid );
159 
160         return this;
161     }
162 
163 
164     /**
165      * {@inheritDoc}
166      */
167     public ExtendedRequest setMessageId( int messageId )
168     {
169         super.setMessageId( messageId );
170 
171         return this;
172     }
173 
174 
175     /**
176      * {@inheritDoc}
177      */
178     public ExtendedRequest addControl( Control control )
179     {
180         return ( ExtendedRequest ) super.addControl( control );
181     }
182 
183 
184     /**
185      * {@inheritDoc}
186      */
187     public ExtendedRequest addAllControls( Control[] controls )
188     {
189         return ( ExtendedRequest ) super.addAllControls( controls );
190     }
191 
192 
193     /**
194      * {@inheritDoc}
195      */
196     public ExtendedRequest removeControl( Control control )
197     {
198         return ( ExtendedRequest ) super.removeControl( control );
199     }
200 }