Package er.rest.example.delegates

Source Code of er.rest.example.delegates.CarRestDelegate

package er.rest.example.delegates;

import com.webobjects.eocontrol.EOClassDescription;
import com.webobjects.foundation.NSArray;

import er.extensions.eof.ERXQ;
import er.rest.ERXAbstractRestDelegate;
import er.rest.ERXRestContext;
import er.rest.example.model.Car;

/**
* CarsRestDelegate is an example of a rest delegate for retrieving
* and creating objects of non-EO types. The name of the class is
* important (the delegate for the "Car" entity), though you can manually
* register a different class name via IERXRestDelegate.Factory.
* @author mschrag
*/
public class CarRestDelegate extends ERXAbstractRestDelegate {
  public CarRestDelegate() {
  }
 
  public Object createObjectOfEntityWithID(EOClassDescription entity, Object id, ERXRestContext context) {
    return new Car();
  }
 
  public Object primaryKeyForObject(Object obj, ERXRestContext context) {
    return ((Car) obj).getName();
  }
 
  public Object objectOfEntityWithID(EOClassDescription entity, Object id, ERXRestContext context) {
    NSArray<Car> cars = ERXQ.filtered(Car.cars(), ERXQ.is("name", id));
    return cars.size() == 0 ? null : cars.objectAtIndex(0);
  }
}
TOP

Related Classes of er.rest.example.delegates.CarRestDelegate

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.