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