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

com.sap.cds.reflect.impl.CdsServiceBuilder Maven / Gradle / Ivy

There is a newer version: 3.6.1
Show newest version
/*******************************************************************
 * © 2020 SAP SE or an SAP affiliate company. All rights reserved. *
 *******************************************************************/
package com.sap.cds.reflect.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;

import com.sap.cds.reflect.CdsAction;
import com.sap.cds.reflect.CdsAnnotation;
import com.sap.cds.reflect.CdsEntity;
import com.sap.cds.reflect.CdsEvent;
import com.sap.cds.reflect.CdsFunction;
import com.sap.cds.reflect.CdsService;

public class CdsServiceBuilder extends CdsDefinitionBuilder {

	private List events;
	private List entities;
	private List functions;
	private List actions;

	public CdsServiceBuilder(List> annotations, String qualifiedName) {
		super(annotations, qualifiedName);
	}

	public void setEvents(List events) {
		this.events = new ArrayList<>(events);
	}

	public void setEntities(List entities) {
		this.entities = new ArrayList<>(entities);
	}

	public void setFunctions(List functions) {
		this.functions = new ArrayList<>(functions);
	}

	public void setActions(List actions) {
		this.actions = new ArrayList<>(actions);
	}

	@Override
	public CdsService build() {
		ArrayList immutableEntities = new ArrayList<>();
		ArrayList immutableEvents = new ArrayList<>();
		ArrayList immutableActions = new ArrayList<>();
		ArrayList immutableFunctions = new ArrayList<>();
		entities.forEach(e -> immutableEntities.add(e.build()));
		events.forEach(e -> immutableEvents.add(e.build()));
		actions.forEach(a -> immutableActions.add(a.build()));
		functions.forEach(a -> immutableFunctions.add(a.build()));
		return new CdsServiceImpl(annotations, qualifiedName, immutableEvents, immutableEntities, immutableFunctions,
				immutableActions);
	}

	private static class CdsServiceImpl extends CdsDefinitionImpl implements CdsService {

		private final List events;
		private final List entities;
		private final List functions;
		private final List actions;

		private CdsServiceImpl(Collection> annotations, String qualifiedName, List events,
				List entities, List functions, List actions) {
			super(annotations, qualifiedName);
			this.events = new ArrayList<>(events);
			this.entities = new ArrayList<>(entities);
			this.functions = new ArrayList<>(functions);
			this.actions = new ArrayList<>(actions);
		}

		@Override
		public boolean isAbstract() {
			throw new UnsupportedOperationException();
		}

		@Override
		public Stream events() {
			return events.stream();
		}

		@Override
		public Stream entities() {
			return entities.stream();
		}

		@Override
		public Stream functions() {
			return functions.stream();
		}

		@Override
		public Stream actions() {
			return actions.stream();
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy