/*
 * VowlClassVisitor.java
 *
 */

package de.uni_stuttgart.vis.vowl.owl2vowl.parser.vowl.classes;

import de.uni_stuttgart.vis.vowl.owl2vowl.constants.VowlAttribute;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.data.VowlData;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.nodes.AbstractNode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.util.OWLClassExpressionVisitorAdapter;

import java.util.Set;

/**
 *
 */
public class VowlClassVisitor extends OWLClassExpressionVisitorAdapter {
	private final VowlData vowlData;
	private final OWLClass referencedClass;
	Logger logger = LogManager.getLogger(VowlClassVisitor.class);

	public VowlClassVisitor(VowlData vowlData, OWLClass referencedClass) {
		this.vowlData = vowlData;
		this.referencedClass = referencedClass;
	}

	@Override
	protected void handleDefault(OWLClassExpression c) {
		logger.info("Not implemented for equivalents: " + c);
	}

	@Override
	public void visit(OWLObjectUnionOf ce) {
		Set<OWLClassExpression> operands = ce.getOperands();
		AbstractNode node = vowlData.getClassForIri(referencedClass.getIRI());

		for (OWLClassExpression operand : operands) {
			if (!operand.isAnonymous()) {
				node.addElementToUnion(operand.asOWLClass().getIRI());
				node.addAttribute(VowlAttribute.UNION);
			} else {
				// TODO Anonymous undefined behaviour
				logger.info("Anonymous exists in unions.");
			}
		}
	}

	@Override
	public void visit(OWLObjectComplementOf ce) {
		if (ce.getOperand().isAnonymous()) {
			logger.info("Anonymous operand in object complement of.");
			return;
		}

		IRI baseClassIri = ce.getOperand().asOWLClass().getIRI();
		IRI complementIri = referencedClass.getIRI();

		// TODO where to set the complement?
		//vowlData.getClassForIri(baseClassIri).addComplement(complementIri);
		vowlData.getClassForIri(complementIri).addComplement(baseClassIri);
		vowlData.getClassForIri(complementIri).addAttribute(VowlAttribute.COMPLEMENT);
	}

	@Override
	public void visit(OWLObjectIntersectionOf ce) {
		Set<OWLClassExpression> operands = ce.getOperands();
		AbstractNode node = vowlData.getClassForIri(referencedClass.getIRI());

		for (OWLClassExpression operand : operands) {
			if (!operand.isAnonymous()) {
				node.addElementToIntersection(operand.asOWLClass().getIRI());
				node.addAttribute(VowlAttribute.INTERSECTION);
			} else {
				// TODO Anonymous undefined behaviour
				logger.info("Anonymous exists in intersections.");
			}
		}
	}
}

@@ -301,16 +301,102 @@
 ctNode;%0A
+import de.uni_stuttgart.vis.vowl.owl2vowl.model.entities.nodes.classes.AbstractClass;%0A
 import o
@@ -580,16 +580,49 @@
 apter;%0A%0A
+import javax.annotation.Nonnull;%0A
 import j
@@ -2668,11 +2668,537 @@
 %7D%0A%09%09%7D%0A%09%7D
+%0A%0A%09@Override%0A%09public void visit(OWLObjectOneOf ce) %7B%0A%09%09AbstractClass oneOfClass = vowlData.getClassForIri(referencedClass.getIRI());%0A%09%09ce.getIndividuals().forEach(individual -%3E individual.accept(new OWLIndividualVisitor() %7B%0A%09%09%09@Override%0A%09%09%09public void visit(@Nonnull OWLNamedIndividual owlNamedIndividual) %7B%0A%09%09%09%09oneOfClass.addIndividual(owlNamedIndividual.getIRI());%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public void visit(@Nonnull OWLAnonymousIndividual owlAnonymousIndividual) %7B%0A%09%09%09%09// TODO anonymous behaviour of individuals%0A%09%09%09%7D%0A%09%09%7D));%0A%09%7D
 %0A%7D%0A

Implement OWLObjectOneOf behaviour.