package de.fabiankeller.palladio.builder.repository.impl;

import de.fabiankeller.palladio.builder.repository.ComponentBuilder;
import de.fabiankeller.palladio.builder.repository.InterfaceBuilder;
import de.fabiankeller.palladio.builder.repository.RepositoryBuilder;
import org.palladiosimulator.pcm.repository.BasicComponent;
import org.palladiosimulator.pcm.repository.OperationProvidedRole;
import org.palladiosimulator.pcm.repository.OperationRequiredRole;
import org.palladiosimulator.pcm.repository.RepositoryFactory;


public class ComponentBuilderImpl extends AbstractHierarchicalBuilder<ComponentBuilder, BasicComponent, RepositoryBuilder> implements ComponentBuilder {


    ComponentBuilderImpl(final RepositoryBuilder belongsTo) {
        super(belongsTo);
    }

    @Override
    protected BasicComponent newEModel() {
        return RepositoryFactory.eINSTANCE.createBasicComponent();
    }

    @Override
    protected void registerParent() {
        this.eModel.setRepository__RepositoryComponent(this.belongsTo.getReference());
    }


    @Override
    public ComponentBuilder provides(final InterfaceBuilder iface) {
        // create model
        final OperationProvidedRole provided = RepositoryFactory.eINSTANCE.createOperationProvidedRole();
        provided.setProvidedInterface__OperationProvidedRole(iface.getReference());

        // link model
        this.eModel.getProvidedRoles_InterfaceProvidingEntity().add(provided);

        return this;
    }

    @Override
    public ComponentBuilder requires(final InterfaceBuilder iface) {
        // create model
        final OperationRequiredRole provided = RepositoryFactory.eINSTANCE.createOperationRequiredRole();
        provided.setRequiredInterface__OperationRequiredRole(iface.getReference());

        // link model
        this.eModel.getRequiredRoles_InterfaceRequiringEntity().add(provided);

        return this;
    }
}

@@ -1252,32 +1252,164 @@
 ProvidedRole();%0A
+        provided.setEntityName(String.format(%22%25s_provides_%25s%22, this.eModel.getEntityName(), iface.getReference().getEntityName()));%0A
         provided
@@ -1746,30 +1746,30 @@
 equiredRole 
-provid
+requir
 ed = Reposit
@@ -1824,30 +1824,162 @@
 ();%0A        
-provid
+required.setEntityName(String.format(%22%25s_requires_%25s%22, this.eModel.getEntityName(), iface.getReference().getEntityName()));%0A        requir
 ed.setRequir
@@ -2119,38 +2119,38 @@
 ingEntity().add(
-provid
+requir
 ed);%0A%0A        re

set default entity name for interfaces required/provided by components