/*
* 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 Sun Microsystems, Inc.
* Portions Copyright 2013-2015 ForgeRock AS.
*/
/**
* Class property definition.
* <p>
* A class property definition defines a property whose values
* represent a Java class. It is possible to restrict the type of java
* class by specifying "instance of" constraints.
* <p>
* not capable of validating the Java class (e.g. it will not be able
* to load it nor have access to the interfaces it is supposed to
* implement). For this reason, it is possible to switch off
* validation in the client by calling the static method
* {@link #setAllowClassValidation(boolean)}.
*/
/**
* An interface for incrementally constructing class property
* definitions.
*/
public static class Builder extends
/** List of interfaces which property values must implement. */
/** Private constructor. */
super(d, propertyName);
}
/**
* Add an class name which property values must implement.
*
* @param className
* The name of a class which property values must
* implement.
*/
/*
* Do some basic checks to make sure the string representation is valid.
*/
+ "\" is not a valid Java class name");
}
/*
* If possible try and load the class in order to perform additional
* validation.
*/
if (isAllowClassValidation()) {
/*
* Check that the class can be loaded so that validation can be
* performed.
*/
try {
} catch (ClassNotFoundException e) {
// TODO: can we do something better here?
throw new RuntimeException(e);
}
}
}
/** {@inheritDoc} */
AbstractManagedObjectDefinition<?, ?> d,
}
}
/** Regular expression for validating class names. */
"^([A-Za-z][A-Za-z0-9_]*\\.)*[A-Za-z][A-Za-z0-9_]*(\\$[A-Za-z0-9_]+)*$";
/**
* Flag indicating whether class property values should be validated.
*/
private static boolean allowClassValidation = true;
/**
* Create a class property definition builder.
*
* @param d
* The managed object definition associated with this
* property definition.
* @param propertyName
* The property name.
* @return Returns the new class property definition builder.
*/
return new Builder(d, propertyName);
}
/**
* Determine whether or not class property definitions should
* validate class name property values. Validation involves checking
* that the class exists and that it implements the required
* interfaces.
*
* @return Returns <code>true</code> if class property definitions
* should validate class name property values.
*/
public static boolean isAllowClassValidation() {
return allowClassValidation;
}
/**
* Specify whether or not class property definitions should validate
* class name property values. Validation involves checking that the
* class exists and that it implements the required interfaces.
* <p>
* By default validation is switched on.
*
* @param value
* <code>true</code> if class property definitions should
* validate class name property values.
*/
}
/** Load a named class. */
throws ClassNotFoundException, LinkageError {
.getInstance().getClassLoader());
}
/** List of interfaces which property values must implement. */
/** Private constructor. */
private ClassPropertyDefinition(
this.instanceOfInterfaces = Collections
}
/** {@inheritDoc} */
return v.visitClass(this, p);
}
/** {@inheritDoc} */
return v.visitClass(this, value, p);
}
/** {@inheritDoc} */
throws PropertyException {
try {
} catch (PropertyException e) {
}
return value;
}
/**
* Get an unmodifiable list of classes which values of this property
* must implement.
*
* @return Returns an unmodifiable list of classes which values of
* this property must implement.
*/
return instanceOfInterfaces;
}
/**
* Validate and load the named class, and cast it to a subclass of
* the specified class.
*
* @param <T>
* The requested type.
* @param className
* The name of the class to validate and load.
* @param instanceOf
* The class representing the requested type.
* @return Returns the named class cast to a subclass of the
* specified class.
* @throws PropertyException
* If the named class was invalid, could not be loaded, or
* did not implement the required interfaces.
* @throws ClassCastException
* If the referenced class does not implement the
* requested type.
*/
// Make sure that the named class is valid.
// Cast it to the required type.
}
/** {@inheritDoc} */
throws PropertyException {
}
/** {@inheritDoc} */
throws PropertyException {
// Always make sure the name is a valid class name.
/*
* If additional validation is enabled then attempt to load the class and
* check the interfaces that it implements/extends.
*/
if (allowClassValidation) {
validateClassInterfaces(value, false);
}
}
/**
* Make sure that named class implements the interfaces named by this
* definition.
*/
throws PropertyException {
for (String i : instanceOfInterfaces) {
}
}
return theClass;
}
try {
} catch (ClassNotFoundException | LinkageError e) {
// If the class cannot be loaded then it is an invalid value.
throw illegalPropertyValueException(this, componentClassName, e);
}
}
/**
* Do some basic checks to make sure the string representation is valid.
*/
throws PropertyException {
}
}
}