NIHVIVO-3312 minor cleanup of WebappDaoFactory

This commit is contained in:
brianjlowe 2011-11-14 22:16:56 +00:00
parent 1982c96756
commit 0ecd02f04e
11 changed files with 168 additions and 281 deletions

View file

@ -50,10 +50,8 @@ public class VclassEditController extends BaseEditController {
VClass vcl = (VClass)vcwDao.getVClassByURI(request.getParameter("uri")); VClass vcl = (VClass)vcwDao.getVClassByURI(request.getParameter("uri"));
if (vcl == null) { if (vcl == null) {
if (VitroModelProperties.isRDFS(request.getFullWebappDaoFactory().getLanguageProfile()) vcl = request.getFullWebappDaoFactory()
&& ( (RDF.getURI()+"Resource").equals(request.getParameter("uri")))) { .getVClassDao().getTopConcept();
vcl = new VClass(RDF.getURI()+"Resource");
}
} }
request.setAttribute("VClass",vcl); request.setAttribute("VClass",vcl);

View file

@ -84,36 +84,15 @@ public class ClassHierarchyListingController extends BaseEditController {
} else if (startClassUri != null) { } else if (startClassUri != null) {
roots = new LinkedList<VClass>(); roots = new LinkedList<VClass>();
roots.add(vcDao.getVClassByURI(startClassUri)); roots.add(vcDao.getVClassByURI(startClassUri));
} else {
/* TODO: this needs more thinking */
if (false) { // (getWebappDaoFactory() instanceof WebappDaoFactoryJena) {
String topConceptURI = null;
int langProfile = ((WebappDaoFactoryJena) vrequest.getFullWebappDaoFactory()).getLanguageProfile();
if (langProfile==WebappDaoFactoryJena.OWL_CONST) {
topConceptURI = OWL.Thing.getURI();
} else if (langProfile==WebappDaoFactoryJena.RDFS_CONST) {
topConceptURI = RDFS.Resource.getURI();
}
VClass top = vcDao.getVClassByURI(topConceptURI);
if (top != null) {
roots = new LinkedList<VClass>();
roots.add(top);
} else { } else {
roots = vcDao.getRootClasses(); roots = vcDao.getRootClasses();
} }
} else {
roots = vcDao.getRootClasses();
}
}
// DEBUGGING // DEBUGGING
if (roots == null) { if (roots == null) {
roots = new LinkedList<VClass>(); roots = new LinkedList<VClass>();
if (VitroModelProperties.isOWL(vrequest.getFullWebappDaoFactory().getLanguageProfile())) { roots.add(vrequest.getFullWebappDaoFactory().getVClassDao()
roots.add(vcDao.getVClassByURI(OWL.Thing.getURI())); .getTopConcept());
} else if (VitroModelProperties.isRDFS(vrequest.getFullWebappDaoFactory().getLanguageProfile())) {
roots.add(new VClass(RDF.getURI()+"Resource"));
}
} }
Collections.sort(roots); Collections.sort(roots);

View file

@ -1,16 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.dao;
/**
* Created by IntelliJ IDEA.
* User: bdc34
* Date: Apr 18, 2007
* Time: 4:32:30 PM
* To change this template use File | Settings | File Templates.
*/
public interface FlagDao {
String getFlagNames(String table, String field);
public String convertNumericFlagToInsertString(int numeric,String column,String table);
public String convertNumericFlagToInsertString(int numeric,String flagColumns);
}

View file

@ -9,26 +9,32 @@ import java.util.Set;
public interface WebappDaoFactory { public interface WebappDaoFactory {
/** /**
* Retrieves a map containing arbitrary key-value pairs describing this WebappDaoFactory * Free any resources associated with this WebappDaoFactory
*/
public void close();
/**
* Retrieves a map containing arbitrary key-value pairs describing this
* WebappDaoFactory
*/ */
public Map<String,String> getProperties(); public Map<String,String> getProperties();
/** /**
* Checks a URI String for two things: well-formedness and uniqueness in the model. * Checks a URI String for two things: well-formedness and uniqueness in the
* Ill-formed strings or those matching URIs already in use will cause an error message to be returned. * model. Ill-formed strings or those matching URIs already in use will
* cause an error message to be returned.
* @return error message String if invalid; otherwise null * @return error message String if invalid; otherwise null
*/ */
public String checkURI(String uriStr); public String checkURI(String uriStr);
/** /**
* Checks a URI String for two things: well-formedness and, optionally, uniqueness in the model. * Checks a URI String for two things: well-formedness and, optionally,
* Ill-formed strings or those matching URIs already in use will cause an error message to be returned. * uniqueness in the model. Ill-formed strings or those matching URIs
* already in use will cause an error message to be returned.
* @return error message String if invalid; otherwise null * @return error message String if invalid; otherwise null
*/ */
public String checkURI(String uriStr, boolean checkUniqueness); public String checkURI(String uriStr, boolean checkUniqueness);
public int getLanguageProfile();
public String getDefaultNamespace(); public String getDefaultNamespace();
public Set<String> getNonuserNamespaces(); public Set<String> getNonuserNamespaces();
@ -36,33 +42,37 @@ public interface WebappDaoFactory {
public String[] getPreferredLanguages(); public String[] getPreferredLanguages();
/** /**
* BJL23 2008-05-20: Putting this here for lack of a more logical place. We need to build better support for the RDFS vocabulary into our API. * BJL23 2008-05-20: Putting this here for lack of a more logical place.
* Returns a list of the simple lexical form strings of the rdfs:comment values for a resource; empty list if none found. * We need to build better support for the RDFS vocabulary into our API.
* Returns a list of the simple lexical form strings of the rdfs:comment
* values for a resource; empty list if none found.
*/ */
public List<String> getCommentsForResource(String resourceURI); public List<String> getCommentsForResource(String resourceURI);
/** /**
* Copy this DAO factory to a new object associated with the specified user URI, or return the same factory if a user-aware version cannot be used. * Copy this DAO factory to a new object associated with the specified user
* URI, or return the same factory if a user-aware version cannot be used.
* @param userURI * @param userURI
* @return * @return
*/ */
public WebappDaoFactory getUserAwareDaoFactory(String userURI); public WebappDaoFactory getUserAwareDaoFactory(String userURI);
/** /**
* Return URI of user associated with this WebappDaoFactory, or null if not applicable. * Return URI of user associated with this WebappDaoFactory,
* or null if not applicable.
* @return * @return
*/ */
public String getUserURI(); public String getUserURI();
/* ======================== DAOs for ontology (TBox) manipulation ======================== */ /* =============== DAOs for ontology (TBox) manipulation =============== */
/** /**
* returns a Data Access Object for working with class subsumption axioms in the model * returns a Data Access Object for working with class subsumption axioms
*/ */
public Classes2ClassesDao getClasses2ClassesDao(); public Classes2ClassesDao getClasses2ClassesDao();
/** /**
* returns a Data Access Object for working with DataProperties in the model * returns a Data Access Object for working with DataProperties
*/ */
public DataPropertyDao getDataPropertyDao(); public DataPropertyDao getDataPropertyDao();
@ -72,42 +82,42 @@ public interface WebappDaoFactory {
public DatatypeDao getDatatypeDao(); public DatatypeDao getDatatypeDao();
/** /**
* returns a Data Access Object for working with ObjectProperties in the model * returns a Data Access Object for working with ObjectProperties
*/ */
public ObjectPropertyDao getObjectPropertyDao(); public ObjectPropertyDao getObjectPropertyDao();
/** /**
* returns a Data Access Object for working with Ontologies in the model * returns a Data Access Object for working with Ontologies
*/ */
public OntologyDao getOntologyDao(); public OntologyDao getOntologyDao();
/** /**
* returns a Data Access Object for working with ontology class objects in the model * returns a Data Access Object for working with ontology class objects
*/ */
public VClassDao getVClassDao(); public VClassDao getVClassDao();
/* ======================== DAOs for ABox manipulation ======================== */ /* ==================== DAOs for ABox manipulation ===================== */
/** /**
* returns a Data Access Object for working with DatatypePropertyStatements in the model * returns a Data Access Object for working with DatatypePropertyStatements
*/ */
public DataPropertyStatementDao getDataPropertyStatementDao(); public DataPropertyStatementDao getDataPropertyStatementDao();
/** /**
* returns a Data Access Object for working with Individuals in the model * returns a Data Access Object for working with Individuals
*/ */
public IndividualDao getIndividualDao(); public IndividualDao getIndividualDao();
/** /**
* returns a Data Access Object for working with ObjectPropertyStatements in the model * returns a Data Access Object for working with ObjectPropertyStatements
*/ */
public ObjectPropertyStatementDao getObjectPropertyStatementDao(); public ObjectPropertyStatementDao getObjectPropertyStatementDao();
public DisplayModelDao getDisplayModelDao(); public DisplayModelDao getDisplayModelDao();
/* ======================== DAOs for other objects ======================== */ /* ====================== DAOs for other objects ======================= */
public ApplicationDao getApplicationDao(); public ApplicationDao getApplicationDao();
@ -125,5 +135,4 @@ public interface WebappDaoFactory {
public MenuDao getMenuDao(); public MenuDao getMenuDao();
public void close();
} }

View file

@ -94,10 +94,6 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory {
return innerWebappDaoFactory.getUserAwareDaoFactory(userURI); return innerWebappDaoFactory.getUserAwareDaoFactory(userURI);
} }
public int getLanguageProfile() {
return innerWebappDaoFactory.getLanguageProfile();
}
public String getDefaultNamespace() { public String getDefaultNamespace() {
return innerWebappDaoFactory.getDefaultNamespace(); return innerWebappDaoFactory.getDefaultNamespace();
} }

View file

@ -888,22 +888,6 @@ public class JenaBaseDao extends JenaBaseDaoCon {
return PREFERRED_LANGUAGES[0]; return PREFERRED_LANGUAGES[0];
} }
protected Map<String,OntClass>getFlag2ValueMap() {
try {
return ((WebappDaoFactoryJena) this.webappDaoFactory).getFlag2ValueMap();
} catch (ClassCastException cce) {
return null;
}
}
protected Map<Resource,String>getFlag2ClassLabelMap() {
try {
return ((WebappDaoFactoryJena) this.webappDaoFactory).getFlag2ClassLabelMap();
} catch (ClassCastException cce) {
return null;
}
}
/** /**
* Checks a URI for validity. Jena models can store invalid URIs, but this causes RDF/XML output serialization to fail. * Checks a URI for validity. Jena models can store invalid URIs, but this causes RDF/XML output serialization to fail.
* @param uri * @param uri

View file

@ -1,36 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.dao.jena;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.dao.VitroModelProperties;
public class VitroJenaModel {
private String graphURI = null;
private OntModel jenaOntModel = null;
private VitroModelProperties vitroModelProperties = null;
public String getGraphURI() {
return graphURI;
}
public void setGraphURI(String graphURI) {
this.graphURI = graphURI;
}
public OntModel getJenaOntModel() {
return this.jenaOntModel;
}
public void setJenaOntModel(OntModel ontModel) {
this.jenaOntModel = ontModel;
}
public VitroModelProperties getVitroModelProperties() {
return this.vitroModelProperties;
}
public void setVitroModelProperties(VitroModelProperties vitroModelProperties) {
this.vitroModelProperties = vitroModelProperties;
}
}

View file

@ -1,19 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.dao.jena;
public interface VitroJenaModelSource {
public abstract VitroJenaModel getVitroJenaModel();
public abstract VitroJenaModel getVitroJenaModel(String namespace);
public abstract VitroJenaModel getMutableVitroJenaModel();
public abstract VitroJenaModel getMutableVitroJenaModel(String namespace);
public abstract VitroJenaModel getVitroAnnotationsJenaModel();
public abstract VitroJenaModel getVitroAnnotationsJenaModel(String namespace);
}

View file

@ -13,7 +13,6 @@ import java.util.Set;
import com.hp.hpl.jena.iri.IRI; import com.hp.hpl.jena.iri.IRI;
import com.hp.hpl.jena.iri.IRIFactory; import com.hp.hpl.jena.iri.IRIFactory;
import com.hp.hpl.jena.iri.Violation; import com.hp.hpl.jena.iri.Violation;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntResource; import com.hp.hpl.jena.ontology.OntResource;
@ -27,20 +26,18 @@ import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.util.iterator.ClosableIterator; import com.hp.hpl.jena.util.iterator.ClosableIterator;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
import edu.cornell.mannlib.vitro.webapp.dao.ApplicationDao; import edu.cornell.mannlib.vitro.webapp.dao.ApplicationDao;
import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao; import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao; import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayModelDao; import edu.cornell.mannlib.vitro.webapp.dao.DisplayModelDao;
import edu.cornell.mannlib.vitro.webapp.dao.FlagDao;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.LinksDao; import edu.cornell.mannlib.vitro.webapp.dao.LinksDao;
import edu.cornell.mannlib.vitro.webapp.dao.LinktypeDao; import edu.cornell.mannlib.vitro.webapp.dao.LinktypeDao;
@ -63,7 +60,6 @@ import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
public class WebappDaoFactoryJena implements WebappDaoFactory { public class WebappDaoFactoryJena implements WebappDaoFactory {
protected IndividualDao entityWebappDao; protected IndividualDao entityWebappDao;
protected FlagDao flagDao;
protected LinksDao linksDao; protected LinksDao linksDao;
protected LinktypeDao linktypeDao; protected LinktypeDao linktypeDao;
protected ApplicationDaoJena applicationDao; protected ApplicationDaoJena applicationDao;
@ -84,9 +80,6 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
protected String userURI; protected String userURI;
protected Map<String,OntClass> flag2ValueMap;
protected Map<Resource,String> flag2ClassLabelMap;
protected boolean INCLUDE_TOP_CONCEPT = false; protected boolean INCLUDE_TOP_CONCEPT = false;
protected boolean INCLUDE_BOTTOM_CONCEPT = false; protected boolean INCLUDE_BOTTOM_CONCEPT = false;
@ -94,9 +87,6 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
protected DatasetWrapperFactory dwf; protected DatasetWrapperFactory dwf;
// for temporary use to construct URIs for the things that still use integer IDs.
// As these objects get changed to support getURI(), this should become unnecessary.
/* **************** constructors **************** */ /* **************** constructors **************** */
public WebappDaoFactoryJena(WebappDaoFactoryJena base, String userURI) { public WebappDaoFactoryJena(WebappDaoFactoryJena base, String userURI) {
@ -105,8 +95,6 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
this.nonuserNamespaces = base.nonuserNamespaces; this.nonuserNamespaces = base.nonuserNamespaces;
this.preferredLanguages = base.preferredLanguages; this.preferredLanguages = base.preferredLanguages;
this.userURI = userURI; this.userURI = userURI;
this.flag2ValueMap = base.flag2ValueMap;
this.flag2ClassLabelMap = base.flag2ClassLabelMap;
this.dwf = base.dwf; this.dwf = base.dwf;
} }
@ -120,17 +108,6 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
this.ontModelSelector = ontModelSelector; this.ontModelSelector = ontModelSelector;
// BJL23 2009-04-27
// As I understand it, the the following setting should allow more
// relaxed use of .as() in Jena's polymorphic framework and avoid
// ClassCastExceptions deep in Jena when, for example, a resource
// used as a class is not explicitly typed as such. In reality,
// this setting seems to have dangerous consequences and causes
// bizarre other exceptions to be thrown in ways that make the model
// seem to behave even *more* strictly. Uncomment at your own risk:
// this.ontModel.setStrictMode(false);
if (defaultNamespace != null) { if (defaultNamespace != null) {
this.defaultNamespace = defaultNamespace; this.defaultNamespace = defaultNamespace;
} else { } else {
@ -151,17 +128,22 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
if (INCLUDE_TOP_CONCEPT) { if (INCLUDE_TOP_CONCEPT) {
Resource top = getTopConcept(); Resource top = getTopConcept();
if (top != null) { if (top != null) {
languageUniversalsModel.add(top, RDF.type, this.ontModelSelector.getTBoxModel().getProfile().CLASS()); languageUniversalsModel.add(top, RDF.type,
this.ontModelSelector.getTBoxModel().getProfile()
.CLASS());
} }
} }
if (INCLUDE_BOTTOM_CONCEPT) { if (INCLUDE_BOTTOM_CONCEPT) {
Resource bottom = getBottomConcept(); Resource bottom = getBottomConcept();
if (bottom != null) { if (bottom != null) {
languageUniversalsModel.add(bottom, RDF.type, this.ontModelSelector.getTBoxModel().getProfile().CLASS()); languageUniversalsModel.add(bottom, RDF.type,
this.ontModelSelector.getTBoxModel().getProfile()
.CLASS());
} }
} }
if (languageUniversalsModel.size()>0) { if (languageUniversalsModel.size()>0) {
this.ontModelSelector.getTBoxModel().addSubModel(languageUniversalsModel); this.ontModelSelector.getTBoxModel().addSubModel(
languageUniversalsModel);
} }
Model assertions = (baseOntModelSelector != null) Model assertions = (baseOntModelSelector != null)
@ -176,13 +158,13 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
} }
public static Dataset makeInMemoryDataset(Model assertions, Model inferences) { public static Dataset makeInMemoryDataset(Model assertions,
Model inferences) {
DataSource dataset = DatasetFactory.create(); DataSource dataset = DatasetFactory.create();
OntModel union = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel union = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
if (assertions != null) { if (assertions != null) {
dataset.addNamedModel(JenaDataSourceSetupBase.JENA_DB_MODEL, assertions); dataset.addNamedModel(
JenaDataSourceSetupBase.JENA_DB_MODEL, assertions);
union.addSubModel(assertions); union.addSubModel(assertions);
} }
if (inferences != null) { if (inferences != null) {
@ -208,28 +190,62 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
userURI); userURI);
} }
public WebappDaoFactoryJena(OntModelSelector ontModelSelector, String defaultNamespace, HashSet<String> nonuserNamespaces, String[] preferredLanguages){ public WebappDaoFactoryJena(OntModelSelector ontModelSelector,
this(ontModelSelector, defaultNamespace, nonuserNamespaces, preferredLanguages, null); String defaultNamespace,
HashSet<String> nonuserNamespaces,
String[] preferredLanguages) {
this(ontModelSelector,
defaultNamespace,
nonuserNamespaces,
preferredLanguages,
null);
} }
public WebappDaoFactoryJena(OntModelSelector ontModelSelector, OntModelSelector baseOntModelSelector, OntModelSelector inferenceOntModelSelector, String defaultNamespace, HashSet<String> nonuserNamespaces, String[] preferredLanguages){ public WebappDaoFactoryJena(OntModelSelector ontModelSelector,
this(ontModelSelector, baseOntModelSelector, inferenceOntModelSelector, defaultNamespace, nonuserNamespaces, preferredLanguages, null); OntModelSelector baseOntModelSelector,
OntModelSelector inferenceOntModelSelector,
String defaultNamespace,
HashSet<String> nonuserNamespaces,
String[] preferredLanguages){
this(ontModelSelector,
baseOntModelSelector,
inferenceOntModelSelector,
defaultNamespace,
nonuserNamespaces,
preferredLanguages,
null);
} }
public WebappDaoFactoryJena(OntModelSelector ontModelSelector) { public WebappDaoFactoryJena(OntModelSelector ontModelSelector) {
this(ontModelSelector, null, null, null, null, null); this(ontModelSelector, null, null, null, null, null);
} }
public WebappDaoFactoryJena(OntModel ontModel, String defaultNamespace, HashSet<String> nonuserNamespaces, String[] preferredLanguages, String userURI){ public WebappDaoFactoryJena(OntModel ontModel,
this(new SimpleOntModelSelector(ontModel), defaultNamespace, nonuserNamespaces, preferredLanguages, userURI); String defaultNamespace,
HashSet<String> nonuserNamespaces,
String[] preferredLanguages,
String userURI) {
this(new SimpleOntModelSelector(ontModel),
defaultNamespace,
nonuserNamespaces,
preferredLanguages,
userURI);
} }
public WebappDaoFactoryJena(OntModel ontModel, String defaultNamespace, HashSet<String> nonuserNamespaces, String[] preferredLanguages){ public WebappDaoFactoryJena(OntModel ontModel,
this(new SimpleOntModelSelector(ontModel), defaultNamespace, nonuserNamespaces, preferredLanguages, null); String defaultNamespace,
HashSet<String> nonuserNamespaces,
String[] preferredLanguages) {
this(new SimpleOntModelSelector(ontModel),
defaultNamespace,
nonuserNamespaces,
preferredLanguages,
null);
} }
public WebappDaoFactoryJena(OntModel ontModel) { public WebappDaoFactoryJena(OntModel ontModel) {
this(new SimpleOntModelSelector(ontModel), null, null, null, null, null); this(new SimpleOntModelSelector(
ontModel), null, null, null, null, null);
} }
public OntModelSelector getOntModelSelector() { public OntModelSelector getOntModelSelector() {
@ -241,13 +257,15 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
} }
/** /**
* Return the current language profile's Top concept as a Jena resource, or null if not applicable. * Return the current language profile's Top concept as a Jena resource,
* The special case is RDFS, where we use rdfs:Resource as the analog of Top, rather than returning null. * or null if not applicable. The special case is RDFS, where we use
* rdfs:Resource as the analog of Top, rather than returning null.
* @return * @return
*/ */
public Resource getTopConcept() { public Resource getTopConcept() {
Resource top = null; Resource top = null;
if (this.ontModelSelector.getTBoxModel().getProfile().NAMESPACE().equals(RDFS.getURI())) { if (this.ontModelSelector.getTBoxModel().getProfile().NAMESPACE()
.equals(RDFS.getURI())) {
top = RDFS.Resource; top = RDFS.Resource;
} else { } else {
top = this.ontModelSelector.getTBoxModel().getProfile().THING(); top = this.ontModelSelector.getTBoxModel().getProfile().THING();
@ -256,7 +274,8 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
} }
/** /**
* Return the current language profile's Bottom concept as a Jena resource, or null if not applicable. * Return the current language profile's Bottom concept as a Jena resource,
* or null if not applicable.
* @return * @return
*/ */
public Resource getBottomConcept() { public Resource getBottomConcept() {
@ -269,11 +288,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
private void initNonuserNamespaces() { private void initNonuserNamespaces() {
nonuserNamespaces = new HashSet<String>(); nonuserNamespaces = new HashSet<String>();
//nonuserNamespaces.add(VitroVocabulary.RDF);
//nonuserNamespaces.add(VitroVocabulary.RDFS);
//nonuserNamespaces.add(VitroVocabulary.OWL);
nonuserNamespaces.add(VitroVocabulary.vitroURI); nonuserNamespaces.add(VitroVocabulary.vitroURI);
nonuserNamespaces.add("http://lowe.mannlib.cornell.edu/ns/vitro0.1/vitro.owl#"); // obsolete Vitro URI
} }
private void initPreferredLanguages() { private void initPreferredLanguages() {
@ -297,19 +312,22 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
uriStr = (uriStr == null) ? " " : uriStr; uriStr = (uriStr == null) ? " " : uriStr;
boolean validURI = true; boolean validURI = true;
String errorMsg = ""; String errorMsg = "";
String duplicateMsg = "URI is already in use. Please enter another URI. "; String duplicateMsg = "URI is already in use. " +
"Please enter another URI. ";
IRIFactory factory = IRIFactory.jenaImplementation(); IRIFactory factory = IRIFactory.jenaImplementation();
IRI iri = factory.create( uriStr ); IRI iri = factory.create( uriStr );
if (iri.hasViolation(false) ) { if (iri.hasViolation(false) ) {
validURI = false; validURI = false;
errorMsg += ((Violation)iri.violations(false).next()).getShortMessage()+" "; errorMsg += ((Violation)iri.violations(false).next())
.getShortMessage() + " ";
} else if (checkUniqueness) { } else if (checkUniqueness) {
OntModel ontModel = ontModelSelector.getFullModel(); OntModel ontModel = ontModelSelector.getFullModel();
ontModel.enterCriticalSection(Lock.READ); ontModel.enterCriticalSection(Lock.READ);
try { try {
Resource newURIAsRes = ResourceFactory.createResource(uriStr); Resource newURIAsRes = ResourceFactory.createResource(uriStr);
Property newURIAsProp = ResourceFactory.createProperty(uriStr); Property newURIAsProp = ResourceFactory.createProperty(uriStr);
ClosableIterator closeIt = ontModel.listStatements(newURIAsRes, null, (RDFNode)null); StmtIterator closeIt = ontModel.listStatements(
newURIAsRes, null, (RDFNode)null);
if (closeIt.hasNext()) { if (closeIt.hasNext()) {
validURI = false; validURI = false;
errorMsg+="Not a valid URI. Please enter another URI. "; errorMsg+="Not a valid URI. Please enter another URI. ";
@ -323,7 +341,8 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
} }
} }
if (validURI) { if (validURI) {
closeIt = ontModel.listStatements(null, newURIAsProp, (RDFNode)null); closeIt = ontModel.listStatements(
null, newURIAsProp, (RDFNode)null);
if (closeIt.hasNext()) { if (closeIt.hasNext()) {
validURI = false; validURI = false;
errorMsg+=duplicateMsg; errorMsg+=duplicateMsg;
@ -337,7 +356,6 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
} }
public WebappDaoFactory getUserAwareDaoFactory(String userURI) { public WebappDaoFactory getUserAwareDaoFactory(String userURI) {
// TODO: put the user-aware factories in a hashmap so we don't keep re-creating them
return new WebappDaoFactoryJena(this, userURI); return new WebappDaoFactoryJena(this, userURI);
} }
@ -351,20 +369,6 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
return defaultNamespace; return defaultNamespace;
} }
public static int OWL_CONST = 202;
public static int RDFS_CONST = 100;
public int getLanguageProfile() {
OntModel ontModel = ontModelSelector.getTBoxModel();
if (ontModel.getProfile().NAMESPACE().equals(OWL.NAMESPACE.getURI())) {
return OWL_CONST;
} else if (ontModel.getProfile().NAMESPACE().equals(RDFS.getURI())) {
return RDFS_CONST;
} else {
return -1;
}
}
public String[] getPreferredLanguages() { public String[] getPreferredLanguages() {
return this.preferredLanguages; return this.preferredLanguages;
} }
@ -392,9 +396,9 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
try { try {
OntResource res = ontModel.getOntResource(resourceURI); OntResource res = ontModel.getOntResource(resourceURI);
if (res != null) { if (res != null) {
ClosableIterator closeIt = res.listComments(null); ClosableIterator<RDFNode> closeIt = res.listComments(null);
try { try {
for (Iterator commIt = closeIt; commIt.hasNext();) { for(Iterator<RDFNode> commIt = closeIt; commIt.hasNext();) {
Literal lit = (Literal) commIt.next(); Literal lit = (Literal) commIt.next();
commentList.add(lit.getLexicalForm()); commentList.add(lit.getLexicalForm());
} }
@ -532,14 +536,6 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
return jenaBaseDao; return jenaBaseDao;
} }
public Map<String,OntClass> getFlag2ValueMap() {
return this.flag2ValueMap;
}
public Map<Resource,String> getFlag2ClassLabelMap() {
return this.flag2ClassLabelMap;
}
@Override @Override
public PageDao getPageDao() { public PageDao getPageDao() {
if( pageDao == null ) if( pageDao == null )
@ -566,62 +562,58 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
} }
} }
//Method for creating a copy - does not pass the same object /**
* Method for creating a copy - does not pass the same object
* @param base
*/
public WebappDaoFactoryJena (WebappDaoFactoryJena base) { public WebappDaoFactoryJena (WebappDaoFactoryJena base) {
//Not sure if selector somehow has greater longevity so making a copy instead of reference // Not sure if selector somehow has greater longevity so
// making a copy instead of reference.
if(base.ontModelSelector instanceof OntModelSelectorImpl) { if(base.ontModelSelector instanceof OntModelSelectorImpl) {
OntModelSelectorImpl selector = new OntModelSelectorImpl(); OntModelSelectorImpl selector = new OntModelSelectorImpl();
selector.setABoxModel(base.ontModelSelector.getABoxModel()); selector.setABoxModel(base.ontModelSelector.getABoxModel());
selector.setApplicationMetadataModel(base.ontModelSelector.getApplicationMetadataModel()); selector.setApplicationMetadataModel(
base.ontModelSelector.getApplicationMetadataModel());
selector.setDisplayModel(base.ontModelSelector.getDisplayModel()); selector.setDisplayModel(base.ontModelSelector.getDisplayModel());
selector.setFullModel(base.ontModelSelector.getFullModel()); selector.setFullModel(base.ontModelSelector.getFullModel());
selector.setTBoxModel(base.ontModelSelector.getTBoxModel()); selector.setTBoxModel(base.ontModelSelector.getTBoxModel());
selector.setUserAccountsModel(base.ontModelSelector.getUserAccountsModel()); selector.setUserAccountsModel(
base.ontModelSelector.getUserAccountsModel());
this.ontModelSelector = selector; this.ontModelSelector = selector;
} else if(base.ontModelSelector instanceof SimpleOntModelSelector) { } else if(base.ontModelSelector instanceof SimpleOntModelSelector) {
SimpleOntModelSelector selector = new SimpleOntModelSelector(); SimpleOntModelSelector selector = new SimpleOntModelSelector();
selector.setABoxModel(base.ontModelSelector.getABoxModel()); selector.setABoxModel(base.ontModelSelector.getABoxModel());
selector.setApplicationMetadataModel(base.ontModelSelector.getApplicationMetadataModel()); selector.setApplicationMetadataModel(
base.ontModelSelector.getApplicationMetadataModel());
selector.setDisplayModel(base.ontModelSelector.getDisplayModel()); selector.setDisplayModel(base.ontModelSelector.getDisplayModel());
selector.setFullModel(base.ontModelSelector.getFullModel()); selector.setFullModel(base.ontModelSelector.getFullModel());
selector.setTBoxModel(base.ontModelSelector.getTBoxModel()); selector.setTBoxModel(base.ontModelSelector.getTBoxModel());
selector.setUserAccountsModel(base.ontModelSelector.getUserAccountsModel()); selector.setUserAccountsModel(
base.ontModelSelector.getUserAccountsModel());
this.ontModelSelector = selector; this.ontModelSelector = selector;
} else { } else {
//Not sure what this is but will set to equivalence here //Not sure what this is but will set to equivalence here
this.ontModelSelector = base.ontModelSelector; this.ontModelSelector = base.ontModelSelector;
} }
this.defaultNamespace = base.defaultNamespace; this.defaultNamespace = base.defaultNamespace;
this.nonuserNamespaces = base.nonuserNamespaces; this.nonuserNamespaces = base.nonuserNamespaces;
this.preferredLanguages = base.preferredLanguages; this.preferredLanguages = base.preferredLanguages;
this.userURI = base.userURI; this.userURI = base.userURI;
if(base.flag2ValueMap != null) {
this.flag2ValueMap = new HashMap<String,OntClass>();
this.flag2ValueMap.putAll(base.flag2ValueMap);
} else {
this.flag2ValueMap = null;
}
if(base.flag2ClassLabelMap != null) {
this.flag2ClassLabelMap = new HashMap<Resource, String>();
this.flag2ClassLabelMap.putAll(base.flag2ClassLabelMap);
} else {
this.flag2ClassLabelMap = null;
}
this.dwf = base.dwf; this.dwf = base.dwf;
} }
/** /**
* Method for using special model for webapp dao factory, such as display model. * Method for using a special model, such as the display model, with the
* The goal here is to modify this WebappDaoFactory so that it is using the * WebappDaoFactory. The goal here is to modify this WebappDaoFactory so
* specialModel, specialTboxModel and the specialDisplayModel for individual * that it is using specialModel, specialTboxModel and specialDisplayModel
* editing. * for individual editing.
* *
* DAOs related to the application configuration, user accounts, and namespaces * DAOs related to the application configuration and user accounts
* should remain unchanged. * should remain unchanged.
*/ */
public void setSpecialDataModel(OntModel specialModel, OntModel specialTboxModel, OntModel specialDisplayModel) { public void setSpecialDataModel(OntModel specialModel,
OntModel specialTboxModel,
OntModel specialDisplayModel) {
if( specialModel == null ) if( specialModel == null )
throw new IllegalStateException("specialModel must not be null"); throw new IllegalStateException("specialModel must not be null");
@ -629,22 +621,26 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
OntModelSelector originalSelector = this.getOntModelSelector(); OntModelSelector originalSelector = this.getOntModelSelector();
// Set up model selector for this special WDF // Set up model selector for this special WDF
//The selector is used by the object property DAO, therefore should be set up even though we // The selector is used by the object property DAO, therefore should be
//use the new webapp dao factory object to generate portions to overwrite the regular webapp dao factory // set up even though we use the new webapp dao factory object to
// generate portions to overwrite the regular webapp dao factory.
//The WDF expects the full model in the OntModelSelect that has //The WDF expects the full model in the OntModelSelect that has
//both the ABox and TBox. This is used to run SPARQL queries against. //both the ABox and TBox. This is used to run SPARQL queries against.
OntModel unionModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); OntModel unionModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM);
unionModel.addSubModel(specialModel); unionModel.addSubModel(specialModel);
OntModelSelectorImpl specialSelector = new OntModelSelectorImpl(); OntModelSelectorImpl specialSelector = new OntModelSelectorImpl();
specialSelector.setFullModel(unionModel); specialSelector.setFullModel(unionModel);
//Keeping original application metadata model and adding special model // Keeping original application metadata model and adding special model.
//adding both allows us to prevent errors in ApplicationDao which may depend on // Adding both allows us to prevent errors in ApplicationDao which may
//a specific individual from the regular application metadata model to pick theme // depend on a specific individual from the regular application metadata
//Adding the new model would take care of special situations where the switch model may // model to pick the theme. Adding the new model would take care of
//contain important information // special situations where the switch model may contain important
OntModel newApplicationModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); // information.
OntModel newApplicationModel = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM);
newApplicationModel.add(specialModel); newApplicationModel.add(specialModel);
newApplicationModel.add(originalSelector.getApplicationMetadataModel()); newApplicationModel.add(originalSelector.getApplicationMetadataModel());
specialSelector.setApplicationMetadataModel(newApplicationModel); specialSelector.setApplicationMetadataModel(newApplicationModel);
@ -655,7 +651,8 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
} else { } else {
OntModel selectorDisplayModel = originalSelector.getDisplayModel(); OntModel selectorDisplayModel = originalSelector.getDisplayModel();
if(selectorDisplayModel != null) { if(selectorDisplayModel != null) {
specialSelector.setDisplayModel(originalSelector.getDisplayModel()); specialSelector.setDisplayModel(
originalSelector.getDisplayModel());
} }
} }
if(specialTboxModel != null) { if(specialTboxModel != null) {
@ -670,16 +667,19 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
specialSelector.setABoxModel(specialModel); specialSelector.setABoxModel(specialModel);
specialSelector.setUserAccountsModel(specialModel); specialSelector.setUserAccountsModel(specialModel);
//although we're only use part of the new wadf and copy over below, the object property dao // Although we're only using part of the new wadf and copy over below,
//utilizes methods that will employ the display model returned from the simple ontmodel selector // the object property dao utilizes methods that will employ the display
//so if the object property dao is to be copied over we need to ensure we have the correct display model // model returned from the simple ontmodel selector, so if the object
//and tbox model // property dao is to be copied over we need to ensure we have the
WebappDaoFactoryJena specialWadfj = new WebappDaoFactoryJena(specialSelector); // correct display model and tbox model.
WebappDaoFactoryJena specialWadfj = new WebappDaoFactoryJena(
specialSelector);
entityWebappDao = specialWadfj.getIndividualDao(); entityWebappDao = specialWadfj.getIndividualDao();
vClassGroupDao = specialWadfj.getVClassGroupDao(); vClassGroupDao = specialWadfj.getVClassGroupDao();
// To allow for testing, add a property group, this will allow // To allow for testing, add a property group, this will allow
//the unassigned group method section to be executed and main Image to be assigned to that group // the unassigned group method section to be executed and main Image to
//otherwise the dummy group does not allow for the unassigned group to be executed // be assigned to that group. Otherwise, the dummy group does not allow
// for the unassigned group to be executed.
propertyGroupDao = specialWadfj.getPropertyGroupDao(); propertyGroupDao = specialWadfj.getPropertyGroupDao();
objectPropertyDao = specialWadfj.getObjectPropertyDao(); objectPropertyDao = specialWadfj.getObjectPropertyDao();
objectPropertyStatementDao = specialWadfj.getObjectPropertyStatementDao(); objectPropertyStatementDao = specialWadfj.getObjectPropertyStatementDao();

View file

@ -86,8 +86,6 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
this.nonuserNamespaces = base.nonuserNamespaces; this.nonuserNamespaces = base.nonuserNamespaces;
this.preferredLanguages = base.preferredLanguages; this.preferredLanguages = base.preferredLanguages;
this.userURI = userURI; this.userURI = userURI;
this.flag2ValueMap = base.flag2ValueMap;
this.flag2ClassLabelMap = base.flag2ClassLabelMap;
this.dwf = base.dwf; this.dwf = base.dwf;
} }

View file

@ -104,12 +104,6 @@ public class WebappDaoFactoryStub implements WebappDaoFactory {
"WebappDaoFactory.checkURI() not implemented."); "WebappDaoFactory.checkURI() not implemented.");
} }
@Override
public int getLanguageProfile() {
throw new RuntimeException(
"WebappDaoFactory.getLanguageProfile() not implemented.");
}
@Override @Override
public String getDefaultNamespace() { public String getDefaultNamespace() {
throw new RuntimeException( throw new RuntimeException(