001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2006-2008 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2016 ForgeRock AS.
016 */
017package org.opends.server.tools.makeldif;
018
019import java.util.List;
020import java.util.UUID;
021
022import org.forgerock.i18n.LocalizableMessage;
023import org.opends.server.types.InitializationException;
024
025import static org.opends.messages.ToolMessages.*;
026
027/** This class defines a tag that is used to include a GUID in the attribute value. */
028public class GUIDTag
029       extends Tag
030{
031  /** Creates a new instance of this GUID tag. */
032  public GUIDTag()
033  {
034    // No implementation required.
035  }
036
037  @Override
038  public String getName()
039  {
040    return "GUID";
041  }
042
043  @Override
044  public boolean allowedInBranch()
045  {
046    return true;
047  }
048
049  @Override
050  public void initializeForBranch(TemplateFile templateFile, Branch branch,
051                                  String[] arguments, int lineNumber,
052                                  List<LocalizableMessage> warnings)
053         throws InitializationException
054  {
055    if (arguments.length != 0)
056    {
057      LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(
058          getName(), lineNumber, 0, arguments.length);
059      throw new InitializationException(message);
060    }
061  }
062
063  @Override
064  public void initializeForTemplate(TemplateFile templateFile,
065                                    Template template, String[] arguments,
066                                    int lineNumber, List<LocalizableMessage> warnings)
067         throws InitializationException
068  {
069    if (arguments.length != 0)
070    {
071      LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(
072          getName(), lineNumber, 0, arguments.length);
073      throw new InitializationException(message);
074    }
075  }
076
077  @Override
078  public TagResult generateValue(TemplateEntry templateEntry,
079                                 TemplateValue templateValue)
080  {
081    templateValue.append(UUID.randomUUID().toString());
082    return TagResult.SUCCESS_RESULT;
083  }
084}