StationDataResource.java :  » UnTagged » windmobile » ch » windmobile » server » resource » Android Open Source

Android Open Source » UnTagged » windmobile 
windmobile » ch » windmobile » server » resource » StationDataResource.java
package ch.windmobile.server.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import ch.windmobile.server.model.WindMobileDataSource;
import ch.windmobile.server.model.xml.StationData;

import com.sun.jersey.api.NotFoundException;

public class StationDataResource {
    private WindMobileDataSource dataSource;
    
    @Context
    UriInfo uriInfo;
    @Context
    Request request;
    String stationId;

    public StationDataResource(UriInfo uriInfo, Request request, String stationId, WindMobileDataSource dataSource) {
        this.uriInfo = uriInfo;
        this.request = request;
        this.stationId = stationId;
        this.dataSource = dataSource;
    }

    @GET
    @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
    public StationData getStationData() {
        try {
            StationData stationData = dataSource.getStationData(stationId);
            if (stationData != null) {
                return stationData;
            } else {
                throw new NotFoundException("No such StationData with id '" + stationId + "'");
            }
        } catch (Exception e) {
            ExceptionHandler.treatException(e);
            return null;
        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.