io.yawp.repository.EndpointFeatures Maven / Gradle / Ivy
package io.yawp.repository;
import io.yawp.commons.utils.kind.KindResolver;
import io.yawp.repository.actions.ActionKey;
import io.yawp.repository.actions.ActionMethod;
import io.yawp.repository.annotations.Endpoint;
import io.yawp.repository.hooks.Hook;
import io.yawp.repository.pipes.Pipe;
import io.yawp.repository.shields.ShieldInfo;
import java.lang.reflect.Method;
import java.util.*;
public class EndpointFeatures {
private Class clazz;
private Map actions;
private Map transformers;
private Set> hooks;
private ShieldInfo super T> shieldInfo;
private Set> pipes;
private List> pipesSink;
public EndpointFeatures(Class clazz) {
this.clazz = clazz;
this.actions = new HashMap<>();
this.transformers = new HashMap<>();
this.hooks = new HashSet<>();
this.pipes = new HashSet<>();
}
private void assertValidPathOrKind() {
Endpoint endpoint = clazz.getAnnotation(Endpoint.class);
if (endpoint == null) {
throw new RuntimeException("The class " + clazz.getName() + " was used as an entity but was not annotated with @Endpoint.");
}
}
public Class getClazz() {
return this.clazz;
}
public Endpoint getEndpointAnnotation() {
return clazz.getAnnotation(Endpoint.class);
}
public String getEndpointPath() {
Endpoint endpoint = clazz.getAnnotation(Endpoint.class);
return endpoint.path();
}
public String getEndpointKind() {
return KindResolver.getKindFromClass(clazz);
}
public ActionMethod getAction(ActionKey key) {
return actions.get(key);
}
public Class> getActionClazz(ActionKey key) {
return actions.get(key).getMethod().getDeclaringClass();
}
public boolean hasCustomAction(ActionKey actionKey) {
return actions.containsKey(actionKey);
}
public Method getTransformer(String name) {
return transformers.get(name);
}
public boolean hasTranformer(String transformerName) {
return transformers.containsKey(transformerName);
}
public Set> getHooks() {
return hooks;
}
public ShieldInfo super T> getShieldInfo() {
return shieldInfo;
}
public Set> getPipes() {
return pipes;
}
public List> getPipesSink() {
return pipesSink;
}
public boolean hasShield() {
return shieldInfo != null;
}
public void setActions(Map actions) {
this.actions = actions;
}
public void setTransformers(Map transformers) {
this.transformers = transformers;
}
public void setHooks(Set> hooks) {
this.hooks = hooks;
}
public void setShieldInfo(ShieldInfo super T> shieldInfo) {
this.shieldInfo = shieldInfo;
}
public void setPipes(Set> pipes) {
this.pipes = pipes;
}
public void setPipesSink(List> pipesSink) {
this.pipesSink = pipesSink;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EndpointFeatures> that = (EndpointFeatures>) o;
return clazz.equals(that.clazz);
}
@Override
public int hashCode() {
return clazz.hashCode();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy