package com.peterphi.std.guice.restclient.jaxb.webquery;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

/**
 * Defines a sort instruction
 */
@XmlType(name = "OrderType")
public class WQOrder
{
	@XmlAttribute
	public String field;

	/**
	 * ASC or DESC
	 */
	@XmlAttribute
	public String direction;


	public WQOrder()
	{
	}


	public WQOrder(final String field, final String direction)
	{
		if (!direction.equalsIgnoreCase("asc") && !direction.equalsIgnoreCase("desc"))
			throw new IllegalArgumentException("Direction must be asc or desc, not " + direction);

		this.field = field;
		this.direction = direction.toLowerCase();
	}


	public boolean isAsc()
	{
		return this.direction.equalsIgnoreCase("asc");
	}


	public String toLegacyForm()
	{
		return field + " " + direction;
	}


	@Override
	public String toString()
	{
		return "WQOrder{" + toLegacyForm() + '}';
	}


	public static WQOrder asc(final String field)
	{
		return new WQOrder(field, "asc");
	}


	public static WQOrder desc(final String field)
	{
		return new WQOrder(field, "desc");
	}


	public static WQOrder parseLegacy(final String expr)
	{
		final String[] parts = expr.split(" ", 2);

		return new WQOrder(parts[0], parts[1]);
	}
}

@@ -139,16 +139,45 @@
 XmlType;
+%0Aimport java.beans.Transient;
 %0A%0A/**%0A *
@@ -691,32 +691,151 @@
 werCase();%0A%09%7D%0A%0A%0A
+%09public String getField()%0A%09%7B%0A%09%09return field;%0A%09%7D%0A%0A%0A%09public String getDirection()%0A%09%7B%0A%09%09return direction;%0A%09%7D%0A%0A%09@Transient%0A
 %09public boolean 

Add getters for WQOrder fields