001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2006-2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.extensions; 028 029 030 031 import java.util.LinkedHashSet; 032 import java.util.List; 033 034 import org.opends.messages.Message; 035 import org.opends.server.admin.std.server.SubschemaSubentryVirtualAttributeCfg; 036 import org.opends.server.api.VirtualAttributeProvider; 037 import org.opends.server.config.ConfigException; 038 import org.opends.server.core.DirectoryServer; 039 import org.opends.server.core.SearchOperation; 040 import org.opends.server.loggers.debug.DebugTracer; 041 import org.opends.server.types.AttributeValue; 042 import org.opends.server.types.ByteString; 043 import org.opends.server.types.ConditionResult; 044 import org.opends.server.types.Entry; 045 import org.opends.server.types.InitializationException; 046 import org.opends.server.types.ResultCode; 047 import org.opends.server.types.VirtualAttributeRule; 048 049 import static org.opends.server.loggers.debug.DebugLogger.*; 050 import static org.opends.messages.ExtensionMessages.*; 051 import static org.opends.server.util.ServerConstants.*; 052 053 054 055 /** 056 * This class implements a virtual attribute provider that is meant to serve the 057 * subschemaSubentry operational attribute as described in RFC 4512. 058 */ 059 public class SubschemaSubentryVirtualAttributeProvider 060 extends VirtualAttributeProvider<SubschemaSubentryVirtualAttributeCfg> 061 { 062 /** 063 * The tracer object for the debug logger. 064 */ 065 private static final DebugTracer TRACER = getTracer(); 066 067 068 069 /** 070 * Creates a new instance of this subschemaSubentry virtual attribute 071 * provider. 072 */ 073 public SubschemaSubentryVirtualAttributeProvider() 074 { 075 super(); 076 077 // All initialization should be performed in the 078 // initializeVirtualAttributeProvider method. 079 } 080 081 082 083 /** 084 * {@inheritDoc} 085 */ 086 @Override() 087 public void initializeVirtualAttributeProvider( 088 SubschemaSubentryVirtualAttributeCfg configuration) 089 throws ConfigException, InitializationException 090 { 091 // No initialization is required. 092 } 093 094 095 096 /** 097 * {@inheritDoc} 098 */ 099 @Override() 100 public boolean isMultiValued() 101 { 102 return false; 103 } 104 105 106 107 /** 108 * {@inheritDoc} 109 */ 110 @Override() 111 public LinkedHashSet<AttributeValue> getValues(Entry entry, 112 VirtualAttributeRule rule) 113 { 114 LinkedHashSet<AttributeValue> values = new LinkedHashSet<AttributeValue>(1); 115 116 values.add(new AttributeValue(rule.getAttributeType(), 117 DirectoryServer.getSchemaDN().toString())); 118 119 return values; 120 } 121 122 123 124 /** 125 * {@inheritDoc} 126 */ 127 @Override() 128 public ConditionResult matchesSubstring(Entry entry, 129 VirtualAttributeRule rule, 130 ByteString subInitial, 131 List<ByteString> subAny, 132 ByteString subFinal) 133 { 134 // DNs cannot be used in substring matching. 135 return ConditionResult.UNDEFINED; 136 } 137 138 139 140 /** 141 * {@inheritDoc} 142 */ 143 @Override() 144 public ConditionResult greaterThanOrEqualTo(Entry entry, 145 VirtualAttributeRule rule, 146 AttributeValue value) 147 { 148 // DNs cannot be used in ordering matching. 149 return ConditionResult.UNDEFINED; 150 } 151 152 153 154 /** 155 * {@inheritDoc} 156 */ 157 @Override() 158 public ConditionResult lessThanOrEqualTo(Entry entry, 159 VirtualAttributeRule rule, 160 AttributeValue value) 161 { 162 // DNs cannot be used in ordering matching. 163 return ConditionResult.UNDEFINED; 164 } 165 166 167 168 /** 169 * {@inheritDoc} 170 */ 171 @Override() 172 public ConditionResult approximatelyEqualTo(Entry entry, 173 VirtualAttributeRule rule, 174 AttributeValue value) 175 { 176 // DNs cannot be used in approximate matching. 177 return ConditionResult.UNDEFINED; 178 } 179 180 181 182 /** 183 * {@inheritDoc}. This virtual attribute will support search operations only 184 * if one of the following is true about the search filter: 185 * <UL> 186 * <LI>It is an equality filter targeting the associated attribute 187 * type.</LI> 188 * <LI>It is an AND filter in which at least one of the components is an 189 * equality filter targeting the associated attribute type.</LI> 190 * <LI>It is an OR filter in which all of the components are equality 191 * filters targeting the associated attribute type.</LI> 192 * </UL> 193 */ 194 @Override() 195 public boolean isSearchable(VirtualAttributeRule rule, 196 SearchOperation searchOperation) 197 { 198 // This attribute is not searchable, since it will have the same value in 199 // tons of entries. 200 return false; 201 } 202 203 204 205 /** 206 * {@inheritDoc} 207 */ 208 @Override() 209 public void processSearch(VirtualAttributeRule rule, 210 SearchOperation searchOperation) 211 { 212 searchOperation.setResultCode(ResultCode.UNWILLING_TO_PERFORM); 213 214 Message message = ERR_SUBSCHEMASUBENTRY_VATTR_NOT_SEARCHABLE.get( 215 rule.getAttributeType().getNameOrOID()); 216 searchOperation.appendErrorMessage(message); 217 } 218 } 219