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.DsmlLiterals; 025import org.apache.directory.api.dsmlv2.ParserUtils; 026import org.apache.directory.api.ldap.codec.api.LdapApiService; 027import org.apache.directory.api.ldap.model.message.Control; 028import org.apache.directory.api.ldap.model.message.ExtendedRequest; 029import org.apache.directory.api.ldap.model.message.ExtendedResponse; 030import org.apache.directory.api.ldap.model.message.MessageTypeEnum; 031import org.dom4j.Element; 032import org.dom4j.Namespace; 033import org.dom4j.QName; 034 035 036/** 037 * DSML Decorator for ExtendedRequest 038 * 039 * @param <Q> The extended request type 040 * @param <P> The extended response type 041 * 042 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 043 */ 044public class ExtendedRequestDsml<Q extends ExtendedRequest, P extends ExtendedResponse> 045 extends AbstractResultResponseRequestDsml<Q, P> 046 implements ExtendedRequest 047{ 048 private byte[] requestValue; 049 050 051 /** 052 * Creates a new getDecoratedMessage() of ExtendedRequestDsml. 053 * 054 * @param codec The LDAP Service to use 055 * @param ldapMessage the message to decorate 056 */ 057 public ExtendedRequestDsml( LdapApiService codec, Q ldapMessage ) 058 { 059 super( codec, ldapMessage ); 060 } 061 062 063 /** 064 * {@inheritDoc} 065 */ 066 @Override 067 public MessageTypeEnum getType() 068 { 069 return getDecorated().getType(); 070 } 071 072 073 /** 074 * {@inheritDoc} 075 */ 076 @Override 077 public Element toDsml( Element root ) 078 { 079 Element element = super.toDsml( root ); 080 081 // Request Name 082 if ( getDecorated().getRequestName() != null ) 083 { 084 element.addElement( DsmlLiterals.REQUEST_NAME ).setText( 085 getDecorated().getRequestName() ); 086 } 087 088 // Request Value 089 Namespace xsdNamespace = new Namespace( ParserUtils.XSD, ParserUtils.XML_SCHEMA_URI ); 090 Namespace xsiNamespace = new Namespace( ParserUtils.XSI, ParserUtils.XML_SCHEMA_INSTANCE_URI ); 091 element.getDocument().getRootElement().add( xsdNamespace ); 092 element.getDocument().getRootElement().add( xsiNamespace ); 093 094 Element valueElement = element.addElement( DsmlLiterals.REQUEST_VALUE ).addText( 095 ParserUtils.base64Encode( getRequestValue() ) ); 096 valueElement.addAttribute( new QName( DsmlLiterals.TYPE, xsiNamespace ), 097 ParserUtils.XSD_COLON + ParserUtils.BASE64BINARY ); 098 099 return element; 100 } 101 102 103 /** 104 * Get the extended request name 105 * 106 * @return Returns the request name. 107 */ 108 @Override 109 public String getRequestName() 110 { 111 return getDecorated().getRequestName(); 112 } 113 114 115 /** 116 * Set the extended request name 117 * 118 * @param requestName The request name to set. 119 */ 120 public void setRequestName( Oid requestName ) 121 { 122 getDecorated().setRequestName( requestName.toString() ); 123 } 124 125 126 /** 127 * Get the extended request value 128 * 129 * @return Returns the request value. 130 */ 131 public byte[] getRequestValue() 132 { 133 return this.requestValue; 134 } 135 136 137 /** 138 * Set the extended request value 139 * 140 * @param requestValue The request value to set. 141 */ 142 public void setRequestValue( byte[] requestValue ) 143 { 144 this.requestValue = requestValue; 145 } 146 147 148 /** 149 * {@inheritDoc} 150 */ 151 @Override 152 public MessageTypeEnum getResponseType() 153 { 154 return getDecorated().getResponseType(); 155 } 156 157 158 /** 159 * {@inheritDoc} 160 */ 161 @Override 162 public ExtendedRequest setRequestName( String oid ) 163 { 164 getDecorated().setRequestName( oid ); 165 166 return this; 167 } 168 169 170 /** 171 * {@inheritDoc} 172 */ 173 @Override 174 public ExtendedRequest setMessageId( int messageId ) 175 { 176 super.setMessageId( messageId ); 177 178 return this; 179 } 180 181 182 /** 183 * {@inheritDoc} 184 */ 185 @Override 186 public ExtendedRequest addControl( Control control ) 187 { 188 return ( ExtendedRequest ) super.addControl( control ); 189 } 190 191 192 /** 193 * {@inheritDoc} 194 */ 195 @Override 196 public ExtendedRequest addAllControls( Control[] controls ) 197 { 198 return ( ExtendedRequest ) super.addAllControls( controls ); 199 } 200 201 202 /** 203 * {@inheritDoc} 204 */ 205 @Override 206 public ExtendedRequest removeControl( Control control ) 207 { 208 return ( ExtendedRequest ) super.removeControl( control ); 209 } 210}