001 /**
002 * Copyright (C) 2007-2011, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program. If not, see <http://www.gnu.org/licenses/>.
018 */
019
020 package org.dllearner.core.options;
021
022 import java.net.URL;
023 import java.util.SortedSet;
024 import java.util.TreeSet;
025
026 /**
027 * Option which has an URL as value.
028 *
029 * @author Jens Lehmann
030 *
031 */
032 public class URLConfigOption extends ConfigOption<URL> {
033
034 private boolean refersToFile = false;
035
036 private boolean refersToOWLClass = false;
037
038 public URLConfigOption(String name, String description) {
039 super(name, description);
040 }
041
042 public URLConfigOption(String name, String description, URL defaultValue) {
043 super(name, description, defaultValue);
044 }
045
046 public URLConfigOption(String name, String description, URL defaultValue, boolean mandatory,
047 boolean requiresInit) {
048 super(name, description, defaultValue, mandatory, requiresInit);
049 }
050
051 /**
052 * Returns whether the URI can refer to a file or not, e.g. the
053 * URL of an OWL knowledge source does refer to a file whereas
054 * the URL of a SPARQL endpoint cannot refer to a file. The distinction
055 * can be useful in GUIs (e.g. they may offer to choose a local file).
056 * @return the refersToFile
057 */
058 public boolean refersToFile() {
059 return refersToFile;
060 }
061
062 /**
063 * @param refersToFile Set whether this option can refer to a file.
064 */
065 public void setRefersToFile(boolean refersToFile) {
066 this.refersToFile = refersToFile;
067 }
068
069 /**
070 * Returns whether the URI can refer to a class in a loaded
071 * ontology. This can be used in user interfaces for this component.
072 * @return the refersToOWLClass Whether it refers to an OWL class.
073 */
074 public boolean refersToOWLClass() {
075 return refersToOWLClass;
076 }
077
078 /**
079 * @param refersToFile Set whether this option refers to an OWL class in the
080 * loaded ontology.
081 */
082 public void setRefersToOWLClass(boolean refersToOWLClass) {
083 this.refersToOWLClass = refersToOWLClass;
084 }
085
086 /* (non-Javadoc)
087 * @see org.dllearner.core.config.ConfigOption#checkType(java.lang.Object)
088 */
089 @Override
090 public boolean checkType(Object object) {
091 return (object instanceof URL);
092 }
093
094 /* (non-Javadoc)
095 * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object, java.lang.Integer)
096 */
097 @Override
098 public String getValueFormatting(URL value) {
099 return "\"" + value.toString() + "\";";
100 }
101
102 /* (non-Javadoc)
103 * @see org.dllearner.core.config.ConfigOption#getValueTypeAsJavaString()
104 */
105 @Override
106 public String getValueTypeAsJavaString() {
107 return "URL";
108 }
109
110 /* (non-Javadoc)
111 * @see org.dllearner.core.config.ConfigOption#isValidValue(java.lang.Object)
112 */
113 @Override
114 public boolean isValidValue(URL value) {
115 return true;
116 }
117
118 /* (non-Javadoc)
119 * @see org.dllearner.core.config.ConfigOption#getJavaImports()
120 */
121 @Override
122 public SortedSet<String> getJavaImports() {
123 SortedSet<String> ret = new TreeSet<String>();
124 ret.add("java.net.URL");
125 return ret;
126 }
127
128
129
130 }