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 legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2008 Sun Microsystems, Inc. 025 * Portions Copyright 2014 ForgeRock AS 026 */ 027package org.opends.server.tools.makeldif; 028import org.forgerock.i18n.LocalizableMessage; 029 030 031 032import java.util.List; 033 034import org.opends.server.types.InitializationException; 035 036 037 038/** 039 * This class defines a tag that may be used in a template line. It can be used 040 * to generate content in the resulting LDIF. 041 */ 042public abstract class Tag 043{ 044 /** 045 * Retrieves the name for this tag. 046 * 047 * @return The name for this tag. 048 */ 049 public abstract String getName(); 050 051 052 053 /** 054 * Indicates whether this tag is allowed for use in the extra lines for 055 * branches. 056 * 057 * @return <CODE>true</CODE> if this tag may be used in branch definitions, 058 * or <CODE>false</CODE> if not. 059 */ 060 public abstract boolean allowedInBranch(); 061 062 063 064 /** 065 * Performs any initialization for this tag that may be needed while parsing 066 * a branch definition. 067 * 068 * @param templateFile The template file in which this tag is used. 069 * @param branch The branch in which this tag is used. 070 * @param arguments The set of arguments provided for this tag. 071 * @param lineNumber The line number on which this tag appears in the 072 * template file. 073 * @param warnings A list into which any appropriate warning messages 074 * may be placed. 075 * 076 * @throws InitializationException If a problem occurs while initializing 077 * this tag. 078 */ 079 public void initializeForBranch(TemplateFile templateFile, Branch branch, 080 String[] arguments, int lineNumber, 081 List<LocalizableMessage> warnings) 082 throws InitializationException 083 { 084 // No implementation required by default. 085 } 086 087 088 089 /** 090 * Performs any initialization for this tag that may be needed while parsing 091 * a template definition. 092 * 093 * @param templateFile The template file in which this tag is used. 094 * @param template The template in which this tag is used. 095 * @param arguments The set of arguments provided for this tag. 096 * @param lineNumber The line number on which this tag appears in the 097 * template file. 098 * @param warnings A list into which any appropriate warning messages 099 * may be placed. 100 * 101 * @throws InitializationException If a problem occurs while initializing 102 * this tag. 103 */ 104 public abstract void initializeForTemplate(TemplateFile templateFile, 105 Template template, 106 String[] arguments, int lineNumber, 107 List<LocalizableMessage> warnings) 108 throws InitializationException; 109 110 111 112 /** 113 * Performs any initialization for this tag that may be needed when starting 114 * to generate entries below a new parent. 115 * 116 * @param parentEntry The entry below which the new entries will be 117 * generated. 118 */ 119 public void initializeForParent(TemplateEntry parentEntry) 120 { 121 // No implementation required by default. 122 } 123 124 125 126 /** 127 * Generates the content for this tag by appending it to the provided tag. 128 * 129 * @param templateEntry The entry for which this tag is being generated. 130 * @param templateValue The template value to which the generated content 131 * should be appended. 132 * 133 * @return The result of generating content for this tag. 134 */ 135 public abstract TagResult generateValue(TemplateEntry templateEntry, 136 TemplateValue templateValue); 137} 138