All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.beimin.eveapi.handler.AbstractContentListHandler Maven / Gradle / Ivy

There is a newer version: 7.0.4
Show newest version
package com.beimin.eveapi.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.beimin.eveapi.response.ApiListResponse;
import com.beimin.eveapi.response.ApiResponse;

public abstract class AbstractContentListHandler, B> extends AbstractContentHandler {
	private static final Logger LOGGER = LoggerFactory.getLogger(AbstractContentListHandler.class);

	private final Class clazz;
	protected E response;

	public AbstractContentListHandler(Class clazz) {
		this.clazz = clazz;
	}

	@Override
	public void startDocument() throws SAXException {
		try {
			response = clazz.newInstance();
		} catch (InstantiationException e) {
			LOGGER.error("Could't start document", e);
		} catch (IllegalAccessException e) {
			LOGGER.error("Could't start document", e);
		}
	}
	
	@Override
	public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
		if (qName.equals("row")) {
			response.add(getItem(attrs));
		}
		super.startElement(uri, localName, qName, attrs);
	}
	
	protected abstract B getItem(Attributes attrs);

	@Override
	public ApiResponse getResponse() {
		return response;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy