001package org.andromda.schema2xmi;
002
003import org.apache.commons.lang.StringUtils;
004
005/**
006 * Contains utilities for the Schema2XMI tool.
007 *
008 * @author Chad Brandon
009 * @author Joel Kozikowski
010 */
011class Schema2XMIUtils
012{
013    /**
014     * Constructs the entire type name from the
015     * given name and length.
016     *
017     * @param name the name of the type
018     * @param length the length of the type.
019     * @param decimalPlaces the number of decimal places specified for the type
020     * @return the type name with the length.
021     */
022    static String constructTypeName(
023        final String name,
024        final String length,
025        final String decimalPlaces)
026    {
027        final StringBuilder buffer = new StringBuilder();
028        if (name != null)
029        {
030            buffer.append(name);
031
032            if (!name.matches(".+\\(.+\\)"))
033            {
034                if (StringUtils.isNotBlank(length))
035                {
036                    buffer.append('(').append(length);
037                    if (StringUtils.isNotBlank(decimalPlaces))
038                    {
039                        buffer.append(',').append(decimalPlaces);
040                    }
041                    buffer.append(')');
042                }
043            }
044
045        }
046        return buffer.toString();
047    }
048}