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

io.protostuff.compiler.model.Service Maven / Gradle / Ivy

There is a newer version: 3.1.40
Show newest version
package io.protostuff.compiler.model;

import com.google.common.base.MoreObjects;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author Kostiantyn Shchepanovskyi
 */
public class Service extends AbstractDescriptor implements Type {

    private final Proto parent;
    private Proto proto;
    private String fullyQualifiedName;
    private List methods;

    public Service(Proto parent) {
        this.parent = parent;
    }

    @Override
    public Proto getParent() {
        return parent;
    }

    @Override
    public DescriptorType getDescriptorType() {
        return DescriptorType.SERVICE;
    }

    public Proto getProto() {
        return proto;
    }

    public void setProto(Proto proto) {
        this.proto = proto;
    }

    public String getFullyQualifiedName() {
        return fullyQualifiedName;
    }

    public void setFullyQualifiedName(String fullyQualifiedName) {
        this.fullyQualifiedName = fullyQualifiedName;
    }

    public List getMethods() {
        if (methods == null) {
            return Collections.emptyList();
        }
        return methods;
    }

    public void setMethods(List methods) {
        this.methods = methods;
    }

    public ServiceMethod getMethod(String name) {
        for (ServiceMethod serviceMethod : getMethods()) {
            if (serviceMethod.getName().equals(name)) {
                return serviceMethod;
            }
        }
        return null;
    }

    public void addMethod(ServiceMethod method) {
        if (methods == null) {
            methods = new ArrayList<>();
        }
        methods.add(method);
    }

    public String getCanonicalName() {
        return fullyQualifiedName.substring(1);
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("name", name)
                .add("fullyQualifiedName", fullyQualifiedName)
                .add("methods", methods)
                .add("options", options)
                .toString();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy