001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 */
016package org.opends.server.admin.std.meta;
017
018
019
020import org.forgerock.opendj.ldap.DN;
021import org.opends.server.admin.AdministratorAction;
022import org.opends.server.admin.BooleanPropertyDefinition;
023import org.opends.server.admin.ClassPropertyDefinition;
024import org.opends.server.admin.client.AuthorizationException;
025import org.opends.server.admin.client.CommunicationException;
026import org.opends.server.admin.client.ConcurrentModificationException;
027import org.opends.server.admin.client.ManagedObject;
028import org.opends.server.admin.client.MissingMandatoryPropertiesException;
029import org.opends.server.admin.client.OperationRejectedException;
030import org.opends.server.admin.ManagedObjectAlreadyExistsException;
031import org.opends.server.admin.ManagedObjectDefinition;
032import org.opends.server.admin.PropertyOption;
033import org.opends.server.admin.PropertyProvider;
034import org.opends.server.admin.server.ConfigurationChangeListener;
035import org.opends.server.admin.server.ServerManagedObject;
036import org.opends.server.admin.std.client.SynchronizationProviderCfgClient;
037import org.opends.server.admin.std.server.SynchronizationProviderCfg;
038import org.opends.server.admin.Tag;
039import org.opends.server.admin.TopCfgDefn;
040import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
041
042
043
044/**
045 * An interface for querying the Synchronization Provider managed
046 * object definition meta information.
047 * <p>
048 * Synchronization Providers are responsible for handling
049 * synchronization of the directory server data with other OpenDJ
050 * instances or other data repositories.
051 */
052public final class SynchronizationProviderCfgDefn extends ManagedObjectDefinition<SynchronizationProviderCfgClient, SynchronizationProviderCfg> {
053
054  // The singleton configuration definition instance.
055  private static final SynchronizationProviderCfgDefn INSTANCE = new SynchronizationProviderCfgDefn();
056
057
058
059  // The "enabled" property definition.
060  private static final BooleanPropertyDefinition PD_ENABLED;
061
062
063
064  // The "java-class" property definition.
065  private static final ClassPropertyDefinition PD_JAVA_CLASS;
066
067
068
069  // Build the "enabled" property definition.
070  static {
071      BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled");
072      builder.setOption(PropertyOption.MANDATORY);
073      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled"));
074      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>());
075      PD_ENABLED = builder.getInstance();
076      INSTANCE.registerPropertyDefinition(PD_ENABLED);
077  }
078
079
080
081  // Build the "java-class" property definition.
082  static {
083      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
084      builder.setOption(PropertyOption.MANDATORY);
085      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class"));
086      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
087      builder.addInstanceOf("org.opends.server.api.SynchronizationProvider");
088      PD_JAVA_CLASS = builder.getInstance();
089      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
090  }
091
092
093
094  // Register the tags associated with this managed object definition.
095  static {
096    INSTANCE.registerTag(Tag.valueOf("replication"));
097  }
098
099
100
101  /**
102   * Get the Synchronization Provider configuration definition
103   * singleton.
104   *
105   * @return Returns the Synchronization Provider configuration
106   *         definition singleton.
107   */
108  public static SynchronizationProviderCfgDefn getInstance() {
109    return INSTANCE;
110  }
111
112
113
114  /**
115   * Private constructor.
116   */
117  private SynchronizationProviderCfgDefn() {
118    super("synchronization-provider", TopCfgDefn.getInstance());
119  }
120
121
122
123  /**
124   * {@inheritDoc}
125   */
126  public SynchronizationProviderCfgClient createClientConfiguration(
127      ManagedObject<? extends SynchronizationProviderCfgClient> impl) {
128    return new SynchronizationProviderCfgClientImpl(impl);
129  }
130
131
132
133  /**
134   * {@inheritDoc}
135   */
136  public SynchronizationProviderCfg createServerConfiguration(
137      ServerManagedObject<? extends SynchronizationProviderCfg> impl) {
138    return new SynchronizationProviderCfgServerImpl(impl);
139  }
140
141
142
143  /**
144   * {@inheritDoc}
145   */
146  public Class<SynchronizationProviderCfg> getServerConfigurationClass() {
147    return SynchronizationProviderCfg.class;
148  }
149
150
151
152  /**
153   * Get the "enabled" property definition.
154   * <p>
155   * Indicates whether the Synchronization Provider is enabled for
156   * use.
157   *
158   * @return Returns the "enabled" property definition.
159   */
160  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
161    return PD_ENABLED;
162  }
163
164
165
166  /**
167   * Get the "java-class" property definition.
168   * <p>
169   * Specifies the fully-qualified name of the Java class that
170   * provides the Synchronization Provider implementation.
171   *
172   * @return Returns the "java-class" property definition.
173   */
174  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
175    return PD_JAVA_CLASS;
176  }
177
178
179
180  /**
181   * Managed object client implementation.
182   */
183  private static class SynchronizationProviderCfgClientImpl implements
184    SynchronizationProviderCfgClient {
185
186    // Private implementation.
187    private ManagedObject<? extends SynchronizationProviderCfgClient> impl;
188
189
190
191    // Private constructor.
192    private SynchronizationProviderCfgClientImpl(
193        ManagedObject<? extends SynchronizationProviderCfgClient> impl) {
194      this.impl = impl;
195    }
196
197
198
199    /**
200     * {@inheritDoc}
201     */
202    public Boolean isEnabled() {
203      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
204    }
205
206
207
208    /**
209     * {@inheritDoc}
210     */
211    public void setEnabled(boolean value) {
212      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
213    }
214
215
216
217    /**
218     * {@inheritDoc}
219     */
220    public String getJavaClass() {
221      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
222    }
223
224
225
226    /**
227     * {@inheritDoc}
228     */
229    public void setJavaClass(String value) {
230      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
231    }
232
233
234
235    /**
236     * {@inheritDoc}
237     */
238    public ManagedObjectDefinition<? extends SynchronizationProviderCfgClient, ? extends SynchronizationProviderCfg> definition() {
239      return INSTANCE;
240    }
241
242
243
244    /**
245     * {@inheritDoc}
246     */
247    public PropertyProvider properties() {
248      return impl;
249    }
250
251
252
253    /**
254     * {@inheritDoc}
255     */
256    public void commit() throws ManagedObjectAlreadyExistsException,
257        MissingMandatoryPropertiesException, ConcurrentModificationException,
258        OperationRejectedException, AuthorizationException,
259        CommunicationException {
260      impl.commit();
261    }
262
263
264
265    /** {@inheritDoc} */
266    public String toString() {
267      return impl.toString();
268    }
269  }
270
271
272
273  /**
274   * Managed object server implementation.
275   */
276  private static class SynchronizationProviderCfgServerImpl implements
277    SynchronizationProviderCfg {
278
279    // Private implementation.
280    private ServerManagedObject<? extends SynchronizationProviderCfg> impl;
281
282    // The value of the "enabled" property.
283    private final boolean pEnabled;
284
285    // The value of the "java-class" property.
286    private final String pJavaClass;
287
288
289
290    // Private constructor.
291    private SynchronizationProviderCfgServerImpl(ServerManagedObject<? extends SynchronizationProviderCfg> impl) {
292      this.impl = impl;
293      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
294      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
295    }
296
297
298
299    /**
300     * {@inheritDoc}
301     */
302    public void addChangeListener(
303        ConfigurationChangeListener<SynchronizationProviderCfg> listener) {
304      impl.registerChangeListener(listener);
305    }
306
307
308
309    /**
310     * {@inheritDoc}
311     */
312    public void removeChangeListener(
313        ConfigurationChangeListener<SynchronizationProviderCfg> listener) {
314      impl.deregisterChangeListener(listener);
315    }
316
317
318
319    /**
320     * {@inheritDoc}
321     */
322    public boolean isEnabled() {
323      return pEnabled;
324    }
325
326
327
328    /**
329     * {@inheritDoc}
330     */
331    public String getJavaClass() {
332      return pJavaClass;
333    }
334
335
336
337    /**
338     * {@inheritDoc}
339     */
340    public Class<? extends SynchronizationProviderCfg> configurationClass() {
341      return SynchronizationProviderCfg.class;
342    }
343
344
345
346    /**
347     * {@inheritDoc}
348     */
349    public DN dn() {
350      return impl.getDN();
351    }
352
353
354
355    /** {@inheritDoc} */
356    public String toString() {
357      return impl.toString();
358    }
359  }
360}