package org.arachb.owlbuilder.lib;

import java.sql.SQLException;

import org.arachb.arachadmin.PublicationBean;
import org.arachb.owlbuilder.Owlbuilder;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLObject;
import org.semanticweb.owlapi.model.OWLOntologyManager;

public class Publication implements GeneratingEntity {
	
	
	private final PublicationBean bean;

	private String generatedLabel;
	


	public Publication(PublicationBean b){
		bean = b;
        generatedLabel = generateLabel();
	}



	public boolean hasGeneratedLabel(){
		return (generatedLabel != null);
	}
	
	public String getGeneratedLabel(){
		return generatedLabel;
	}
	
    //generate a label; this should gradually get smarter
	private String generateLabel(){
		StringBuilder b = new StringBuilder(100);
        b.append(bean.getAuthorList());
        b.append(' ');
        b.append(bean.getPublicationYear());
		return b.toString();
	}



	@Override
	public OWLObject generateOWL(Owlbuilder builder) throws SQLException {
		final OWLOntologyManager manager = builder.getOntologyManager();
		final OWLDataFactory factory = builder.getDataFactory();
		final OWLClass pubAboutInvestigationClass = 
				factory.getOWLClass(Vocabulary.pubAboutInvestigation);
		IRI publication_id = IRI.create(bean.checkIRIString(builder.getIRIManager()));
		assert(publication_id != null);
		OWLIndividual pub_ind = factory.getOWLNamedIndividual(publication_id);
		OWLClassAssertionAxiom classAssertion = 
				factory.getOWLClassAssertionAxiom(pubAboutInvestigationClass, pub_ind); 
		manager.addAxiom(builder.getTarget(), classAssertion);
		if (hasGeneratedLabel()){
			OWLAnnotation labelAnno = factory.getOWLAnnotation(factory.getRDFSLabel(),
					factory.getOWLLiteral(getGeneratedLabel()));
			OWLAxiom ax = factory.getOWLAnnotationAssertionAxiom(publication_id, labelAnno);
			// Add the axiom to the ontology
			manager.addAxiom(builder.getTarget(),ax);
		}	
		return pub_ind;
	}
	
	


	
	
	

	
	
}

@@ -45,24 +45,42 @@
 ava.
-sql.SQLException
+util.HashMap;%0Aimport java.util.Map
 ;%0A%0Ai
@@ -745,19 +745,16 @@
 dLabel;%0A
-%09%0A%0A
 %0A%09public
@@ -1263,81 +1263,403 @@
 %09%7D%0A%0A
-%0A%0A%09@Override%0A%09public OWLObject generateOWL(Owlbuilder builder) throws SQL
+%09final private static Map%3CString,OWLObject%3E defaultElementMap = new HashMap%3CString,OWLObject%3E();%0A%0A%09@Override%0A%09public OWLObject generateOWL(Owlbuilder builder) throws Exception %7B%0A%09%09OWLObject result = generateOWL(builder, defaultElementMap);%0A%09%09defaultElementMap.clear();%0A%09%09return result;%0A%09%7D%0A%0A%0A%09@Override%0A%09public OWLObject generateOWL(Owlbuilder builder, Map%3CString, OWLObject%3E elements)%0A%09%09%09throws 
 Exce
@@ -2614,23 +2614,7 @@
 %0A%09%7D%0A
-%09%0A%09%0A%0A%0A%09%0A%09%0A%09%0A%0A%09%0A%09
 %0A%7D%0A

update generation methods