001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * https://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.dsmlv2.request; 021 022 023import org.apache.directory.api.asn1.util.Oid; 024import org.apache.directory.api.dsmlv2.ParserUtils; 025import org.apache.directory.api.ldap.codec.api.LdapApiService; 026import org.apache.directory.api.ldap.model.message.Control; 027import org.apache.directory.api.ldap.model.message.ExtendedRequest; 028import org.apache.directory.api.ldap.model.message.ExtendedResponse; 029import org.apache.directory.api.ldap.model.message.MessageTypeEnum; 030import org.dom4j.Element; 031import org.dom4j.Namespace; 032import org.dom4j.QName; 033 034 035/** 036 * DSML Decorator for ExtendedRequest 037 * 038 * @param <Q> The extended request type 039 * @param <P> The extended response type 040 * 041 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 042 */ 043public class ExtendedRequestDsml<Q extends ExtendedRequest, P extends ExtendedResponse> 044 extends AbstractResultResponseRequestDsml<Q, P> 045 implements ExtendedRequest 046{ 047 private byte[] requestValue; 048 049 050 /** 051 * Creates a new getDecoratedMessage() of ExtendedRequestDsml. 052 * 053 * @param codec The LDAP Service to use 054 * @param ldapMessage the message to decorate 055 */ 056 public ExtendedRequestDsml( LdapApiService codec, Q ldapMessage ) 057 { 058 super( codec, ldapMessage ); 059 } 060 061 062 /** 063 * {@inheritDoc} 064 */ 065 @Override 066 public MessageTypeEnum getType() 067 { 068 return getDecorated().getType(); 069 } 070 071 072 /** 073 * {@inheritDoc} 074 */ 075 @Override 076 public Element toDsml( Element root ) 077 { 078 Element element = super.toDsml( root ); 079 080 // Request Name 081 if ( getDecorated().getRequestName() != null ) 082 { 083 element.addElement( "requestName" ).setText( 084 getDecorated().getRequestName() ); 085 } 086 087 // Request Value 088 Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI ); 089 Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI ); 090 element.getDocument().getRootElement().add( xsdNamespace ); 091 element.getDocument().getRootElement().add( xsiNamespace ); 092 093 Element valueElement = element.addElement( "requestValue" ).addText( 094 ParserUtils.base64Encode( getRequestValue() ) ); 095 valueElement.addAttribute( new QName( "type", xsiNamespace ), 096 "xsd:" + ParserUtils.BASE64BINARY ); 097 098 return element; 099 } 100 101 102 /** 103 * Get the extended request name 104 * 105 * @return Returns the request name. 106 */ 107 @Override 108 public String getRequestName() 109 { 110 return getDecorated().getRequestName(); 111 } 112 113 114 /** 115 * Set the extended request name 116 * 117 * @param requestName The request name to set. 118 */ 119 public void setRequestName( Oid requestName ) 120 { 121 getDecorated().setRequestName( requestName.toString() ); 122 } 123 124 125 /** 126 * Get the extended request value 127 * 128 * @return Returns the request value. 129 */ 130 public byte[] getRequestValue() 131 { 132 return this.requestValue; 133 } 134 135 136 /** 137 * Set the extended request value 138 * 139 * @param requestValue The request value to set. 140 */ 141 public void setRequestValue( byte[] requestValue ) 142 { 143 this.requestValue = requestValue; 144 } 145 146 147 /** 148 * {@inheritDoc} 149 */ 150 @Override 151 public MessageTypeEnum getResponseType() 152 { 153 return getDecorated().getResponseType(); 154 } 155 156 157 /** 158 * {@inheritDoc} 159 */ 160 @Override 161 public ExtendedRequest setRequestName( String oid ) 162 { 163 getDecorated().setRequestName( oid ); 164 165 return this; 166 } 167 168 169 /** 170 * {@inheritDoc} 171 */ 172 @Override 173 public ExtendedRequest setMessageId( int messageId ) 174 { 175 super.setMessageId( messageId ); 176 177 return this; 178 } 179 180 181 /** 182 * {@inheritDoc} 183 */ 184 @Override 185 public ExtendedRequest addControl( Control control ) 186 { 187 return ( ExtendedRequest ) super.addControl( control ); 188 } 189 190 191 /** 192 * {@inheritDoc} 193 */ 194 @Override 195 public ExtendedRequest addAllControls( Control[] controls ) 196 { 197 return ( ExtendedRequest ) super.addAllControls( controls ); 198 } 199 200 201 /** 202 * {@inheritDoc} 203 */ 204 @Override 205 public ExtendedRequest removeControl( Control control ) 206 { 207 return ( ExtendedRequest ) super.removeControl( control ); 208 } 209}