| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.forgerock.opendj.ldif.TemplateFile.Branch; |
| | |
| | | * @param warnings |
| | | * A list into which any appropriate warning messages may be |
| | | * placed. |
| | | * @throws MakeLDIFException |
| | | * @throws DecodeException |
| | | * if a problem occurs |
| | | */ |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | // No implementation required by default. |
| | | } |
| | | |
| | |
| | | * @param warnings |
| | | * A list into which any appropriate warning messages may be |
| | | * placed. |
| | | * @throws MakeLDIFException |
| | | * @throws DecodeException |
| | | * if a problem occurs |
| | | */ |
| | | public abstract void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException; |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException; |
| | | |
| | | /** |
| | | * Performs any initialization for this tag that may be needed when starting |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if ((arguments.length < 1) || (arguments.length > 2)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), lineNumber, |
| | | 1, 2, arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | String lowerName = arguments[0].toLowerCase(); |
| | | attributeType = schema.getAttributeType(lowerName); |
| | | if (!branch.hasAttribute(attributeType)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_UNDEFINED_ATTRIBUTE.get(arguments[0], lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | if (arguments.length == 2) { |
| | |
| | | if (numCharacters < 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INTEGER_BELOW_LOWER_BOUND.get(numCharacters, 0, |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[1], getName(), |
| | | lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } else { |
| | | numCharacters = 0; |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if ((arguments.length < 1) || (arguments.length > 2)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), lineNumber, |
| | | 1, 2, arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | String lowerName = arguments[0].toLowerCase(); |
| | | attributeType = schema.getAttributeType(lowerName); |
| | | if (!template.hasAttribute(attributeType)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_UNDEFINED_ATTRIBUTE.get(arguments[0], lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | if (arguments.length == 2) { |
| | |
| | | if (numCharacters < 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INTEGER_BELOW_LOWER_BOUND.get(numCharacters, 0, |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[1], getName(), |
| | | lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } else { |
| | | numCharacters = 0; |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber); |
| | | } |
| | | |
| | |
| | | * @param lineNumber |
| | | * The line number on which this tag appears in the template |
| | | * file. |
| | | * @throws MakeLDIFException |
| | | * @throws DecodeException |
| | | * If a problem occurs while initializing this tag. |
| | | */ |
| | | private void initializeInternal(TemplateFile templateFile, String[] arguments, int lineNumber) |
| | | throws MakeLDIFException { |
| | | throws DecodeException { |
| | | if (arguments.length == 0) { |
| | | numComponents = 0; |
| | | } else if (arguments.length == 1) { |
| | |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[0], getName(), |
| | | lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } else { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), lineNumber, |
| | | 0, 1, arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber, warnings); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber, warnings); |
| | | } |
| | | |
| | |
| | | * @param warnings |
| | | * A list into which any appropriate warning messages may be |
| | | * placed. |
| | | * @throws MakeLDIFException |
| | | * @throws DecodeException |
| | | * If a problem occurs while initializing this tag. |
| | | */ |
| | | private void initializeInternal(TemplateFile templateFile, String[] arguments, int lineNumber, |
| | | List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | List<LocalizableMessage> warnings) throws DecodeException { |
| | | random = templateFile.getRandom(); |
| | | |
| | | // There must be at least one argument, and possibly two. |
| | | if ((arguments.length < 1) || (arguments.length > 2)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), lineNumber, |
| | | 1, 2, arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | // The first argument should be the path to the file. |
| | | dataFile = templateFile.getFile(arguments[0]); |
| | | if ((dataFile == null) || (!dataFile.exists())) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_FIND_FILE.get(arguments[0], getName(), lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | // If there is a second argument, then it should be either |
| | |
| | | } else { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_FILE_ACCESS_MODE.get(arguments[1], getName(), |
| | | lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } else { |
| | | sequential = false; |
| | |
| | | } catch (IOException ioe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_READ_FILE.get(arguments[0], getName(), lineNumber, |
| | | String.valueOf(ioe)); |
| | | throw new MakeLDIFException(message, ioe); |
| | | throw DecodeException.fatalError(message, ioe); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | this.templateFile = templateFile; |
| | | |
| | | if (arguments.length != 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(getName(), lineNumber, 0, |
| | | arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if (arguments.length != 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(getName(), lineNumber, 0, |
| | | arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if (arguments.length != 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(getName(), lineNumber, 0, |
| | | arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if ((arguments.length < 1) || (arguments.length > 2)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), lineNumber, |
| | | 1, 2, arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | String lowerName = arguments[0].toLowerCase(); |
| | | AttributeType t = schema.getAttributeType(lowerName); |
| | | if (!branch.hasAttribute(t)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_UNDEFINED_ATTRIBUTE.get(arguments[0], lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | if (arguments.length == 2) { |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if ((arguments.length < 1) || (arguments.length > 2)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), lineNumber, |
| | | 1, 2, arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | String lowerName = arguments[0].toLowerCase(); |
| | | attributeType = schema.getAttributeType(lowerName); |
| | | if (!template.hasAttribute(attributeType)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_UNDEFINED_ATTRIBUTE.get(arguments[0], lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | if (arguments.length == 2) { |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if ((arguments.length < 1) || (arguments.length > 2)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), lineNumber, |
| | | 1, 2, arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | String lowerName = arguments[0].toLowerCase(); |
| | | AttributeType t = schema.getAttributeType(lowerName); |
| | | if (!branch.hasAttribute(t)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_UNDEFINED_ATTRIBUTE.get(arguments[0], lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | if (arguments.length == 2) { |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if ((arguments.length < 1) || (arguments.length > 2)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), lineNumber, |
| | | 1, 2, arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | String lowerName = arguments[0].toLowerCase(); |
| | | attributeType = schema.getAttributeType(lowerName); |
| | | if (!template.hasAttribute(attributeType)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_UNDEFINED_ATTRIBUTE.get(arguments[0], lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | if (arguments.length == 2) { |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | this.templateFile = templateFile; |
| | | |
| | | if (arguments.length != 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(getName(), lineNumber, 0, |
| | | arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber, warnings); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber, warnings); |
| | | } |
| | | |
| | |
| | | * @param warnings |
| | | * A list into which any appropriate warning messages may be |
| | | * placed. |
| | | * @throws MakeLDIFException |
| | | * @throws DecodeException |
| | | * If a problem occurs while initializing this tag. |
| | | */ |
| | | private void initializeInternal(TemplateFile templateFile, String[] arguments, int lineNumber, |
| | | List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | List<LocalizableMessage> warnings) throws DecodeException { |
| | | if (arguments.length == 0) { |
| | | throw new MakeLDIFException(ERR_MAKELDIF_TAG_LIST_NO_ARGUMENTS.get(lineNumber)); |
| | | throw DecodeException.fatalError(ERR_MAKELDIF_TAG_LIST_NO_ARGUMENTS.get(lineNumber)); |
| | | } |
| | | |
| | | valueStrings = new String[arguments.length]; |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if (arguments.length != 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(getName(), lineNumber, 0, |
| | | arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber); |
| | | } |
| | | |
| | |
| | | * @param lineNumber |
| | | * The line number on which this tag appears in the template |
| | | * file. |
| | | * @throws MakeLDIFException |
| | | * @throws DecodeException |
| | | * If a problem occurs while initializing this tag. |
| | | */ |
| | | private void initializeInternal(TemplateFile templateFile, String[] arguments, int lineNumber) |
| | | throws MakeLDIFException { |
| | | throws DecodeException { |
| | | random = templateFile.getRandom(); |
| | | |
| | | if (arguments.length != 1) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(getName(), lineNumber, 1, |
| | | arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | try { |
| | |
| | | if (percentage < 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INTEGER_BELOW_LOWER_BOUND.get(percentage, 0, |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } else if (percentage > 100) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INTEGER_ABOVE_UPPER_BOUND.get(percentage, 100, |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[0], getName(), |
| | | lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber, warnings); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber, warnings); |
| | | } |
| | | |
| | |
| | | * @param warnings |
| | | * A list into which any appropriate warning messages may be |
| | | * placed. |
| | | * @throws MakeLDIFException |
| | | * @throws DecodeException |
| | | * If a problem occurs while initializing this tag. |
| | | */ |
| | | private void initializeInternal(TemplateFile templateFile, String[] arguments, int lineNumber, |
| | | List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | List<LocalizableMessage> warnings) throws DecodeException { |
| | | random = templateFile.getRandom(); |
| | | |
| | | // There must be at least one argument, to specify the type of |
| | | // random value to generate. |
| | | if ((arguments == null) || (arguments.length == 0)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_NO_RANDOM_TYPE_ARGUMENT.get(lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | int numArgs = arguments.length; |
| | |
| | | if (minLength < 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INTEGER_BELOW_LOWER_BOUND.get(minLength, 0, |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } else if (minLength == 0) { |
| | | LocalizableMessage message = WARN_MAKELDIF_TAG_WARNING_EMPTY_VALUE.get(lineNumber); |
| | | warnings.add(message); |
| | |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[1], |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message, nfe); |
| | | throw DecodeException.fatalError(message, nfe); |
| | | } |
| | | } else if ((numArgs == 3) || (numArgs == 4)) { |
| | | randomType = RANDOM_TYPE_NUMERIC; |
| | |
| | | } catch (Exception e) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_FORMAT_STRING.get(arguments[3], |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message, e); |
| | | throw DecodeException.fatalError(message, e); |
| | | } |
| | | } else { |
| | | decimalFormat = null; |
| | |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[1], |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message, nfe); |
| | | throw DecodeException.fatalError(message, nfe); |
| | | } |
| | | |
| | | try { |
| | |
| | | if (maxValue < minValue) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INTEGER_BELOW_LOWER_BOUND.get(maxValue, |
| | | minValue, getName(), lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | valueRange = maxValue - minValue + 1; |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[2], |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message, nfe); |
| | | throw DecodeException.fatalError(message, nfe); |
| | | } |
| | | } else { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), |
| | | lineNumber, 2, 4, numArgs); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } else if (randomTypeString.equals("alphanumeric")) { |
| | | characterSet = ALPHANUMERIC_CHARS; |
| | |
| | | if ((numArgs < 3) || (numArgs > 4)) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), |
| | | lineNumber, 3, 4, numArgs); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | characterSet = arguments[1].toCharArray(); |
| | |
| | | if (maxLength <= 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INTEGER_BELOW_LOWER_BOUND.get(maxLength, 1, |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[1], |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message, nfe); |
| | | throw DecodeException.fatalError(message, nfe); |
| | | } |
| | | } else { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), |
| | | lineNumber, 1, 2, numArgs); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } else if (randomTypeString.equals("telephone")) { |
| | | randomType = RANDOM_TYPE_TELEPHONE; |
| | | } else { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_UNKNOWN_RANDOM_TYPE.get(lineNumber, randomTypeString); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | * placed. |
| | | */ |
| | | private void decodeLength(String[] arguments, int startPos, int lineNumber, List<LocalizableMessage> warnings) |
| | | throws MakeLDIFException { |
| | | throws DecodeException { |
| | | int numArgs = arguments.length - startPos + 1; |
| | | |
| | | if (numArgs == 2) { |
| | |
| | | if (minLength < 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INTEGER_BELOW_LOWER_BOUND.get(minLength, 0, |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } else if (minLength == 0) { |
| | | LocalizableMessage message = WARN_MAKELDIF_TAG_WARNING_EMPTY_VALUE.get(lineNumber); |
| | | warnings.add(message); |
| | |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[startPos], |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message, nfe); |
| | | throw DecodeException.fatalError(message, nfe); |
| | | } |
| | | } else if (numArgs == 3) { |
| | | // There are minimum and maximum lengths. |
| | |
| | | if (minLength < 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INTEGER_BELOW_LOWER_BOUND.get(minLength, 0, |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[startPos], |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message, nfe); |
| | | throw DecodeException.fatalError(message, nfe); |
| | | } |
| | | |
| | | try { |
| | |
| | | if (maxLength < minLength) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INTEGER_BELOW_LOWER_BOUND.get(maxLength, |
| | | minLength, getName(), lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } else if (maxLength == 0) { |
| | | LocalizableMessage message = WARN_MAKELDIF_TAG_WARNING_EMPTY_VALUE.get(lineNumber); |
| | | warnings.add(message); |
| | |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[startPos + 1], |
| | | getName(), lineNumber); |
| | | throw new MakeLDIFException(message, nfe); |
| | | throw DecodeException.fatalError(message, nfe); |
| | | } |
| | | } else { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), lineNumber, |
| | | startPos + 1, startPos + 2, numArgs); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if (arguments.length != 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(getName(), lineNumber, 0, |
| | | arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if (arguments.length != 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(getName(), lineNumber, 0, |
| | | arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber); |
| | | } |
| | | |
| | |
| | | * @param lineNumber |
| | | * The line number on which this tag appears in the template |
| | | * file. |
| | | * @throws MakeLDIFException |
| | | * @throws DecodeException |
| | | * If a problem occurs while initializing this tag. |
| | | */ |
| | | private void initializeInternal(TemplateFile templateFile, String[] arguments, int lineNumber) |
| | | throws MakeLDIFException { |
| | | throws DecodeException { |
| | | switch (arguments.length) { |
| | | case 0: |
| | | initialValue = 0; |
| | |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[0], getName(), |
| | | lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | nextValue = initialValue; |
| | |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[0], getName(), |
| | | lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | if (arguments[1].equalsIgnoreCase("true")) { |
| | |
| | | } else { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_BOOLEAN.get(arguments[1], getName(), |
| | | lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | nextValue = initialValue; |
| | |
| | | default: |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), lineNumber, |
| | | 0, 2, arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if (arguments.length != 1) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(getName(), lineNumber, 1, |
| | | arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | text = arguments[0]; |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if (arguments.length != 1) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(getName(), lineNumber, 1, |
| | | arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | text = arguments[0]; |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForBranch(Schema schema, TemplateFile templateFile, Branch branch, String[] arguments, |
| | | int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | initializeInternal(templateFile, arguments, lineNumber); |
| | | } |
| | | |
| | |
| | | * @param lineNumber |
| | | * The line number on which this tag appears in the template |
| | | * file. |
| | | * @throws MakeLDIFException |
| | | * @throws DecodeException |
| | | * TODO |
| | | */ |
| | | private void initializeInternal(TemplateFile templateFile, String[] arguments, int lineNumber) |
| | | throws MakeLDIFException { |
| | | throws DecodeException { |
| | | if (arguments.length == 0) { |
| | | numComponents = 0; |
| | | } else if (arguments.length == 1) { |
| | |
| | | } catch (NumberFormatException nfe) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_CANNOT_PARSE_AS_INTEGER.get(arguments[0], getName(), |
| | | lineNumber); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } else { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_RANGE_COUNT.get(getName(), lineNumber, |
| | | 0, 1, arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void initializeForTemplate(Schema schema, TemplateFile templateFile, Template template, |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws MakeLDIFException { |
| | | String[] arguments, int lineNumber, List<LocalizableMessage> warnings) throws DecodeException { |
| | | if (arguments.length != 0) { |
| | | LocalizableMessage message = ERR_MAKELDIF_TAG_INVALID_ARGUMENT_COUNT.get(getName(), lineNumber, 0, |
| | | arguments.length); |
| | | throw new MakeLDIFException(message); |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | } |
| | | |