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 * docs/licenses/cddl.txt 011 * or http://www.opensource.org/licenses/cddl1.php. 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 * docs/licenses/cddl.txt. 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 2013 UnboundID Corp. 026 */ 027 package com.unboundid.directory.sdk.ds.api; 028 029 030 031 import java.util.Collections; 032 import java.util.List; 033 import java.util.Map; 034 035 import com.unboundid.directory.sdk.broker.internal.IdentityBrokerExtension; 036 import com.unboundid.directory.sdk.common.internal.ExampleUsageProvider; 037 import com.unboundid.directory.sdk.common.internal.Reconfigurable; 038 import com.unboundid.directory.sdk.common.internal.UnboundIDExtension; 039 import com.unboundid.directory.sdk.common.types.CompletedOperationContext; 040 import com.unboundid.directory.sdk.ds.config.ResultCriteriaConfig; 041 import com.unboundid.directory.sdk.ds.types.DirectoryServerContext; 042 import com.unboundid.directory.sdk.ds.internal.DirectoryServerExtension; 043 import com.unboundid.directory.sdk.metrics.internal.MetricsEngineExtension; 044 import com.unboundid.directory.sdk.proxy.internal.DirectoryProxyServerExtension; 045 import com.unboundid.directory.sdk.sync.internal.SynchronizationServerExtension; 046 import com.unboundid.ldap.sdk.LDAPException; 047 import com.unboundid.ldap.sdk.ResultCode; 048 import com.unboundid.util.Extensible; 049 import com.unboundid.util.ThreadSafety; 050 import com.unboundid.util.ThreadSafetyLevel; 051 import com.unboundid.util.args.ArgumentException; 052 import com.unboundid.util.args.ArgumentParser; 053 054 055 056 /** 057 * This class defines an API that must be implemented by extensions which can 058 * be used to classify client results. 059 * <BR> 060 * <H2>Configuring Result Criteria</H2> 061 * In order to configure a result criteria object created using this API, use a 062 * command like: 063 * <PRE> 064 * dsconfig create-result-criteria \ 065 * --provider-name "<I>{provider-name}</I>" \ 066 * --type third-party \ 067 * --set enabled:true \ 068 * --set "extension-class:<I>{class-name}</I>" \ 069 * --set "extension-argument:<I>{name=value}</I>" 070 * </PRE> 071 * where "<I>{provider-name}</I>" is the name to use for the result criteria 072 * instance, "<I>{class-name}</I>" is the fully-qualified name of the Java class 073 * that extends {@code com.unboundid.directory.sdk.ds.api.ResultCriteria}, and 074 * "<I>{name=value}</I>" represents name-value pairs for any arguments to 075 * provide to the result criteria. If multiple arguments should be provided to 076 * the result criteria instance, then the 077 * "<CODE>--set extension-argument:<I>{name=value}</I></CODE>" option should be 078 * provided multiple times. 079 */ 080 @Extensible() 081 @DirectoryServerExtension() 082 @DirectoryProxyServerExtension(appliesToLocalContent=true, 083 appliesToRemoteContent=true) 084 @SynchronizationServerExtension(appliesToLocalContent=true, 085 appliesToSynchronizedContent=false) 086 @MetricsEngineExtension() 087 @IdentityBrokerExtension() 088 @ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE) 089 public abstract class ResultCriteria 090 implements UnboundIDExtension, 091 Reconfigurable<ResultCriteriaConfig>, 092 ExampleUsageProvider 093 { 094 /** 095 * Creates a new instance of this result criteria. All result criteria 096 * implementations must include a default constructor, but any initialization 097 * should generally be done in the {@code initializeResultCriteria} method. 098 */ 099 public ResultCriteria() 100 { 101 // No implementation is required. 102 } 103 104 105 106 /** 107 * {@inheritDoc} 108 */ 109 public abstract String getExtensionName(); 110 111 112 113 /** 114 * {@inheritDoc} 115 */ 116 public abstract String[] getExtensionDescription(); 117 118 119 120 /** 121 * {@inheritDoc} 122 */ 123 public void defineConfigArguments(final ArgumentParser parser) 124 throws ArgumentException 125 { 126 // No arguments will be allowed by default. 127 } 128 129 130 131 /** 132 * Initializes this result criteria. 133 * 134 * @param serverContext A handle to the server context for the server in 135 * which this extension is running. 136 * @param config The general configuration for this result criteria. 137 * @param parser The argument parser which has been initialized from 138 * the configuration for this result criteria. 139 * 140 * @throws LDAPException If a problem occurs while initializing this result 141 * criteria. 142 */ 143 public void initializeResultCriteria( 144 final DirectoryServerContext serverContext, 145 final ResultCriteriaConfig config, 146 final ArgumentParser parser) 147 throws LDAPException 148 { 149 // No initialization will be performed by default. 150 } 151 152 153 154 /** 155 * {@inheritDoc} 156 */ 157 public boolean isConfigurationAcceptable( 158 final ResultCriteriaConfig config, 159 final ArgumentParser parser, 160 final List<String> unacceptableReasons) 161 { 162 // No extended validation will be performed by default. 163 return true; 164 } 165 166 167 168 /** 169 * {@inheritDoc} 170 */ 171 public ResultCode applyConfiguration(final ResultCriteriaConfig config, 172 final ArgumentParser parser, 173 final List<String> adminActionsRequired, 174 final List<String> messages) 175 { 176 // By default, no configuration changes will be applied. If there are any 177 // arguments, then add an admin action message indicating that the extension 178 // needs to be restarted for any changes to take effect. 179 if (! parser.getNamedArguments().isEmpty()) 180 { 181 adminActionsRequired.add( 182 "No configuration change has actually been applied. The new " + 183 "configuration will not take effect until this result " + 184 "criteria is disabled and re-enabled or until the server is " + 185 "restarted."); 186 } 187 188 return ResultCode.SUCCESS; 189 } 190 191 192 193 /** 194 * Performs any cleanup which may be necessary when this result criteria 195 * is to be taken out of service. 196 */ 197 public void finalizeResultCriteria() 198 { 199 // No implementation is required. 200 } 201 202 203 204 /** 205 * Indicates whether the provided operation matches the criteria for this 206 * result criteria object. 207 * 208 * @param o The operation for which to make the determination. 209 * 210 * @return {@code true} if the provided operation matches the criteria for 211 * this result criteria object, or {@code false} if not. 212 */ 213 public abstract boolean matches(final CompletedOperationContext o); 214 215 216 217 /** 218 * {@inheritDoc} 219 */ 220 public Map<List<String>,String> getExamplesArgumentSets() 221 { 222 return Collections.emptyMap(); 223 } 224 }