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    import org.opends.messages.Message;
029    
030    
031    
032    import java.util.List;
033    
034    import org.opends.server.types.InitializationException;
035    
036    import static org.opends.messages.ToolMessages.*;
037    
038    
039    
040    /**
041     * This class defines a tag that is used to include a last name in the
042     * attribute value.
043     */
044    public class LastNameTag
045           extends Tag
046    {
047      // The template file with which this tag is associated.
048      private TemplateFile templateFile;
049    
050    
051    
052      /**
053       * Creates a new instance of this last name tag.
054       */
055      public LastNameTag()
056      {
057        // No implementation required.
058      }
059    
060    
061    
062      /**
063       * Retrieves the name for this tag.
064       *
065       * @return  The name for this tag.
066       */
067      public String getName()
068      {
069        return "Last";
070      }
071    
072    
073    
074      /**
075       * Indicates whether this tag is allowed for use in the extra lines for
076       * branches.
077       *
078       * @return  <CODE>true</CODE> if this tag may be used in branch definitions,
079       *          or <CODE>false</CODE> if not.
080       */
081      public boolean allowedInBranch()
082      {
083        return false;
084      }
085    
086    
087    
088      /**
089       * Performs any initialization for this tag that may be needed while parsing
090       * a template definition.
091       *
092       * @param  templateFile  The template file in which this tag is used.
093       * @param  template      The template in which this tag is used.
094       * @param  arguments     The set of arguments provided for this tag.
095       * @param  lineNumber    The line number on which this tag appears in the
096       *                       template file.
097       * @param  warnings      A list into which any appropriate warning messages
098       *                       may be placed.
099       *
100       * @throws  InitializationException  If a problem occurs while initializing
101       *                                   this tag.
102       */
103      public void initializeForTemplate(TemplateFile templateFile,
104                                        Template template, String[] arguments,
105                                        int lineNumber, List<Message> warnings)
106             throws InitializationException
107      {
108        this.templateFile = templateFile;
109    
110        if (arguments.length != 0)
111        {
112          Message message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(
113              getName(), lineNumber, 0, arguments.length);
114          throw new InitializationException(message);
115        }
116      }
117    
118    
119    
120      /**
121       * Generates the content for this tag by appending it to the provided tag.
122       *
123       * @param  templateEntry  The entry for which this tag is being generated.
124       * @param  templateValue  The template value to which the generated content
125       *                        should be appended.
126       *
127       * @return  The result of generating content for this tag.
128       */
129      public TagResult generateValue(TemplateEntry templateEntry,
130                                     TemplateValue templateValue)
131      {
132        templateValue.append(templateFile.getLastName());
133        return TagResult.SUCCESS_RESULT;
134      }
135    }
136