ConfigFromFile.java revision 987a50dfe113ed235d28716ff080b59e8873655c
/*
* 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
* 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.
*/
/**
* This class is used to retrieve configuration information directly from the
* config.ldif file.
*
*/
public class ConfigFromFile
{
private final ObjectClass connectionHandlerOc =
private final ObjectClass ldapConnectionHandlerOc =
private final ObjectClass jmxConnectionHandlerOc =
private final ObjectClass ldifConnectionHandlerOc =
private final ObjectClass backendOc =
private final ObjectClass administrativeUserOc =
private final ObjectClass syncProviderOc =
private final ObjectClass replicationConfigOc =
private DN replicationDomainDN;
new HashSet<ListenerDescriptor>();
new HashSet<ListenerDescriptor>();
new HashSet<DatabaseDescriptor>();
private Message errorMessage;
private boolean replicationConfigured = false;
/**
* Default constructor.
*
*/
public ConfigFromFile()
{
}
/**
* Reads the configuration from the config.ldif file. When calling this
* method the thread is blocked until all the configuration is read.
*
*/
public void readConfiguration()
{
errorMessage = null;
replicationConfigured = false;
try
{
LDIFImportConfig c = new LDIFImportConfig(
reader = new LDIFReader(c);
{
}
}
catch (IOException ioe)
{
}
catch (LDIFException le)
{
}
catch (Throwable t)
{
// Bug
t.printStackTrace();
ERR_READING_CONFIG_FILE.get(), t);
}
finally
{
{
try
{
}
catch (Throwable t)
{
}
}
}
}
/**
* Returns the Administrative User DNs found in the config.ldif.
* @return the Administrative User DNs found in the config.ldif.
*/
{
return copy;
}
/**
* Returns the database descriptors found in the config.ldif.
* @return the database descriptors found in the config.ldif.
*/
{
return copy;
}
/**
* Returns the listener descriptors found in the config.ldif.
* @return the listeners descriptors found in the config.ldif.
*/
{
return copy;
}
/**
* Returns the error message that we got when retrieving the information
* from the config.ldif file.
* @return the error message that we got when retrieving the information
* from the config.ldif file.
*/
public Message getErrorMessage()
{
return errorMessage;
}
/**
* Returns the ldap URL that we can use to connect to the server based in
* what we found in the config.ldif file.
* @return the ldap URL that we can use to connect to the server based in
* what we found in the config.ldif file.
*/
public String getLDAPURL()
{
return getLDAPURL(false);
}
/**
* Returns the ldaps URL that we can use to connect to the server based in
* what we found in the config.ldif file.
* @return the ldaps URL that we can use to connect to the server based in
* what we found in the config.ldif file.
*/
public String getLDAPSURL()
{
return getLDAPURL(true);
}
/**
* Returns the ldap URL that we can use to connect to the server using Start
* TLS based in what we found in the config.ldif file.
* @return the ldap URL that we can use to connect to the server using Start
* TLS based in what we found in the config.ldif file.
*/
public String getStartTLSURL()
{
{
{
int port = -1;
try
{
if (index != -1)
{
}
else
{
}
}
{
// Could not get the port
}
if (port != -1)
{
break;
}
}
}
return url;
}
/**
* Retuns the LDAP URL for the specified connection policy.
* @param policy the connection policy to be used.
* @return the LDAP URL for the specified connection policy.
* @throws ConfigException if a valid LDAP URL could not be found.
*/
{
switch (policy)
{
case USE_STARTTLS:
if (startTlsUrl != null)
{
url = startTlsUrl;
}
else
{
}
break;
case USE_LDAPS:
{
}
else
{
}
break;
case USE_LDAP:
{
}
else
{
}
break;
{
}
else if (startTlsUrl != null)
{
url = startTlsUrl;
}
{
}
else
{
}
break;
{
}
{
}
else
{
}
break;
default:
throw new IllegalStateException("Unknown connection policy: "+
policy);
}
return url;
}
{
{
{
int port = -1;
try
{
if (index != -1)
{
}
else
{
}
}
{
// Could not get the port
}
if (port != -1)
{
if (!secure &&
{
break;
}
if (secure &&
{
break;
}
}
}
}
return url;
}
/**
* An convenience method to know if the provided ID corresponds to a
* configuration backend or not.
* @param id the backend ID to analyze
* @return <CODE>true</CODE> if the the id corresponds to a configuration
* backend and <CODE>false</CODE> otherwise.
*/
{
}
/**
* Updates the configuration data we expose to the user with the provided
* entry object.
* @param entry the entry to analyze.
*/
{
{
}
{
}
{
}
{
}
{
}
}
/**
* Updates the listener configuration data we expose to the user with the
* provided entry object.
* @param entry the entry to analyze.
*/
{
{
if (isSecure)
{
}
else
{
}
if (enabled)
{
}
else
{
}
}
{
if (isSecure)
{
}
else
{
}
if (enabled)
{
}
else
{
}
}
{
if (enabled)
{
}
else
{
}
}
else
{
/* Try to figure a name from the cn */
{
if (index > 0)
{
}
else
{
}
}
else
{
}
}
{
if (allowStartTLS != null)
{
{
}
}
}
}
/**
* Updates the database configuration data we expose to the user with the
* provided entry object.
* @param entry the entry to analyze.
*/
{
if (!isConfigBackend(id))
{
{
}
}
}
/**
* Updates the administrative user configuration data we expose to the user
* with the provided entry object.
* @param entry the entry to analyze.
*/
{
}
/**
* Updates the replication configuration data we expose to the user with
* the provided entry object.
* @param entry the entry to analyze.
*/
{
"ds-cfg-enabled")))
{
replicationConfigured = true;
}
else
{
replicationConfigured = false;
}
}
/**
* Updates the databases suffixes with the list of replicated suffixes
* found.
*/
private void updateReplication()
{
{
{
{
{
{
break;
}
}
{
break;
}
}
{
}
}
}
/**
* Updates the replication configuration data we expose to the user with
* the provided entry object.
* @param entry the entry to analyze.
*/
{
if (replicationDomainDN == null)
{
try
{
"cn=domains,cn=Multimaster Synchronization,"+
"cn=Synchronization Providers,cn=config");
}
catch (Throwable t)
{
// Bug
throw new IllegalStateException("Bug: "+t, t);
}
}
{
}
}
/*
* The following 2 methods are convenience methods to retrieve String values
* from an entry.
*/
{
{
{
for (AttributeValue v : vs)
{
}
}
}
return values;
}
{
{
}
return v;
}
/**
* Create a non replicated base DN descriptor.
*/
{
}
}