class TagDaoHelper {

    public void validateParentTagEntity(TagEntity tagEntity, TagEntity parentTagEntity)
    {
        Integer maxAllowedTagNesting = configurationHelper.getProperty(ConfigurationValue.MAX_ALLOWED_TAG_NESTING, Integer.class);

        TagEntity localParentTagEntity = parentTagEntity;
        int level = 0;
        while (localParentTagEntity != null)
        {
            Assert.isTrue(!tagEntity.equals(localParentTagEntity), "Parent tag key cannot be the requested tag key or any of its children’s tag keys.");
            localParentTagEntity = localParentTagEntity.getParentTagEntity();
            if (level++ >= maxAllowedTagNesting)
            {
                throw new IllegalArgumentException("Exceeds maximum allowed tag nesting level of " + maxAllowedTagNesting);
            }
        }
    }

}