package com.sap.core.odata.api.exception;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * A {@link MessageReference} references to the used message for an {@link ODataHttpException} and is used to support
 * internationalization and translation of exception messages for all {@link ODataHttpException} and sub classes.
 * Theses classes all contains a {@link MessageReference} object which can be mapped to a related key and message in the resource bundles.
 * @author SAP AG
 */
public abstract class MessageReference {

  protected final String key;
  protected List<Object> content = null;

  private MessageReference(String key) {
    this(key, null);
  }

  private MessageReference(String key, List<Object> content) {
    this.key = key;
    this.content = content;
  }

  /**
   * Create a {@link MessageReference} for given <code>class</code> and <code>key</code>.
   * These combination of <code>class</code> and <code>key</code> has to be provided by a resource bundle.
   * 
   * @param clazz
   *        {@link ODataHttpException} for which this {@link MessageReference} should be used.
   * @param key
   *        Unique key (in context of {@link ODataHttpException}) for reference to message in resource bundle
   * @return created {@link MessageReference}
   */
  public static MessageReference create(Class<? extends ODataException> clazz, String key) {
    return new SimpleMessageReference(clazz.getName() + "." + key);
  }

  /**
   * Returns message key.
   */
  public String getKey() {
    return key;
  }

  /**
   * Add given content to message reference.
   */
  public MessageReference addContent(Object... content) {
    return new SimpleMessageReference(this.key, content);
  }

  /**
   * Receive content for this {@link MessageReference}.
   * Beware that returned list is immutable.
   */
  public List<?> getContent() {
    if (content == null)
      return Collections.emptyList();
    else
      return Collections.unmodifiableList(content);
  }

  /**
   * Simple inner class for realization of {@link MessageReference} interface.
   */
  private static class SimpleMessageReference extends MessageReference {
    public SimpleMessageReference(String implKey) {
      super(implKey);
    }

    public SimpleMessageReference(String implKey, List<Object> content) {
      super(implKey, content);
    }

    public SimpleMessageReference(String implKey, Object... content) {
      super(implKey, Arrays.asList(content));
    }

    @Override
    public MessageReference addContent(Object... content) {
      if (this.content == null)
        this.content = new ArrayList<Object>();
      
      for (Object object : content)
        this.content.add(object);
      return this;
    }
  }

  public MessageReference create() {
    return new SimpleMessageReference(this.key);
  }
}
@@ -40,36 +40,8 @@
 n;%0A%0A
-import java.util.ArrayList;%0A
 impo
@@ -1467,32 +1467,125 @@
 .%22 + key);%0A  %7D%0A%0A
+  public MessageReference create() %7B%0A    return new SimpleMessageReference(this.key);%0A  %7D%0A  %0A
   /**%0A   * Retur
@@ -2589,356 +2589,8 @@
    %7D
-%0A%0A    @Override%0A    public MessageReference addContent(Object... content) %7B%0A      if (this.content == null)%0A        this.content = new ArrayList%3CObject%3E();%0A      %0A      for (Object object : content)%0A        this.content.add(object);%0A      return this;%0A    %7D%0A  %7D%0A%0A  public MessageReference create() %7B%0A    return new SimpleMessageReference(this.key);
 %0A  %7D

Fix with addContent