// Path: src/main/java/uk/bl/odin/orcid/guice/SelfInjectingServerResource.java
// public abstract class SelfInjectingServerResource extends ServerResource {
// 
// 	/**
// 	 * Implemented by DI framework-specific code. For example, with Guice, the
// 	 * statically-injected MembersInjector just calls
// 	 * {@code injector.injectMembers(object)}.
// 	 */
// 	public interface MembersInjector {
// 		void injectMembers(Object object);
// 	}
// 
// 	/**
// 	 * Subclasseses overriding this method must call {@code super.doInit()}
// 	 * first.
// 	 */
// 	protected void doInit() {
// 		ensureInjected(theMembersInjector);
// 	}
// 
// 	@Inject
// 	private void injected() { // NOPMD
// 		injected.set(true);
// 	}
// 
// 	void ensureInjected(MembersInjector membersInjector) {
// 		if (injected.compareAndSet(false, true)) {
// 			membersInjector.injectMembers(this);
// 		}
// 	}
// 
// 	/**
// 	 * Whether we've been injected yet. This protects against multiple injection
// 	 * of a subclass that gets injected before doInit is called.
// 	 */
// 	private final AtomicBoolean injected = new AtomicBoolean(false);
// 
// 	/**
// 	 * Must be statically injected by DI framework.
// 	 */
// 	@Inject
// 	private static volatile MembersInjector theMembersInjector;
// }


import java.io.IOException;
import javax.inject.Inject;
import org.restlet.data.Status;
import org.restlet.ext.jaxb.JaxbRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import uk.bl.odin.orcid.client.OrcidPublicClient;
import uk.bl.odin.orcid.guice.SelfInjectingServerResource;
import uk.bl.odin.orcid.schema.messages.onepointtwo.OrcidProfile;
package uk.bl.odin.orcid.rest;





/**
 * Fetches orcid profiles and passes them through
 * 
 */
public class OrcidProfileResource extends SelfInjectingServerResource {

	@Inject
	OrcidPublicClient client;

	@Get("xml")
	public Representation getProfile() {
		try {
			OrcidProfile profile = client.getOrcidProfile(this.getAttribute("orcid"));
			return new JaxbRepresentation<OrcidProfile>(profile);
		} catch (ResourceException e) {
			setStatus(Status.CLIENT_ERROR_BAD_REQUEST, "invalid orcid, cannot resolve orcid");
		} catch (IOException e) {
// Path: src/main/java/uk/bl/odin/orcid/guice/SelfInjectingServerResource.java
// public abstract class SelfInjectingServerResource extends ServerResource {
// 
// 	/**
// 	 * Implemented by DI framework-specific code. For example, with Guice, the
// 	 * statically-injected MembersInjector just calls
// 	 * {@code injector.injectMembers(object)}.
// 	 */
// 	public interface MembersInjector {
// 		void injectMembers(Object object);
// 	}
// 
// 	/**
// 	 * Subclasseses overriding this method must call {@code super.doInit()}
// 	 * first.
// 	 */
// 	protected void doInit() {
// 		ensureInjected(theMembersInjector);
// 	}
// 
// 	@Inject
// 	private void injected() { // NOPMD
// 		injected.set(true);
// 	}
// 
// 	void ensureInjected(MembersInjector membersInjector) {
// 		if (injected.compareAndSet(false, true)) {
// 			membersInjector.injectMembers(this);
// 		}
// 	}
// 
// 	/**
// 	 * Whether we've been injected yet. This protects against multiple injection
// 	 * of a subclass that gets injected before doInit is called.
// 	 */
// 	private final AtomicBoolean injected = new AtomicBoolean(false);
// 
// 	/**
// 	 * Must be statically injected by DI framework.
// 	 */
// 	@Inject
// 	private static volatile MembersInjector theMembersInjector;
// }


// Path: src/main/java/uk/bl/odin/orcid/rest/OrcidProfileResource.java
import java.io.IOException;
import javax.inject.Inject;
import org.restlet.data.Status;
import org.restlet.ext.jaxb.JaxbRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
import uk.bl.odin.orcid.client.OrcidPublicClient;
import uk.bl.odin.orcid.guice.SelfInjectingServerResource;
import uk.bl.odin.orcid.schema.messages.onepointtwo.OrcidProfile;

package uk.bl.odin.orcid.rest;





/**
 * Fetches orcid profiles and passes them through
 * 
 */
public class OrcidProfileResource extends SelfInjectingServerResource {

	@Inject
	OrcidPublicClient client;

	@Get("xml")
	public Representation getProfile() {
		try {
			OrcidProfile profile = client.getOrcidProfile(this.getAttribute("orcid"));
			return new JaxbRepresentation<OrcidProfile>(profile);
		} catch (ResourceException e) {
			setStatus(Status.CLIENT_ERROR_BAD_REQUEST, "invalid orcid, cannot resolve orcid");
		} catch (IOException e) {
			this.setStatus(Status.SERVER_ERROR_BAD_GATEWAY, e.getMessage());