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