package net.sf.jasperreports.engine.util;

import java.io.InvalidObjectException;
import java.text.AttributedCharacterIterator;
import java.util.HashMap;
import java.util.Map;

public final class JRTextAttribute extends AttributedCharacterIterator.Attribute {
  private static final long serialVersionUID = 10200L;
  
  private static final Map instanceMap = new HashMap(4);
  
  public static JRTextAttribute PDF_FONT_NAME = new JRTextAttribute("PDF_FONT_NAME");
  
  public static JRTextAttribute PDF_ENCODING = new JRTextAttribute("PDF_ENCODING");
  
  public static JRTextAttribute IS_PDF_EMBEDDED = new JRTextAttribute("IS_PDF_EMBEDDED");
  
  public static JRTextAttribute HTML_FONT_FACE = new JRTextAttribute("HTML_FONT_FACE");
  
  private JRTextAttribute(String name) {
    super(name);
    if (getClass() == JRTextAttribute.class)
      instanceMap.put(name, this); 
  }
  
  protected Object readResolve() throws InvalidObjectException {
    if (getClass() != JRTextAttribute.class)
      throw new InvalidObjectException("Subclass didn't correctly implement readResolve"); 
    JRTextAttribute instance = (JRTextAttribute)instanceMap.get(getName());
    if (instance != null)
      return instance; 
    throw new InvalidObjectException("Unknown attribute name");
  }
}
