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 */ 020 package org.apache.directory.shared.dsmlv2.request; 021 022 023 import org.apache.directory.shared.asn1.primitives.OID; 024 import org.apache.directory.shared.dsmlv2.ParserUtils; 025 import org.apache.directory.shared.ldap.codec.MessageTypeEnum; 026 import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec; 027 import org.dom4j.Element; 028 import org.dom4j.Namespace; 029 import org.dom4j.QName; 030 031 032 /** 033 * DSML Decorator for ExtendedRequest 034 * 035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 036 * @version $Rev$, $Date$ 037 */ 038 public class ExtendedRequestDsml extends AbstractRequestDsml 039 { 040 /** 041 * Creates a new instance of ExtendedRequestDsml. 042 */ 043 public ExtendedRequestDsml() 044 { 045 super( new ExtendedRequestCodec() ); 046 } 047 048 049 /** 050 * Creates a new instance of ExtendedRequestDsml. 051 * 052 * @param ldapMessage 053 * the message to decorate 054 */ 055 public ExtendedRequestDsml( ExtendedRequestCodec ldapMessage ) 056 { 057 super( ldapMessage ); 058 } 059 060 061 /** 062 * {@inheritDoc} 063 */ 064 public MessageTypeEnum getMessageType() 065 { 066 return instance.getMessageType(); 067 } 068 069 070 /** 071 * {@inheritDoc} 072 */ 073 public Element toDsml( Element root ) 074 { 075 Element element = super.toDsml( root ); 076 077 ExtendedRequestCodec request = ( ExtendedRequestCodec ) instance; 078 079 // Request Name 080 if ( request.getRequestName() != null ) 081 { 082 element.addElement( "requestName" ).setText( request.getRequestName() ); 083 } 084 085 // Request Value 086 Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI ); 087 Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI ); 088 element.getDocument().getRootElement().add( xsdNamespace ); 089 element.getDocument().getRootElement().add( xsiNamespace ); 090 091 Element valueElement = element.addElement( "requestValue" ).addText( 092 ParserUtils.base64Encode( request.getRequestValue() ) ); 093 valueElement.addAttribute( new QName( "type", xsiNamespace ), "xsd:" + ParserUtils.BASE64BINARY ); 094 095 return element; 096 } 097 098 099 /** 100 * Get the extended request name 101 * 102 * @return Returns the request name. 103 */ 104 public String getRequestName() 105 { 106 return ( ( ExtendedRequestCodec ) instance ).getRequestName(); 107 } 108 109 110 /** 111 * Set the extended request name 112 * 113 * @param requestName The request name to set. 114 */ 115 public void setRequestName( OID requestName ) 116 { 117 ( ( ExtendedRequestCodec ) instance ).setRequestName( requestName ); 118 } 119 120 121 /** 122 * Get the extended request value 123 * 124 * @return Returns the request value. 125 */ 126 public byte[] getRequestValue() 127 { 128 return ( ( ExtendedRequestCodec ) instance ).getRequestValue(); 129 } 130 131 132 /** 133 * Set the extended request value 134 * 135 * @param requestValue The request value to set. 136 */ 137 public void setRequestValue( byte[] requestValue ) 138 { 139 ( ( ExtendedRequestCodec ) instance ).getRequestValue(); 140 } 141 }