/** * ************************************************************************ Get the database path * for this project * * @return *********************************************************************** */ @SuppressWarnings("unchecked") public String getDatabasePath() { HashMap<QualifiedName, Object> properties = null; try { properties = new HashMap<QualifiedName, Object>(m_project.getPersistentProperties()); } catch (CoreException e1) { System.err.println( "Cannot retrieve persistent properties for project " + m_project.getName()); return null; } if (!properties.containsKey(ProjectDatabaseProperty.GCS_DATABASE.getKey())) { restoreProjectProperties(ProjectDatabaseProperty.GCS_DATABASE); } try { String path = m_project.getPersistentProperty(ProjectDatabaseProperty.GCS_DATABASE.getKey()); // Relative path boolean absolute = true; if (!path.isEmpty()) { absolute = new File(path).isAbsolute(); } if (!path.isEmpty() && !absolute) { IPath projAbsolute = m_project.getLocation(); String projectPath = projAbsolute.toFile().getAbsolutePath(); path = projectPath + File.separator + path; } return path; } catch (CoreException e) { return null; } }
/** * ************************************************************************* Restore project * properties * * @param project ************************************************************************ */ @SuppressWarnings("unchecked") private void restoreProjectProperties(ProjectDatabaseProperty property) { HashMap<QualifiedName, Object> properties = null; try { properties = new HashMap<QualifiedName, Object>(m_project.getPersistentProperties()); } catch (CoreException e1) { System.err.println( "Cannot retrieve persistent propertier for project " + m_project.getName()); return; } if (!properties.containsKey(property.getKey())) { try { String defaultVal = getDefaultValue(property); m_project.setPersistentProperty(property.getKey(), defaultVal); } catch (CoreException e) { System.err.println("Cannot set default value for property " + property.getKey()); } } }
/** * ************************************************************************ Get the database * driver attached to a project * * @param project * @return *********************************************************************** */ @SuppressWarnings("unchecked") public String getDatabaseDriverName() { HashMap<QualifiedName, Object> properties = null; try { properties = new HashMap<QualifiedName, Object>(m_project.getPersistentProperties()); } catch (CoreException e1) { System.err.println( "Cannot retrieve persistent properties for project " + m_project.getName()); return null; } if (!properties.containsKey(ProjectDatabaseProperty.GCS_DRIVER.getKey())) { restoreProjectProperties(ProjectDatabaseProperty.GCS_DRIVER); } try { return m_project.getPersistentProperty(ProjectDatabaseProperty.GCS_DRIVER.getKey()); } catch (CoreException e) { return null; } }