/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at * trunk/opends/resource/legal-notices/OpenDS.LICENSE * or https://OpenDS.dev.java.net/OpenDS.LICENSE. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, * add the following below this CDDL HEADER, with the fields enclosed * by brackets "[]" replaced with your own identifying information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Portions Copyright 2007 Sun Microsystems, Inc. */ package org.opends.server.admin.client; import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.SortedSet; import org.opends.server.admin.ConfigurationClient; import org.opends.server.admin.IllegalPropertyValueException; import org.opends.server.admin.InheritedDefaultValueProvider; import org.opends.server.admin.InstantiableRelationDefinition; import org.opends.server.admin.ManagedObjectDefinition; import org.opends.server.admin.ManagedObjectPath; import org.opends.server.admin.OperationsException; import org.opends.server.admin.OptionalRelationDefinition; import org.opends.server.admin.PropertyDefinition; import org.opends.server.admin.PropertyException; import org.opends.server.admin.PropertyIsMandatoryException; import org.opends.server.admin.PropertyIsReadOnlyException; import org.opends.server.admin.PropertyIsSingleValuedException; import org.opends.server.admin.PropertyNotFoundException; import org.opends.server.admin.PropertyProvider; import org.opends.server.admin.SingletonRelationDefinition; /** * A managed object which is not bound to any underlying management * context. *

* The purpose of this managed object implementation is to facilitate * the construction of new configuration objects. Once all appropriate * properties are set, the initial managed object can be used as a * property provider during an invocation of * ManagedObject#createChild. *

* Any attempt to commit, retrieve, list, remove, or add new child * managed objects will result in an * {@link UnsupportedOperationException}. * * @param * The type of client configuration represented by the client * managed object. */ public final class InitialManagedObject implements ManagedObject { /** * Internal inherited default value provider implementation. *

* FIXME: very dumb implementation which always throws a * PropertyNotFoundException. */ private static class MyInheritedDefaultValueProvider implements InheritedDefaultValueProvider { // Private constructor. private MyInheritedDefaultValueProvider() { // No implementation required. } /** * {@inheritDoc} */ public Collection getDefaultPropertyValues( ManagedObjectPath path, String propertyName) throws OperationsException, PropertyNotFoundException { throw new PropertyNotFoundException(propertyName); } /** * {@inheritDoc} */ public ManagedObjectPath getManagedObjectPath() { return ManagedObjectPath.emptyPath(); } } // The managed object definition associated with this managed // object. private final ManagedObjectDefinition definition; // The managed object's properties. private final PropertySet properties; /** * Creates a new initial managed object associated with the * specified definition. * * @param definition * The managed object definition. */ public InitialManagedObject(ManagedObjectDefinition definition) { this.definition = definition; // FIXME: how will we cope with inherited default values? List exceptions = new LinkedList(); this.properties = PropertySet.create(definition, PropertyProvider.DEFAULT_PROVIDER, new MyInheritedDefaultValueProvider(), exceptions); } /** * {@inheritDoc} *

* This implementation throws an * {@link UnsupportedOperationException}. */ public void commit() throws OperationsException { throw new UnsupportedOperationException(); } /** * {@inheritDoc} *

* This implementation throws an * {@link UnsupportedOperationException}. */ public ManagedObject createChild( InstantiableRelationDefinition r, ManagedObjectDefinition d, String name, PropertyProvider p) throws IllegalArgumentException, OperationsException { throw new UnsupportedOperationException(); } /** * {@inheritDoc} *

* This implementation throws an * {@link UnsupportedOperationException}. */ public ManagedObject createChild( OptionalRelationDefinition r, ManagedObjectDefinition d, PropertyProvider p) throws IllegalArgumentException, OperationsException { throw new UnsupportedOperationException(); } /** * {@inheritDoc} *

* This implementation throws an * {@link UnsupportedOperationException}. */ public ManagedObject getChild( InstantiableRelationDefinition d, String name) throws IllegalArgumentException, OperationsException { throw new UnsupportedOperationException(); } /** * {@inheritDoc} *

* This implementation throws an * {@link UnsupportedOperationException}. */ public ManagedObject getChild( OptionalRelationDefinition d) throws IllegalArgumentException, OperationsException { throw new UnsupportedOperationException(); } /** * {@inheritDoc} *

* This implementation throws an * {@link UnsupportedOperationException}. */ public ManagedObject getChild( SingletonRelationDefinition d) throws IllegalArgumentException, OperationsException { throw new UnsupportedOperationException(); } /** * {@inheritDoc} */ public C getConfiguration() { return definition.createClientConfiguration(this); } /** * {@inheritDoc} */ public ManagedObjectDefinition getManagedObjectDefinition() { return definition; } /** * {@inheritDoc} *

* This implementation throws an * {@link UnsupportedOperationException}. */ public ManagedObjectPath getManagedObjectPath() { throw new UnsupportedOperationException(); } /** * {@inheritDoc} */ public T getPropertyValue(PropertyDefinition d) throws IllegalArgumentException { return properties.getPropertyValue(d); } /** * {@inheritDoc} */ public SortedSet getPropertyValues(PropertyDefinition d) throws IllegalArgumentException { return properties.getPropertyValues(d); } /** * {@inheritDoc} *

* This implementation throws an * {@link UnsupportedOperationException}. */ public boolean hasChild(OptionalRelationDefinition d) throws IllegalArgumentException, OperationsException { throw new UnsupportedOperationException(); } /** * {@inheritDoc} *

* This implementation throws an * {@link UnsupportedOperationException}. */ public String[] listChildren(InstantiableRelationDefinition d) throws IllegalArgumentException, OperationsException { throw new UnsupportedOperationException(); } /** * {@inheritDoc} *

* This implementation throws an * {@link UnsupportedOperationException}. */ public void removeChild( InstantiableRelationDefinition d, String name) throws IllegalArgumentException, OperationsException { throw new UnsupportedOperationException(); } /** * {@inheritDoc} *

* This implementation throws an * {@link UnsupportedOperationException}. */ public void removeChild( OptionalRelationDefinition d) throws IllegalArgumentException, OperationsException { throw new UnsupportedOperationException(); } /** * {@inheritDoc} */ public void setPropertyValue(PropertyDefinition d, T value) throws IllegalPropertyValueException, PropertyIsReadOnlyException, PropertyIsMandatoryException, IllegalArgumentException { properties.setPropertyValue(d, value); } /** * {@inheritDoc} */ public void setPropertyValues(PropertyDefinition d, Collection values) throws IllegalPropertyValueException, PropertyIsSingleValuedException, PropertyIsReadOnlyException, PropertyIsMandatoryException, IllegalArgumentException { properties.setPropertyValues(d, values); } }