1 5 6 11 12 package com.hp.hpl.jena.rdql; 13 14 import com.hp.hpl.jena.rdf.model.* ; 16 17 class Slot 18 { 19 Value value ; 20 Var variable ; 21 Resource resource ; 23 Property property ; 24 Literal literal ; 25 26 27 private void unset() 28 { 29 value = null ; 30 variable = null ; 31 resource = null ; 32 property = null ; 33 literal = null ; 34 } 35 36 public Slot() 37 { 38 unset() ; 39 } 40 41 public Slot(Slot slot) 42 { 43 value = slot.value ; 44 variable = slot.variable ; 45 property = slot.property ; 46 resource = slot.resource ; 47 } 48 49 public void set(Value v) 50 { 51 unset() ; 52 value = v ; 53 } 54 55 public void set(Var v) 56 { 57 unset() ; 58 variable = v ; 59 } 60 61 public void set(Resource r) 62 { 63 unset() ; 64 resource = r ; 65 } 66 67 public void set(Property p) 68 { 69 unset() ; 70 property = p; 71 } 72 73 public void set(Literal l) 74 { 75 unset() ; 76 literal = l ; 77 } 78 79 public boolean isValue() { return value != null ; } 80 public boolean isVar() { return variable != null ; } 81 public boolean isResource() { return resource != null ; } 82 public boolean isProperty() { return property != null ; } 83 public boolean isLiteral () { return literal != null ; } 84 85 public Value getValue() { return value ; } 86 public Var getVar() { return variable ; } 87 public Resource getResource() { return resource ; } 88 public Property getProperty() { return property ; } 89 public Literal getLiteral() { return literal ; } 90 91 public String getVarName() 92 { 93 if ( variable == null ) 94 return null ; 95 return variable.getVarName() ; 96 } 97 98 public String toString() 101 { 102 if ( value != null ) 103 return value.asInfixString() ; 104 if ( variable != null ) 105 return variable.toString() ; 106 if ( property != null ) 107 return "<"+property.toString()+">" ; 108 if ( resource != null ) 109 return "<"+resource.toString()+">" ; 110 if ( literal != null ) 111 { 112 String s = literal.toString() ; 113 if ( literal.getLanguage().equals("") && literal.getDatatype() == null ) 114 return s ; 115 116 StringBuffer sb = new StringBuffer (s) ; 117 if ( !literal.getLanguage().equals("") ) 118 sb.append("@").append(literal.getLanguage()) ; 119 if ( literal.getDatatype() != null) 120 sb.append("^^").append(literal.getDatatypeURI()) ; 121 return sb.toString() ; 122 } 123 124 return "slot:unset" ; 125 } 126 } 127 128 154 | Popular Tags |