1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.dsmlv2; 21 22 23 import org.apache.directory.api.ldap.codec.api.LdapApiService; 24 import org.apache.directory.api.ldap.model.message.Control; 25 import org.dom4j.Element; 26 27 28 /** 29 * A DSML decorator for a {@link Control}. 30 * 31 * @param <C> The decorated Control 32 * 33 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 34 */ 35 public class DsmlControl<C extends Control> implements Control, DsmlDecorator<C> 36 { 37 /** The decorated Control */ 38 private C decorated; 39 40 /** The encoded value of the control. */ 41 protected byte[] value; 42 43 /** The codec service responsible for encoding decoding this object */ 44 private LdapApiService codec; 45 46 47 /** 48 * Creates a new instance of DsmlControl 49 * @param codec The Codec used to encode/decode the Control 50 * @param decorated The decorated control 51 */ 52 public DsmlControl( LdapApiService codec, C decorated ) 53 { 54 this.codec = codec; 55 this.decorated = decorated; 56 } 57 58 59 /** 60 * @return The LDAP codec service. 61 */ 62 public LdapApiService getCodecService() 63 { 64 return codec; 65 } 66 67 68 /** 69 * Checks to see if this DSML control decorator has a value. 70 * 71 * @return true if the DSML control has a value, false otherwise. 72 */ 73 public boolean hasValue() 74 { 75 return value != null; 76 } 77 78 79 /** 80 * Gets the control value 81 * 82 * @return The control value 83 */ 84 public byte[] getValue() 85 { 86 return value; 87 } 88 89 90 /** 91 * Sets the encoded control value 92 * 93 * @param value The encoded control value to store 94 */ 95 public void setValue( byte[] value ) 96 { 97 if ( value != null ) 98 { 99 byte[] copy = new byte[value.length]; 100 System.arraycopy( value, 0, copy, 0, value.length ); 101 this.value = copy; 102 } 103 else 104 { 105 this.value = null; 106 } 107 } 108 109 110 /** 111 * {@inheritDoc} 112 */ 113 public String getOid() 114 { 115 return decorated.getOid(); 116 } 117 118 119 /** 120 * {@inheritDoc} 121 */ 122 public boolean isCritical() 123 { 124 return decorated.isCritical(); 125 } 126 127 128 /** 129 * {@inheritDoc} 130 */ 131 public void setCritical( boolean isCritical ) 132 { 133 decorated.setCritical( isCritical ); 134 } 135 136 137 /** 138 * {@inheritDoc} 139 */ 140 public Element toDsml( Element root ) 141 { 142 return null; 143 } 144 145 146 /** 147 * {@inheritDoc} 148 */ 149 public C getDecorated() 150 { 151 return decorated; 152 } 153 }