Driver.java revision a94c41b1759c23f849376a5f5448bc6e819f1c11
/*
* 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 legal-notices/CDDLv1_0.txt
* 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 legal-notices/CDDLv1_0.txt.
* 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
*
*
* Copyright 2008-2009 Sun Microsystems, Inc.
*/
/**
* An abstract management connection context driver which should form the basis
* of driver implementations.
*/
public abstract class Driver {
/**
* A default behavior visitor used for retrieving the default values of a
* property.
*
* @param <T>
* The type of the property.
*/
private final class DefaultValueFinder<T> implements DefaultBehaviorProviderVisitor<T, Collection<T>, Void> {
// Any exception that occurred whilst retrieving inherited default
// values.
// The path of the managed object containing the first property.
private final ManagedObjectPath<?, ?> firstPath;
// Indicates whether the managed object has been created yet.
private final boolean isCreate;
// The path of the managed object containing the next property.
// The next property whose default values were required.
// Private constructor.
this.firstPath = p;
}
/**
* {@inheritDoc}
*/
public Collection<T> visitAbsoluteInherited(AbsoluteInheritedDefaultBehaviorProvider<T> d, Void p) {
try {
d.getPropertyName());
} catch (PropertyException e) {
exception = e;
return Collections.emptySet();
}
}
/**
* {@inheritDoc}
*/
return Collections.emptySet();
}
/**
* {@inheritDoc}
*/
try {
} catch (PropertyException e) {
break;
}
}
return values;
}
/**
* {@inheritDoc}
*/
public Collection<T> visitRelativeInherited(RelativeInheritedDefaultBehaviorProvider<T> d, Void p) {
try {
d.getPropertyName());
} catch (PropertyException e) {
exception = e;
return Collections.emptySet();
}
}
/**
* {@inheritDoc}
*/
return Collections.emptySet();
}
this.nextPath = p;
this.nextProperty = pd;
throw exception;
}
}
return values;
}
// Get an inherited property value.
@SuppressWarnings("unchecked")
// First check that the requested type of managed object
// corresponds to the path.
if (!supr.isParentOf(d)) {
throw PropertyException.defaultBehaviorException(nextProperty, new DefinitionDecodingException(supr,
}
// Save the current property in case of recursion.
try {
// Determine the requested property definition.
try {
// FIXME: we use the definition taken from the default
// behavior here when we should really use the exact
// definition of the component being created.
} catch (IllegalArgumentException e) {
throw new PropertyNotFoundException(propertyName);
} catch (ClassCastException e) {
// FIXME: would be nice to throw a better exception here.
throw new PropertyNotFoundException(propertyName);
}
// If the path relates to the current managed object and the
// managed object is in the process of being created it won't
// exist, so we should just use the default values of the
// referenced property.
// Recursively retrieve this property's default values.
}
return values;
} else {
// FIXME: issue 2481 - this is broken if the referenced
// property
// inherits its defaults from the newly created managed
// object.
}
} catch (PropertyException e) {
// Wrap any errors due to recursion.
} catch (DefinitionDecodingException e) {
} catch (PropertyNotFoundException e) {
} catch (ErrorResultException e) {
} catch (ManagedObjectNotFoundException e) {
}
}
};
private final PropertyDefinitionsOptions propertyDefOptions;
/**
* Creates a new abstract driver.
*
* @param propertyDefOptions
* Decoding options for property definitions values.
*/
this.propertyDefOptions = propertyDefOptions;
}
/**
* Closes any context associated with this management context driver.
*/
public void close() {
// do nothing by default
}
/**
* Deletes the named instantiable child managed object from the named parent
* managed object.
*
* @param <C>
* The type of client managed object configuration that the
* relation definition refers to.
* @param <S>
* The type of server managed object configuration that the
* relation definition refers to.
* @param parent
* The path of the parent managed object.
* @param rd
* The instantiable relation definition.
* @param name
* The name of the child managed object to be removed.
* @return Returns <code>true</code> if the named instantiable child managed
* object was found, or <code>false</code> if it was not found.
* @throws IllegalArgumentException
* If the relation definition is not associated with the parent
* managed object's definition.
* @throws ManagedObjectNotFoundException
* If the parent managed object could not be found.
* @throws OperationRejectedException
* If the managed object cannot be removed due to some
* client-side or server-side constraint which cannot be
* satisfied (for example, if it is referenced by another
* managed object).
* @throws ErrorResultException
* If any other error occurs.
*/
return doDeleteManagedObject(child);
}
/**
* Deletes the optional child managed object from the named parent managed
* object.
*
* @param <C>
* The type of client managed object configuration that the
* relation definition refers to.
* @param <S>
* The type of server managed object configuration that the
* relation definition refers to.
* @param parent
* The path of the parent managed object.
* @param rd
* The optional relation definition.
* @return Returns <code>true</code> if the optional child managed object
* was found, or <code>false</code> if it was not found.
* @throws IllegalArgumentException
* If the relation definition is not associated with the parent
* managed object's definition.
* @throws ManagedObjectNotFoundException
* If the parent managed object could not be found.
* @throws OperationRejectedException
* If the managed object cannot be removed due to some
* client-side or server-side constraint which cannot be
* satisfied (for example, if it is referenced by another
* managed object).
* @throws ErrorResultException
* If any other error occurs.
*/
ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd) throws ManagedObjectNotFoundException,
return doDeleteManagedObject(child);
}
/**
* Deletes the named instantiable child managed object from the named parent
* managed object.
*
* @param <C>
* The type of client managed object configuration that the
* relation definition refers to.
* @param <S>
* The type of server managed object configuration that the
* relation definition refers to.
* @param parent
* The path of the parent managed object.
* @param rd
* The instantiable relation definition.
* @param name
* The name of the child managed object to be removed.
* @return Returns <code>true</code> if the named instantiable child managed
* object was found, or <code>false</code> if it was not found.
* @throws IllegalArgumentException
* If the relation definition is not associated with the parent
* managed object's definition.
* @throws ManagedObjectNotFoundException
* If the parent managed object could not be found.
* @throws OperationRejectedException
* If the managed object cannot be removed due to some
* client-side or server-side constraint which cannot be
* satisfied (for example, if it is referenced by another
* managed object).
* @throws ErrorResultException
* If any other error occurs.
*/
return doDeleteManagedObject(child);
}
/**
* Gets the named managed object. The path is guaranteed to be non-empty, so
* implementations do not need to worry about handling this special case.
*
* @param <C>
* The type of client managed object configuration that the path
* definition refers to.
* @param <S>
* The type of server managed object configuration that the path
* definition refers to.
* @param path
* The non-empty path of the managed object.
* @return Returns the named managed object.
* @throws DefinitionDecodingException
* If the managed object was found but its type could not be
* determined.
* @throws ManagedObjectDecodingException
* If the managed object was found but one or more of its
* properties could not be decoded.
* @throws ManagedObjectNotFoundException
* If the requested managed object could not be found on the
* server.
* @throws ErrorResultException
* If any other error occurs.
*/
// @Checkstyle:ignore
public abstract <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getManagedObject(
/**
* Gets the effective values of a property in the named managed object.
* <p>
* Implementations MUST NOT not use
* {@link #getManagedObject(ManagedObjectPath)} to read the referenced
* managed object in its entirety. Specifically, implementations MUST only
* attempt to resolve the default values for the requested property and its
* dependencies (if it uses inherited defaults). This is to avoid infinite
* recursion where a managed object contains a property which inherits
* default values from another property in the same managed object.
*
* @param <C>
* The type of client managed object configuration that the path
* definition refers to.
* @param <S>
* The type of server managed object configuration that the path
* definition refers to.
* @param <P>
* The type of the property to be retrieved.
* @param path
* The path of the managed object containing the property.
* @param pd
* The property to be retrieved.
* @return Returns the property's effective values, or an empty set if there
* are no values defined.
* @throws IllegalArgumentException
* If the property definition is not associated with the
* referenced managed object's definition.
* @throws DefinitionDecodingException
* If the managed object was found but its type could not be
* determined.
* @throws PropertyException
* If the managed object was found but the requested property
* could not be decoded.
* @throws ManagedObjectNotFoundException
* If the requested managed object could not be found on the
* server.
* @throws ErrorResultException
* If any other error occurs.
*/
public abstract <C extends ConfigurationClient, S extends Configuration, P> SortedSet<P> getPropertyValues(
/**
* Gets the root configuration managed object associated with this
* management context driver.
*
* @return Returns the root configuration managed object associated with
* this management context driver.
*/
/**
* Lists the child managed objects of the named parent managed object which
* are a sub-type of the specified managed object definition.
*
* @param <C>
* The type of client managed object configuration that the
* relation definition refers to.
* @param <S>
* The type of server managed object configuration that the
* relation definition refers to.
* @param parent
* The path of the parent managed object.
* @param rd
* The instantiable relation definition.
* @param d
* The managed object definition.
* @return Returns the names of the child managed objects which are a
* sub-type of the specified managed object definition.
* @throws IllegalArgumentException
* If the relation definition is not associated with the parent
* managed object's definition.
* @throws ManagedObjectNotFoundException
* If the parent managed object could not be found.
* @throws ErrorResultException
* If any other error occurs.
*/
public abstract <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws ManagedObjectNotFoundException,
/**
* Lists the child managed objects of the named parent managed object which
* are a sub-type of the specified managed object definition.
*
* @param <C>
* The type of client managed object configuration that the
* relation definition refers to.
* @param <S>
* The type of server managed object configuration that the
* relation definition refers to.
* @param parent
* The path of the parent managed object.
* @param rd
* The set relation definition.
* @param d
* The managed object definition.
* @return Returns the names of the child managed objects which are a
* sub-type of the specified managed object definition.
* @throws IllegalArgumentException
* If the relation definition is not associated with the parent
* managed object's definition.
* @throws ManagedObjectNotFoundException
* If the parent managed object could not be found.
* @throws ErrorResultException
* If any other error occurs.
*/
public abstract <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws ManagedObjectNotFoundException,
/**
* Determines whether or not the named managed object exists.
* <p>
* Implementations should always return <code>true</code> when the provided
* path is empty.
*
* @param path
* The path of the named managed object.
* @return Returns <code>true</code> if the named managed object exists,
* <code>false</code> otherwise.
* @throws ManagedObjectNotFoundException
* If the parent managed object could not be found.
* @throws ErrorResultException
* If any other error occurs.
*/
public abstract boolean managedObjectExists(ManagedObjectPath<?, ?> path) throws ManagedObjectNotFoundException,
/**
* Deletes the named managed object.
* <p>
* Implementations do not need check whether the named managed object
* exists, nor do they need to enforce client constraints.
*
* @param <C>
* The type of client managed object configuration that the
* relation definition refers to.
* @param <S>
* The type of server managed object configuration that the
* relation definition refers to.
* @param path
* The path of the managed object to be deleted.
* @throws OperationRejectedException
* If the managed object cannot be removed due to some
* server-side constraint which cannot be satisfied (for
* example, if it is referenced by another managed object).
* @throws ErrorResultException
* If any other error occurs.
*/
protected abstract <C extends ConfigurationClient, S extends Configuration> void deleteManagedObject(
/**
* Gets the default values for the specified property.
*
* @param <P>
* The type of the property.
* @param p
* The managed object path of the current managed object.
* @param pd
* The property definition.
* @param isCreate
* Indicates whether the managed object has been created yet.
* @return Returns the default values for the specified property.
* @throws PropertyException
* If the default values could not be retrieved or decoded
* properly.
*/
protected final <P> Collection<P> findDefaultValues(ManagedObjectPath<?, ?> p, PropertyDefinition<P> pd,
boolean isCreate) {
}
/**
* Gets the management context associated with this driver.
*
* @return Returns the management context associated with this driver.
*/
protected abstract ManagementContext getManagementContext();
/**
* Validate that a relation definition belongs to the managed object
* referenced by the provided path.
*
* @param path
* The parent managed object path.
* @param rd
* The relation definition.
* @throws IllegalArgumentException
* If the relation definition does not belong to the managed
* object definition.
*/
protected final void validateRelationDefinition(ManagedObjectPath<?, ?> path, RelationDefinition<?, ?> rd) {
+ d.getName());
}
}
// Remove a managed object, first ensuring that the parent exists,
// then ensuring that the child exists, before ensuring that any
// constraints are satisfied.
// First make sure that the parent exists.
throw new ManagedObjectNotFoundException();
}
// Make sure that the targeted managed object exists.
if (!managedObjectExists(path)) {
return false;
}
// The targeted managed object is guaranteed to exist, so enforce
// any constraints.
boolean isAcceptable = true;
isAcceptable = false;
}
}
if (!isAcceptable) {
break;
}
}
if (!isAcceptable) {
}
return true;
}
}