All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jn.agileway.jaxrs.rr.requestmapping.JaxrsRequestMappingAccessor Maven / Gradle / Ivy

The newest version!
package com.jn.agileway.jaxrs.rr.requestmapping;

import com.jn.agileway.http.rr.requestmapping.RequestMappingAccessor;
import com.jn.langx.util.collection.Collects;
import com.jn.langx.util.enums.Enums;
import com.jn.langx.util.net.http.HttpMethod;

import javax.ws.rs.*;
import java.lang.annotation.Annotation;
import java.util.List;

public class JaxrsRequestMappingAccessor implements RequestMappingAccessor {
    private E mappingAnno;
    private Path pathAnno;
    private Consumes consumesAnno;
    private Produces producesAnno;
    private List paths;
    private List methods;

    public JaxrsRequestMappingAccessor(E mappingAnno, Path pathAnno, Produces producesAnno, Consumes consumesAnno, List paths) {
        setMapping(mappingAnno);
        this.pathAnno = pathAnno;
        this.producesAnno = producesAnno;
        this.consumesAnno = consumesAnno;
        this.paths = paths;
        initMethods();
    }

    private void initMethods(){
        HttpMethod method = null;
        if (mappingAnno instanceof javax.ws.rs.HttpMethod) {
            method = Enums.ofName(HttpMethod.class, ((javax.ws.rs.HttpMethod) mappingAnno).value());
        } else if (mappingAnno instanceof GET) {
            method = HttpMethod.GET;
        } else if (mappingAnno instanceof POST) {
            method = HttpMethod.POST;
        } else if (mappingAnno instanceof DELETE) {
            method = HttpMethod.DELETE;
        } else if (mappingAnno instanceof PATCH) {
            method = HttpMethod.PATCH;
        }
        else if(mappingAnno instanceof  PUT){
            method = HttpMethod.PUT;
        }else if(mappingAnno instanceof  OPTIONS){
            method = HttpMethod.OPTIONS;
        }
        else if(mappingAnno instanceof  HEAD){
            method = HttpMethod.HEAD;
        }
        else {
            method = HttpMethod.TRACE;
        }
        this.methods = Collects.immutableArrayList(method);
    }


    @Override
    public E getMapping() {
        return this.mappingAnno;
    }

    @Override
    public void setMapping(E mapping) {
        this.mappingAnno = mapping;
    }

    @Override
    public String name() {
        return null;
    }

    @Override
    public List values() {
        return paths;
    }

    @Override
    public List paths() {
        return paths;
    }

    @Override
    public List params() {
        return null;
    }

    @Override
    public List headers() {
        return null;
    }



    @Override
    public List methods() {
        return this.methods;
    }

    @Override
    public List consumes() {
        return consumesAnno == null ? Collects.emptyArrayList() : Collects.asList(consumesAnno.value());
    }

    @Override
    public List produces() {
        return producesAnno == null ? Collects.emptyArrayList() : Collects.asList(producesAnno.value());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy