/**
* Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.web.region;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import org.joda.beans.impl.flexi.FlexiBean;
import com.opengamma.master.region.RegionMaster;
import com.opengamma.util.ArgumentChecker;
import com.opengamma.web.AbstractPerRequestWebResource;
import com.opengamma.web.WebHomeUris;
/**
* Abstract base class for RESTful region resources.
*/
public abstract class AbstractWebRegionResource extends AbstractPerRequestWebResource {
/**
* HTML ftl directory
*/
protected static final String HTML_DIR = "regions/html/";
/**
* JSON ftl directory
*/
protected static final String JSON_DIR = "regions/json/";
/**
* The backing bean.
*/
private final WebRegionData _data;
/**
* Creates the resource.
* @param regionMaster the region master, not null
*/
protected AbstractWebRegionResource(final RegionMaster regionMaster) {
ArgumentChecker.notNull(regionMaster, "regionMaster");
_data = new WebRegionData();
data().setRegionMaster(regionMaster);
}
/**
* Creates the resource.
* @param parent the parent resource, not null
*/
protected AbstractWebRegionResource(final AbstractWebRegionResource parent) {
super(parent);
_data = parent._data;
}
/**
* Setter used to inject the URIInfo.
* This is a roundabout approach, because Spring and JSR-311 injection clash.
* DO NOT CALL THIS METHOD DIRECTLY.
* @param uriInfo the URI info, not null
*/
@Context
public void setUriInfo(final UriInfo uriInfo) {
data().setUriInfo(uriInfo);
}
//-------------------------------------------------------------------------
/**
* Creates the output root data.
* @return the output root data, not null
*/
protected FlexiBean createRootData() {
FlexiBean out = getFreemarker().createRootData();
out.put("homeUris", new WebHomeUris(data().getUriInfo()));
out.put("uris", new WebRegionUris(data()));
return out;
}
//-------------------------------------------------------------------------
/**
* Gets the backing bean.
* @return the beacking bean, not null
*/
protected WebRegionData data() {
return _data;
}
}