/*
 * VowlClassVisitor.java
 *
 */

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

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.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) {
		System.out.println("Not implemented VowlClassVisitor: " + c);
		logger.info("Not implemented for equivalents: " + c);
	}

	@Override
	public void visit(OWLObjectUnionOf ce) {
		System.out.println("Not implemented OWLObjectUnionOf: " + ce);
		logger.info("Not implemented for OWLObjectUnionOf: " + ce);
	}

	@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();

		vowlData.getClassForIri(baseClassIri).setComplement(complementIri);
		vowlData.getClassForIri(complementIri).setComplement(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.");
			}
		}
	}
}

@@ -1118,131 +1118,428 @@
 %0A%09%09S
-ystem.out.println(%22Not implemented OWLObjectUnionOf: %22 + ce);%0A%09%09logger.info(%22Not implemented for OWLObjectUnionOf: %22 + ce);
+et%3COWLClassExpression%3E operands = ce.getOperands();%0A%09%09AbstractNode node = vowlData.getClassForIri(referencedClass.getIRI());%0A%0A%09%09for (OWLClassExpression operand : operands) %7B%0A%09%09%09if (!operand.isAnonymous()) %7B%0A%09%09%09%09node.addElementToUnion(operand.asOWLClass().getIRI());%0A%09%09%09%09node.addAttribute(VowlAttribute.UNION);%0A%09%09%09%7D else %7B%0A%09%09%09%09// TODO Anonymous undefined behaviour%0A%09%09%09%09logger.info(%22Anonymous exists in unions.%22);%0A%09%09%09%7D%0A%09%09%7D
 %0A%09%7D%0A
@@ -2163,17 +2163,16 @@
 ands();%0A
-%0A
 %09%09Abstra

Implement object union of