/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This source file is part of SableVM.                            *
 *                                                                 *
 * See the file "LICENSE" for the copyright information and for    *
 * the terms and conditions for copying, distribution and          *
 * modification of this source file.                               *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/**
 * @author Patrick Latifi
 */
import java.io.*;

class SInnerClassesAttributeParser implements SParser
{
	private static SInnerClassesAttributeParser instance;

	private SInnerClassesAttributeParser()
	{
	}

	public static SInnerClassesAttributeParser getInstance()
	{
		if (instance == null)
			instance = new SInnerClassesAttributeParser();

		return instance;
	}

	public Object read(DataInputStream d) throws SClassFileException
	{
	    SClasses classes;
		
	    try {
		    classes = (SClasses) SClassesParser.getInstance().read(d);
		    return new SInnerClassesAttribute(
			SAttributeInfoParser.getInstance().
			getAttributeNameIndex(),
			SAttributeInfoParser.getInstance().getAttributeLength(),
			classes);
	    }
	    catch(SClassFileException cfe) {
		throw new SClassFileException(
			"In " + SConstants.INNER_CLASSES_ATTRIBUTE + " " +
			cfe.getMessage());
	    }
	}

	public void write(DataOutputStream d, Object obj)
		throws SClassFileException
	{
		SInnerClassesAttribute attribute = (SInnerClassesAttribute) obj;

		SClassesParser.getInstance().write(d, attribute.getClasses());
	}
}
