diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java index fc89134e7..4a832d784 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java @@ -115,10 +115,6 @@ public class DisplayVocabulary { public static final String USE_TBOX_MODEL_PARAM = "useThisTboxModel"; public static final String USE_DISPLAY_MODEL_PARAM = "useThisDisplayModel"; - //Attribute values used to store display tbox/display display model in servlet context - public static final String CONTEXT_DISPLAY_TBOX = "displayOntModelTBOX"; - public static final String CONTEXT_DISPLAY_DISPLAY = "displayOntModelDisplayModel"; - //URL for menu management public static final String PROCESS_MENU_MANAGEMENT_URL = "/menuManagementEdit"; public static final String REORDER_MENU_URL = PROCESS_MENU_MANAGEMENT_URL + "?cmd=Reorder&" + SWITCH_TO_DISPLAY_MODEL + "=true"; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java index 68d89d310..51bd6b8eb 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java @@ -18,7 +18,43 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector; /** * Hierarchical storage for models. TODO + * + * Could this be extended? Could it be used to replace or implement these + * methods? + * + *
+ * VitroRequest.getAssertionsWebappDaoFactory() + * VitroRequest.getDeductionsWebappDaoFactory() + * VitroRequest.getFullWebappDaoFactory() + * VitroRequest.getRDFService() + * VitroRequest.getUnfilteredRDFService() + * VitroRequest.getWebappDaoFactory() + * VitroRequest.getWriteModel() + * VitroRequest.getJenaOntModel() + * VitroRequest.setJenaOntModel() + * OntModelSelector.getAboxModel + * OntModelSelector.getApplicationMetadataModel() + * OntModelSelector.getFullModel() + * OntModelSelector.getTBoxModel() + * OntModelSelector.getTBoxModel(ontologyURI) + * OntModelSelector.getUserAccountsModel() + * VitroModelSource.getModel(URL) + * VitroModelSource.getModel(URL, loadIfAbsent) + * VitroModelSource.openModel(name) + * VitroModelSource.openModelIfPresent(string) + * ServletContext.getAttribute("assertionsWebappDaoFactory") + * ServletContext.getAttribute("baseOntModelSelector") + * ServletContext.getAttribute("jenaPersistentOntModel") + * ServletContext.getAttribute("pelletOntModel") + * ServletContext.getAttribute("webappDaoFactory") + * VitroJenaModelMaker + * VitroJenaSpecialModelMaker + * JenaDataSourceSetupBase.getApplicationDataSource(ctx) + * JenaDataSourceSetupBase.getStartupDataset() + * HttpSession.getAttribute("jenaAuditModel") + **/ + public class ModelAccess { private static final Log log = LogFactory.getLog(ModelAccess.class); @@ -188,6 +224,12 @@ public class ModelAccess { // Helper classes // ---------------------------------------------------------------------- + /** + * This OntModelSelector doesn't actually hold any OntModels. Instead, it + * links back to the ModelAccess that it was created from. So, if you change + * a model on the ModelAccess, it will change on the OntModelSelector also. + * Even if the OntModelSelector was created first. + */ private static class FacadeOntModelSelector implements OntModelSelector { private final ModelAccess parent; private final ModelID aboxID; @@ -238,49 +280,4 @@ public class ModelAccess { } } - // public OntModel getDisplayTboxOntModel() { - // throw new RuntimeException( - // "ModelAccess.getDisplayTboxOntModel not implemented."); - // } - // - // public OntModel getDisplayModelDisplayOntModel() { - // throw new RuntimeException( - // "ModelAccess.getDisplayModelDisplayOntModel not implemented."); - // } - // - - /** - *
- * VitroRequest.getAssertionsWebappDaoFactory() - * VitroRequest.getDeductionsWebappDaoFactory() - * VitroRequest.getFullWebappDaoFactory() - * VitroRequest.getRDFService() - * VitroRequest.getUnfilteredRDFService() - * VitroRequest.getWebappDaoFactory() - * VitroRequest.getWriteModel() - * VitroRequest.getJenaOntModel() - * VitroRequest.setJenaOntModel() - * OntModelSelector.getAboxModel - * OntModelSelector.getApplicationMetadataModel() - * OntModelSelector.getFullModel() - * OntModelSelector.getTBoxModel() - * OntModelSelector.getTBoxModel(ontologyURI) - * OntModelSelector.getUserAccountsModel() - * VitroModelSource.getModel(URL) - * VitroModelSource.getModel(URL, loadIfAbsent) - * VitroModelSource.openModel(name) - * VitroModelSource.openModelIfPresent(string) - * ServletContext.getAttribute("assertionsWebappDaoFactory") - * ServletContext.getAttribute("baseOntModelSelector") - * ServletContext.getAttribute("jenaPersistentOntModel") - * ServletContext.getAttribute("pelletOntModel") - * ServletContext.getAttribute("webappDaoFactory") - * VitroJenaModelMaker - * VitroJenaSpecialModelMaker - * JenaDataSourceSetupBase.getApplicationDataSource(ctx) - * JenaDataSourceSetupBase.getStartupDataset() - * HttpSession.getAttribute("jenaAuditModel") - *- */ - } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroModelSource.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroModelSource.java index 4ca09b10c..d41df3011 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroModelSource.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroModelSource.java @@ -9,8 +9,8 @@ import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelReader; import com.hp.hpl.jena.rdf.model.ModelSource; -import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID; /** * ModelSource that will handle specially named Vitro models such @@ -113,9 +113,9 @@ public class VitroModelSource implements ModelSource { case DISPLAY: return ModelAccess.on(context).getDisplayModel(); case DISPLAY_TBOX: - return (Model) context.getAttribute(DisplayVocabulary.CONTEXT_DISPLAY_TBOX); + return ModelAccess.on(context).getOntModel(ModelID.DISPLAY_TBOX); case DISPLAY_DISPLAY: - return (Model) context.getAttribute(DisplayVocabulary.CONTEXT_DISPLAY_DISPLAY); + return ModelAccess.on(context).getOntModel(ModelID.DISPLAY_DISPLAY); case USER_ACCOUNTS: throw new IllegalArgumentException("getNamedModel() Does not yet handle USER_ACCOUNTS"); default: diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java index e9dd1ba67..821efd570 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java @@ -3,7 +3,6 @@ package edu.cornell.mannlib.vitro.webapp.filters; import static edu.cornell.mannlib.vitro.webapp.controller.VitroRequest.SPECIAL_WRITE_MODEL; -import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.CONTEXT_DISPLAY_TBOX; import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.SWITCH_TO_DISPLAY_MODEL; import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_DISPLAY_MODEL_PARAM; import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_MODEL_PARAM; @@ -41,6 +40,7 @@ import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.FilterFactory; @@ -233,7 +233,7 @@ public class VitroRequestPrep implements Filter { // If they asked for the display model, give it to them. if (isParameterPresent(vreq, SWITCH_TO_DISPLAY_MODEL)) { OntModel mainOntModel = ModelAccess.on(_context).getDisplayModel(); - OntModel tboxOntModel = (OntModel) _context.getAttribute(CONTEXT_DISPLAY_TBOX); + OntModel tboxOntModel = ModelAccess.on(_context).getOntModel(ModelID.DISPLAY_TBOX); setSpecialWriteModel(vreq, mainOntModel); vreq.setAttribute(VitroRequest.ID_FOR_ABOX_MODEL, VitroModelSource.ModelName.DISPLAY.toString()); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ApplicationModelSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ApplicationModelSetup.java index 6e7269907..366cbc5d6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ApplicationModelSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ApplicationModelSetup.java @@ -23,6 +23,7 @@ import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; @@ -83,7 +84,7 @@ implements ServletContextListener { MEM_ONT_MODEL_SPEC); appTBOXModel.add(displayTboxModel); appTBOXModel.getBaseModel().register(new ModelSynchronizer(displayTboxModel)); - ctx.setAttribute("displayOntModelTBOX", appTBOXModel); + ModelAccess.on(ctx).setOntModel(ModelID.DISPLAY_TBOX, appTBOXModel); log.debug("Loaded file " + APPPATH_LOAD + "displayTBOX.n3 into display tbox model"); } catch (Throwable t) { log.error("Unable to load user application configuration model TBOX", t); @@ -101,7 +102,7 @@ implements ServletContextListener { MEM_ONT_MODEL_SPEC); appDisplayDisplayModel.add(displayDisplayModel); appDisplayDisplayModel.getBaseModel().register(new ModelSynchronizer(displayDisplayModel)); - ctx.setAttribute("displayOntModelDisplayModel", appDisplayDisplayModel); + ModelAccess.on(ctx).setOntModel(ModelID.DISPLAY_DISPLAY, appDisplayDisplayModel); log.debug("Loaded file " + APPPATH_LOAD + "displayDisplay.n3 into display display model"); } catch (Throwable t) { log.error("Unable to load user application configuration model Display Model", t);