BackendTypeHelper.java revision 58821a211f38cf48a75a9cbc36b472d95b035ce2
/*
* 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 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")
{
if (isLocalDBBackend())
{
}
{
{
}
}
throw new IllegalArgumentException("Impossible to find the equivalent backend type in old config framework: "
+ getBackend().getName());
}
private boolean isLocalDBBackend()
{
}
}
/** Creates a new backend type helper. */
public BackendTypeHelper()
{
}
@SuppressWarnings("unchecked")
private void createAvailableBackendsList()
{
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)
{
backends.add((ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg>) backendType);
}
}
}
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())
{
}
}
}