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

org.raml.model.Raml Maven / Gradle / Ivy

Go to download

Java implementation of the raml parser taken from https://github.com/raml-org/raml-java-parser and adjusted

The newest version!
//Changed by hybris
/*
 * Copyright 2013 (c) MuleSoft, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 */
package org.raml.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.raml.model.parameter.UriParameter;
import org.raml.parser.annotation.Mapping;
import org.raml.parser.annotation.Scalar;
import org.raml.parser.annotation.Sequence;
import org.raml.parser.resolver.ResourceHandler;
import org.raml.parser.rule.SecurityReferenceSequenceRule;


public class Raml implements Serializable
{

    private static final long serialVersionUID = -7107368438040691199L;

    @Scalar(required = true)
    private String title;

    @Scalar()
    private String version;

    @Scalar(rule = org.raml.parser.rule.BaseUriRule.class)
    private String baseUri;

    @Sequence
    private List protocols = new ArrayList();

    @Mapping(rule = org.raml.parser.rule.UriParametersRule.class)
    private Map baseUriParameters = new LinkedHashMap();

    @Scalar()
    private String mediaType;

    @Sequence(rule = org.raml.parser.rule.GlobalSchemasRule.class)
    private List> schemas = new ArrayList>();

    @Sequence
    private List> resourceTypes = new ArrayList>();

    @Sequence
    private List> traits = new ArrayList>();

    @Sequence
    private List> securitySchemes = new ArrayList>();

    @Sequence(rule = SecurityReferenceSequenceRule.class)
    private List securedBy = new ArrayList();

    @Mapping(handler = ResourceHandler.class, implicit = true)
    private Map resources = new LinkedHashMap();

    @Sequence
    private List documentation;

    public Raml()
    {
    }

    public void setDocumentation(List documentation)
    {
        this.documentation = documentation;
    }

    public List getDocumentation()
    {
        return documentation;
    }

    public void setBaseUriParameters(Map uriParameters)
    {
        this.baseUriParameters = uriParameters;
    }

    public void setResources(Map resources)
    {
        this.resources = resources;
    }

    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public String getVersion()
    {
        return version;
    }

    public void setVersion(String version)
    {
        this.version = version;
    }

    public String getBaseUri()
    {
        return baseUri;
    }

    public void setBaseUri(String baseUri)
    {
        this.baseUri = baseUri;
    }

    public String getBasePath()
    {
        //skip protocol separator "//"
        int start = baseUri.indexOf("//") + 2;
        if (start == -1)
        {
            start = 0;
        }

        start = baseUri.indexOf("/", start);
        return baseUri.substring(start);
    }

    public String getUri()
    {
        return "";
    }

    public String getMediaType()
    {
        return mediaType;
    }

    public void setMediaType(String mediaType)
    {
        this.mediaType = mediaType;
    }

    public Map getResources()
    {
        return resources;
    }

    public Map getBaseUriParameters()
    {
        return baseUriParameters;
    }

    public List> getResourceTypes()
    {
        return resourceTypes;
    }

    public void setResourceTypes(List> resourceTypes)
    {
        this.resourceTypes = resourceTypes;
    }

    public List> getTraits()
    {
        return traits;
    }

    public void setTraits(List> traits)
    {
        this.traits = traits;
    }

    public List> getSchemas()
    {
        return schemas;
    }

    public void setSchemas(List> schemas)
    {
        this.schemas = schemas;
    }

    public List getProtocols()
    {
        return protocols;
    }

    public void setProtocols(List protocols)
    {
        this.protocols = protocols;
    }

    public List> getSecuritySchemes()
    {
        return securitySchemes;
    }

    public void setSecuritySchemes(List> securitySchemes)
    {
        this.securitySchemes = securitySchemes;
    }

    public List getSecuredBy()
    {
        return securedBy;
    }

    public void setSecuredBy(List securedBy)
    {
        this.securedBy = securedBy;
    }

    public Map getConsolidatedSchemas()
    {
    	//HYBRIS start - changed HashMap to LinkedHashMap
        Map consolidated = new LinkedHashMap();
        //HYBRIS end
        for (Map map : getSchemas())
        {
            consolidated.putAll(map);
        }
        return consolidated;
    }

    public Resource getResource(String path)
    {
        for (Resource resource : resources.values())
        {
            if (path.startsWith(resource.getRelativeUri()))
            {
                if (path.length() == resource.getRelativeUri().length())
                {
                    return resource;
                }
                if (path.charAt(resource.getRelativeUri().length()) == '/')
                {
                    return resource.getResource(path.substring(resource.getRelativeUri().length()));
                }
            }
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy