Branch.java revision 3c1fa5e3bbf2c06153a060f0490c5f10668f42e3
/*
* 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 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* This class defines a branch that should be included in the resulting LDIF. A
* branch may or may not have subordinate entries.
*/
public class Branch
{
// The DN for this branch entry.
// The number of entries that should be created below this branch for each
// subordinate template.
private int[] numEntriesPerTemplate;
// The names of the subordinate templates for this branch.
private String[] subordinateTemplateNames;
// The set of subordinate templates for this branch.
private Template[] subordinateTemplates;
// The set of template lines that correspond to the RDN components.
private TemplateLine[] rdnLines;
// The set of extra lines that should be included in this branch entry.
private TemplateLine[] extraLines;
/**
* Creates a new branch with the provided information.
*
* @param templateFile The template file in which this branch appears.
* @param branchDN The DN for this branch entry.
*/
{
new TemplateLine[0]);
}
/**
* Creates a new branch with the provided information.
*
* @param templateFile The template file in which this branch
* appears.
* @param branchDN The DN for this branch entry.
* @param subordinateTemplateNames The names of the subordinate templates
* used to generate entries below this
* branch.
* @param numEntriesPerTemplate The number of entries that should be
* created below this branch for each
* subordinate template.
* @param extraLines The set of extra lines that should be
* included in this branch entry.
*/
{
this.extraLines = extraLines;
// Get the RDN template lines based just on the entry DN.
{
try
{
warnings);
TemplateLine l =
tags);
}
catch (Exception e)
{
// This should never happen.
e.printStackTrace();
}
}
{
{
for (ByteString v : a)
{
try
{
}
catch (Exception e)
{
// This should never happen.
e.printStackTrace();
}
}
}
}
{
{
for (ByteString v : a)
{
try
{
}
catch (Exception e)
{
// This should never happen.
e.printStackTrace();
}
}
}
}
}
/**
* Performs any necessary processing to ensure that the branch initialization
* is completed. In particular, it should make sure that all referenced
* subordinate templates actually exist in the template file.
*
* @param templates The set of templates defined in the template file.
*
* @throws MakeLDIFException If any of the subordinate templates are not
* defined in the template file.
*/
throws MakeLDIFException
{
if (subordinateTemplateNames == null)
{
}
else
{
{
subordinateTemplates[i] =
if (subordinateTemplates[i] == null)
{
branchDN, subordinateTemplateNames[i]));
}
}
}
}
/**
* Retrieves the DN for this branch entry.
*
* @return The DN for this branch entry.
*/
public DN getBranchDN()
{
return branchDN;
}
/**
* Retrieves the names of the subordinate templates for this branch.
*
* @return The names of the subordinate templates for this branch.
*/
public String[] getSubordinateTemplateNames()
{
return subordinateTemplateNames;
}
/**
* Retrieves the set of subordinate templates used to generate entries below
* this branch. Note that the subordinate templates will not be available
* until the <CODE>completeBranchInitialization</CODE> method has been called.
*
* @return The set of subordinate templates used to generate entries below
* this branch.
*/
public Template[] getSubordinateTemplates()
{
return subordinateTemplates;
}
/**
* Retrieves the number of entries that should be created below this branch
* for each subordinate template.
*
* @return The number of entries that should be created below this branch for
* each subordinate template.
*/
public int[] getNumEntriesPerTemplate()
{
return numEntriesPerTemplate;
}
/**
* Adds a new subordinate template to this branch. Note that this should not
* be used after <CODE>completeBranchInitialization</CODE> has been called.
*
* @param name The name of the template to use to generate the
* entries.
* @param numEntries The number of entries to create based on the template.
*/
{
}
/**
* Retrieves the set of extra lines that should be included in this branch
* entry.
*
* @return The set of extra lines that should be included in this branch
* entry.
*/
public TemplateLine[] getExtraLines()
{
return extraLines;
}
/**
* Adds the provided template line to the set of extra lines for this branch.
*
* @param line The line to add to the set of extra lines for this branch.
*/
{
}
/**
* Indicates whether this branch contains a reference to the specified
* attribute type, either in the RDN components of the DN or in the extra
* lines.
*
* @param attributeType The attribute type for which to make the
* determination.
*
* @return <CODE>true</CODE> if the branch does contain the specified
* attribute type, or <CODE>false</CODE> if it does not.
*/
{
{
return true;
}
for (TemplateLine l : extraLines)
{
{
return true;
}
}
return false;
}
/**
* Writes the entry for this branch, as well as all appropriate subordinate
* entries.
*
* @param entryWriter The entry writer to which the entries should be
* written.
*
* @return The result that indicates whether processing should continue.
*
* @throws IOException If a problem occurs while attempting to write to the
* LDIF writer.
*
* @throws MakeLDIFException If some other problem occurs.
*/
throws IOException, MakeLDIFException
{
// Create a new template entry and populate it based on the RDN attributes
// and extra lines.
for (TemplateLine l : rdnLines)
{
if (!r.keepProcessingEntry()
|| !r.keepProcessingParent()
|| !r.keepProcessingTemplateFile())
{
return r;
}
}
for (TemplateLine l : extraLines)
{
if ((!r.keepProcessingEntry()
|| !r.keepProcessingParent()
|| !r.keepProcessingTemplateFile()))
{
return r;
}
}
{
return TagResult.STOP_PROCESSING;
}
{
TagResult r =
if (!r.keepProcessingParent()
|| !r.keepProcessingTemplateFile())
{
if (r.keepProcessingTemplateFile())
{
// We don't want to propagate a "stop processing parent" all the way
// up the chain.
return TagResult.SUCCESS_RESULT;
}
return r;
}
}
return TagResult.SUCCESS_RESULT;
}
}