001 /*
002 * The contents of this file are subject to the Mozilla Public License
003 * Version 1.1 (the "License"); you may not use this file except in
004 * compliance with the License. You may obtain a copy of the License at
005 * http://www.mozilla.org/MPL/
006 *
007 * Software distributed under the License is distributed on an "AS IS" basis,
008 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009 * the specific language governing rights and limitations under the License.
010 *
011 * The Original Code is Protege-2000.
012 *
013 * The Initial Developer of the Original Code is Stanford University. Portions
014 * created by Stanford University are Copyright (C) 2007. All Rights Reserved.
015 *
016 * Protege was developed by Stanford Medical Informatics
017 * (http://www.smi.stanford.edu) at the Stanford University School of Medicine
018 * with support from the National Library of Medicine, the National Science
019 * Foundation, and the Defense Advanced Research Projects Agency. Current
020 * information about Protege can be obtained at http://protege.stanford.edu.
021 *
022 */
023
024 package edu.stanford.smi.protegex.owl.model.impl;
025
026 import edu.stanford.smi.protege.model.FrameID;
027 import edu.stanford.smi.protege.model.KnowledgeBase;
028 import edu.stanford.smi.protegex.owl.model.*;
029 import edu.stanford.smi.protegex.owl.model.visitor.OWLModelVisitor;
030
031 import java.util.Collections;
032 import java.util.Iterator;
033 import java.util.List;
034
035 /**
036 * @author Holger Knublauch <holger@knublauch.com>
037 */
038 public class DefaultOWLDataRange extends DefaultRDFIndividual implements OWLDataRange {
039
040 public DefaultOWLDataRange(KnowledgeBase kb, FrameID id) {
041 super(kb, id);
042 }
043
044
045 public DefaultOWLDataRange() {
046 }
047
048
049 public boolean equalsStructurally(RDFObject object) {
050 if (object instanceof OWLDataRange) {
051 OWLDataRange comp = (OWLDataRange) object;
052 return OWLUtil.equalsStructurally(getOneOfValueLiterals(), comp.getOneOfValueLiterals());
053 }
054 return false;
055 }
056
057
058 public String getBrowserText() {
059 String str = "owl:oneOf{";
060 RDFList oneOf = getOneOf();
061 if (oneOf != null) {
062 for (Iterator it = oneOf.getValues().iterator(); it.hasNext();) {
063 Object o = it.next();
064 if (o instanceof String) {
065 str += "\"" + o + "\"";
066 }
067 else if (o instanceof RDFSLiteral) {
068 RDFSLiteral literal = (RDFSLiteral) o;
069 if (literal.getDatatype().equals(getOWLModel().getXSDstring())) {
070 str += "\"" + literal.getString() + "\"";
071 }
072 else {
073 str += literal.getString();
074 }
075 }
076 else {
077 str += o;
078 }
079 if (it.hasNext()) {
080 str += " ";
081 }
082 }
083 }
084 return str + "}";
085 }
086
087
088 public RDFList getOneOf() {
089 return (RDFList) getPropertyValue(getOWLModel().getOWLOneOfProperty());
090 }
091
092
093 public List getOneOfValueLiterals() {
094 RDFList oneOf = getOneOf();
095 if (oneOf == null) {
096 return Collections.EMPTY_LIST;
097 }
098 else {
099 return oneOf.getValueLiterals();
100 }
101 }
102
103
104 public List getOneOfValues() {
105 RDFList oneOf = getOneOf();
106 if (oneOf == null) {
107 return Collections.EMPTY_LIST;
108 }
109 else {
110 return oneOf.getValues();
111 }
112 }
113
114
115 public RDFSDatatype getRDFDatatype() {
116 RDFList oneOf = getOneOf();
117 if (oneOf != null) {
118 Object first = oneOf.getFirst();
119 if (first != null && !getOWLModel().getRDFNil().equals(first)) {
120 return getOWLModel().getRDFSDatatypeOfValue(first);
121 }
122 }
123 return null;
124 }
125
126
127 public void accept(OWLModelVisitor visitor) {
128 visitor.visitOWLDataRange(this);
129 }
130 }
131