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 ForgeRock AS. 016 */ 017package org.opends.server.tools.makeldif; 018import org.forgerock.i18n.LocalizableMessage; 019 020 021 022import java.util.List; 023 024import org.opends.server.types.InitializationException; 025 026 027 028/** 029 * This class defines a tag that may be used in a template line. It can be used 030 * to generate content in the resulting LDIF. 031 */ 032public abstract class Tag 033{ 034 /** 035 * Retrieves the name for this tag. 036 * 037 * @return The name for this tag. 038 */ 039 public abstract String getName(); 040 041 042 043 /** 044 * Indicates whether this tag is allowed for use in the extra lines for 045 * branches. 046 * 047 * @return <CODE>true</CODE> if this tag may be used in branch definitions, 048 * or <CODE>false</CODE> if not. 049 */ 050 public abstract boolean allowedInBranch(); 051 052 053 054 /** 055 * Performs any initialization for this tag that may be needed while parsing 056 * a branch definition. 057 * 058 * @param templateFile The template file in which this tag is used. 059 * @param branch The branch in which this tag is used. 060 * @param arguments The set of arguments provided for this tag. 061 * @param lineNumber The line number on which this tag appears in the 062 * template file. 063 * @param warnings A list into which any appropriate warning messages 064 * may be placed. 065 * 066 * @throws InitializationException If a problem occurs while initializing 067 * this tag. 068 */ 069 public void initializeForBranch(TemplateFile templateFile, Branch branch, 070 String[] arguments, int lineNumber, 071 List<LocalizableMessage> warnings) 072 throws InitializationException 073 { 074 // No implementation required by default. 075 } 076 077 078 079 /** 080 * Performs any initialization for this tag that may be needed while parsing 081 * a template definition. 082 * 083 * @param templateFile The template file in which this tag is used. 084 * @param template The template in which this tag is used. 085 * @param arguments The set of arguments provided for this tag. 086 * @param lineNumber The line number on which this tag appears in the 087 * template file. 088 * @param warnings A list into which any appropriate warning messages 089 * may be placed. 090 * 091 * @throws InitializationException If a problem occurs while initializing 092 * this tag. 093 */ 094 public abstract void initializeForTemplate(TemplateFile templateFile, 095 Template template, 096 String[] arguments, int lineNumber, 097 List<LocalizableMessage> warnings) 098 throws InitializationException; 099 100 101 102 /** 103 * Performs any initialization for this tag that may be needed when starting 104 * to generate entries below a new parent. 105 * 106 * @param parentEntry The entry below which the new entries will be 107 * generated. 108 */ 109 public void initializeForParent(TemplateEntry parentEntry) 110 { 111 // No implementation required by default. 112 } 113 114 115 116 /** 117 * Generates the content for this tag by appending it to the provided tag. 118 * 119 * @param templateEntry The entry for which this tag is being generated. 120 * @param templateValue The template value to which the generated content 121 * should be appended. 122 * 123 * @return The result of generating content for this tag. 124 */ 125 public abstract TagResult generateValue(TemplateEntry templateEntry, 126 TemplateValue templateValue); 127} 128