001: /*
002:
003: Derby - Class org.apache.derby.ui.properties.DerbyProperties
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.ui.properties;
023:
024: import org.apache.derby.ui.common.CommonNames;
025: import org.eclipse.core.resources.IProject;
026: import org.eclipse.core.runtime.CoreException;
027: import org.eclipse.core.runtime.QualifiedName;
028: import org.eclipse.jdt.core.IJavaProject;
029:
030: public class DerbyProperties {
031:
032: public static final String DSPORT = "ds.port";
033: //public static final String DS_RUNNING_PORT = "ds.running.port";
034: public static final String DSHOST = "ds.host";
035: public static final String DS_SYS_HOME = "derby.system.home";
036:
037: //Default Derby Properties
038: private int port = 1527;
039: //private int runningPort=0;
040: private String host = "localhost";
041: private String systemHome = ".";
042:
043: public DerbyProperties() {
044: }
045:
046: public DerbyProperties(IJavaProject javaProject)
047: throws CoreException {
048: load(javaProject.getProject());
049: }
050:
051: public DerbyProperties(IProject project) throws CoreException {
052: load(project);
053: }
054:
055: public void save(IProject project) throws CoreException {
056:
057: project.setPersistentProperty(new QualifiedName(
058: CommonNames.UI_PATH, DSPORT), Integer.toString(port));
059: project.setPersistentProperty(new QualifiedName(
060: CommonNames.UI_PATH, DSHOST), host);
061: project.setPersistentProperty(new QualifiedName(
062: CommonNames.UI_PATH, DS_SYS_HOME), systemHome);
063: // project.setPersistentProperty(new QualifiedName (
064: // CommonNames.UI_PATH, DS_RUNNING_PORT), Integer.toString(runningPort));
065: }
066:
067: public void load(IProject project) throws CoreException {
068:
069: String property = project
070: .getPersistentProperty(new QualifiedName(
071: CommonNames.UI_PATH, DSPORT));
072: port = (property != null && property.length() > 0) ? Integer
073: .parseInt(property) : port;
074: property = project.getPersistentProperty(new QualifiedName(
075: CommonNames.UI_PATH, DSHOST));
076: host = (property != null && property.length() > 0) ? property
077: : host;
078: property = project.getPersistentProperty(new QualifiedName(
079: CommonNames.UI_PATH, DS_SYS_HOME));
080: systemHome = (property != null && property.length() > 0) ? property
081: : systemHome;
082: // property = project.getPersistentProperty(new QualifiedName (
083: // CommonNames.UI_PATH, DS_RUNNING_PORT));
084: // runningPort = (property != null && property.length() > 0) ? Integer.parseInt(property) : runningPort;
085: }
086:
087: public String toString() {
088: return "Derby Server Properties:\n Port = " + getPort()
089: + " Host = " + getHost() + " System Home = "
090: + getSystemHome();
091: }
092:
093: /**
094: * @return Returns the host.
095: */
096: public String getHost() {
097: return host;
098: }
099:
100: /**
101: * @param host The host to set.
102: */
103: public void setHost(String host) {
104: this .host = host;
105: }
106:
107: /**
108: * @return Returns the port.
109: */
110: public int getPort() {
111: return port;
112: }
113:
114: /**
115: * @param port The port to set.
116: */
117: public void setPort(int port) {
118: this .port = port;
119: }
120:
121: /**
122: * @return Returns the systemHome.
123: */
124: public String getSystemHome() {
125: return systemHome;
126: }
127:
128: /**
129: * @param systemHome The systemHome to set.
130: */
131: public void setSystemHome(String systemHome) {
132: this.systemHome = systemHome;
133: }
134:
135: }
|