001    /*
002     * CDDL HEADER START
003     *
004     * The contents of this file are subject to the terms of the
005     * Common Development and Distribution License, Version 1.0 only
006     * (the "License").  You may not use this file except in compliance
007     * with the License.
008     *
009     * You can obtain a copy of the license at
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2006-2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.tools.makeldif;
028    
029    
030    
031    import org.opends.server.types.AttributeType;
032    
033    import static org.opends.server.util.StaticUtils.*;
034    
035    
036    
037    /**
038     * This class defines a line that may appear in a template or branch.  It may
039     * contain any number of tags to be evaluated.
040     */
041    public class TemplateLine
042    {
043      // The attribute type for this template line.
044      private AttributeType attributeType;
045    
046      // The line number on which this template line appears in the template file.
047      private int lineNumber;
048    
049      // The set of tags for this template line.
050      private Tag[] tags;
051    
052    
053    
054      /**
055       * Creates a new template line with the provided information.
056       *
057       * @param  attributeType  The attribute type for this template line.
058       * @param  lineNumber     The line number on which this template line appears
059       *                        in the template file.
060       * @param  tags           The set of tags for this template line.
061       */
062      public TemplateLine(AttributeType attributeType, int lineNumber, Tag[] tags)
063      {
064        this.attributeType = attributeType;
065        this.lineNumber    = lineNumber;
066        this.tags          = tags;
067      }
068    
069    
070    
071      /**
072       * Retrieves the attribute type for this template line.
073       *
074       * @return  The attribute type for this template line.
075       */
076      public AttributeType getAttributeType()
077      {
078        return attributeType;
079      }
080    
081    
082    
083      /**
084       * Retrieves the line number on which this template line appears in the
085       * template file.
086       *
087       * @return  The line number on which this template line appears in the
088       *          template file.
089       */
090      public int getLineNumber()
091      {
092        return lineNumber;
093      }
094    
095    
096    
097      /**
098       * Retrieves the set of tags for this template line.
099       *
100       * @return  The set of tags for this template line.
101       */
102      public Tag[] getTags()
103      {
104        return tags;
105      }
106    
107    
108    
109      /**
110       * Generates the content for this template line and places it in the provided
111       * template entry.
112       *
113       * @param  templateEntry  The template entry being generated.
114       *
115       * @return  The result of generating the template line.
116       */
117      public TagResult generateLine(TemplateEntry templateEntry)
118      {
119        TemplateValue value = new TemplateValue(this);
120    
121        for (Tag t : tags)
122        {
123          TagResult result = t.generateValue(templateEntry, value);
124          if (! (result.keepProcessingLine() && result.keepProcessingEntry() &&
125                 result.keepProcessingParent() &&
126                 result.keepProcessingTemplateFile()))
127          {
128            return result;
129          }
130        }
131    
132        templateEntry.addValue(value);
133        return TagResult.SUCCESS_RESULT;
134      }
135    }
136