package fr.vergne.data;

import java.util.Date;

public class ConceptFactory {

	private final ConceptContainer container;
	private final Concept creator;
	private boolean decorationsActivated;

	public ConceptFactory(ConceptContainer container, Concept creator) {
		this.creator = creator;
		this.container = container;
	}

	public void setDecorationsActivated(boolean decorations) {
		this.decorationsActivated = decorations;
	}

	public boolean getDecorationsActivated() {
		return decorationsActivated;
	}

	private void initConcept(Concept concept) {
		container.addConcept(concept);
		if (getDecorationsActivated()) {
			ConceptFactory systemFactory = container.getSystemConceptFactory();
			boolean old = systemFactory.getDecorationsActivated();
			systemFactory.setDecorationsActivated(false);
			systemFactory.makeWasCreatedByRelation(concept, creator);
			systemFactory.makeWasCreatedOnRelation(concept, new Date());
			systemFactory.setDecorationsActivated(old);
		} else {
			// do not put decorations
		}
	}

	public Property makeProperty() {
		Property property = new Property();
		initConcept(property);
		return property;
	}

	public Property makeProperty(Object representation) {
		Property property = makeProperty();
		property.setRepresentation(representation);
		return property;
	}

	public Relation makeRelation(Concept start, Concept end) {
		Relation relation = new Relation();
		relation.setStart(start);
		relation.setEnd(end);
		initConcept(relation);
		return relation;
	}

	public Relation makeRelation(Concept start, Concept end,
			Object representation) {
		Relation relation = makeRelation(start, end);
		relation.setRepresentation(representation);
		return relation;
	}

	public Relation makeWasCreatedByRelation(Concept created, Concept creator) {
		Relation relation = makeRelation(created, creator);
		relation.setRepresentation("was created by");
		return relation;
	}

	public Relation makeWasCreatedOnRelation(Concept created, Date date) {
		Relation relation = makeRelation(created, makeProperty(date));
		relation.setRepresentation("was created on");
		return relation;
	}

	public Relation makeIsInstanceOfRelation(Concept instance, Concept type) {
		Relation relation = makeRelation(instance, type);
		relation.setRepresentation("is instance of");
		return relation;
	}
}

@@ -1778,35 +1778,22 @@
 or) %7B%0A%09%09
-Relation relation =
+return
  makeRel
@@ -1818,40 +1818,10 @@
 ator
-);%0A%09%09relation.setRepresentation(
+, 
 %22was
@@ -1835,35 +1835,16 @@
 d by%22);%0A
-%09%09return relation;%0A
 %09%7D%0A%0A%09pub
@@ -1913,35 +1913,22 @@
 te) %7B%0A%09%09
-Relation relation =
+return
  makeRel
@@ -1964,40 +1964,10 @@
 ate)
-);%0A%09%09relation.setRepresentation(
+, 
 %22was
@@ -1981,35 +1981,16 @@
 d on%22);%0A
-%09%09return relation;%0A
 %09%7D%0A%0A%09pub
@@ -2063,35 +2063,22 @@
 pe) %7B%0A%09%09
-Relation relation =
+return
  makeRel
@@ -2101,76 +2101,27 @@
 type
-);%0A%09%09relation.setRepresentation(%22is instance of%22);%0A%09%09return relation
+, %22is instance of%22)
 ;%0A%09%7D

Simplify methods.