Package org.jboss.resteasy.links.impl

Source Code of org.jboss.resteasy.links.impl.LinkDecorator

package org.jboss.resteasy.links.impl;

import java.lang.annotation.Annotation;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Marshaller.Listener;

import org.jboss.resteasy.core.ResourceMethodRegistry;
import org.jboss.resteasy.links.AddLinks;
import org.jboss.resteasy.spi.Registry;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.interception.DecoratorProcessor;

public class LinkDecorator implements DecoratorProcessor<Marshaller, AddLinks> {

  public Marshaller decorate(Marshaller target, final AddLinks annotation,
      Class type, Annotation[] annotations, MediaType mediaType) {
    target.setListener(new Listener() {
      @Override
      public void beforeMarshal(Object entity) {
        UriInfo uriInfo = ResteasyProviderFactory.getContextData(UriInfo.class);
        ResourceMethodRegistry registry = (ResourceMethodRegistry) ResteasyProviderFactory.getContextData(Registry.class);

        // find all rest service classes and scan them
        RESTUtils.addDiscovery(entity, uriInfo, registry);
      }
    });
    return target;
  }
}
TOP

Related Classes of org.jboss.resteasy.links.impl.LinkDecorator

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.