BackendTypeHelper.java revision 8196da2152209c8c628611aeeb4adae32079921e
/*
* 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 2015 ForgeRock AS
*/
/**
* Helper class for setup applications. It helps applications to provide a
* backend type choice to the user.
*/
public class BackendTypeHelper
{
/**
* Filter the provided backend name by removing the backend suffix.
*
* @param dsCfgBackendName
* The backend name
* @return The backend name with the '-backend' suffix filtered out
*/
{
final Matcher regExpMatcher = Pattern.compile(cfgNameRegExp, Pattern.CASE_INSENSITIVE).matcher(dsCfgBackendName);
if (regExpMatcher.matches())
{
}
return dsCfgBackendName;
}
/** Adaptor to allow backend type selection in UIs. */
public static class BackendTypeUIAdapter
{
/**
* Create a new {@code BackendTypeUIAdapter}.
*
* @param backend
* The backend to adapt
*/
private BackendTypeUIAdapter(ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backend)
{
}
/**
* Return a user friendly readable name for this backend.
*
* @return A user friendly readable name for this backend.
*/
{
}
{
return obj instanceof BackendTypeUIAdapter && ((BackendTypeUIAdapter) obj).toString().equals(toString());
}
public int hashCode()
{
}
/**
* Return the adapted backend object.
*
* @return The adapted backend object
*/
{
return backend;
}
/**
* Return the old configuration framework backend object.
*
* @return The old configuration framework backend object
*/
@SuppressWarnings("unchecked")
{
{
{
}
}
throw new IllegalArgumentException("Impossible to find the equivalent backend type in old config framework: "
+ getBackend().getName());
}
}
private final List<ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg>> backends;
/** Creates a new backend type helper. */
@SuppressWarnings("unchecked")
public BackendTypeHelper()
{
backends = new LinkedList<>();
for (AbstractManagedObjectDefinition<?, ?> backendType : PluggableBackendCfgDefn.getInstance().getAllChildren())
{
// Filtering out only the non-abstract backends to avoid users attempt to create abstract ones
if (backendType instanceof ManagedObjectDefinition)
{
final Iterator<String> defaultBackendClassNameIterator = defaultBehaviorProvider.getDefaultValues().iterator();
{
return;
}
}
}
}
{
try
{
}
catch (ClassNotFoundException ignored)
{
// The backend is not supported in the running version.
}
}
ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> retrieveBackendTypeFromName(
final String backendTypeStr)
{
for (ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType : getBackendTypes())
{
{
return backendType;
}
}
return null;
}
{
return backends;
}
{
for (ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backend : getBackendTypes())
{
}
if (backendTypeNames.isEmpty())
{
return "Impossible to retrieve supported backend type list";
}
}
/**
* Return a list which contains all available backend type adapted for UI.
*
* @return a list which contains all available backend type adapted for UI
*/
public BackendTypeUIAdapter[] getBackendTypeUIAdaptors()
{
for (ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backend : getBackendTypes())
{
}
}
/**
* Return a BackendTypeUIAdapter which adapts the backend identified by the
* provided backend name.
*
* @param backendName
* the backend name which identifies the backend to adapt.
* @return a BackendTypeUIAdapter which adapts the backend identified by the
* provided backend name.
*/
{
}
/**
* Return a BackendTypeUIAdapter which adapts the provided backend.
*
* @param backend
* the backend type to adapt.
* @return a BackendTypeUIAdapter which adapts the provided backend.
*/
public static BackendTypeUIAdapter getBackendTypeAdapter(
{
return new BackendTypeUIAdapter(backend);
}
}