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; 021 022 023import org.apache.directory.shared.ldap.codec.api.LdapApiService; 024import org.apache.directory.shared.ldap.model.message.Control; 025import org.dom4j.Element; 026 027 028/** 029 * A DSML decorator for a {@link Control}. 030 * 031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 032 */ 033public class DsmlControl<E extends Control> 034 implements Control, DsmlDecorator<E> 035{ 036 /** The decorated Control */ 037 private E decorated; 038 039 /** The encoded value of the control. */ 040 protected byte[] value; 041 042 /** The codec service responsible for encoding decoding this object */ 043 private LdapApiService codec; 044 045 046 public DsmlControl( LdapApiService codec, E decorated ) 047 { 048 this.codec = codec; 049 this.decorated = decorated; 050 } 051 052 053 /** 054 * Gets the LDAP codec service. 055 */ 056 public LdapApiService getCodecService() 057 { 058 return codec; 059 } 060 061 062 /** 063 * Checks to see if this DSML control decorator has a value. 064 * 065 * @return true if the DSML control has a value, false otherwise. 066 */ 067 public boolean hasValue() 068 { 069 return value != null; 070 } 071 072 073 /** 074 * Get the control value 075 * 076 * @return The control value 077 */ 078 public byte[] getValue() 079 { 080 return value; 081 } 082 083 084 /** 085 * Set the encoded control value 086 * 087 * @param value The encoded control value to store 088 */ 089 public void setValue( byte[] value ) 090 { 091 if ( value != null ) 092 { 093 byte[] copy = new byte[ value.length ]; 094 System.arraycopy( value, 0, copy, 0, value.length ); 095 this.value = copy; 096 } 097 else 098 { 099 this.value = null; 100 } 101 } 102 103 104 /** 105 * {@inheritDoc} 106 */ 107 public String getOid() 108 { 109 return decorated.getOid(); 110 } 111 112 113 /** 114 * {@inheritDoc} 115 */ 116 public boolean isCritical() 117 { 118 return decorated.isCritical(); 119 } 120 121 122 /** 123 * {@inheritDoc} 124 */ 125 public void setCritical( boolean isCritical ) 126 { 127 decorated.setCritical( isCritical ); 128 } 129 130 131 /** 132 * {@inheritDoc} 133 */ 134 public Element toDsml( Element root ) 135 { 136 return null; 137 } 138 139 140 /** 141 * {@inheritDoc} 142 */ 143 public E getDecorated() 144 { 145 return decorated; 146 } 147}