1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package ubic.basecode.ontology.model;
20
21 import java.util.Collection;
22 import java.util.HashSet;
23
24 import com.hp.hpl.jena.ontology.ObjectProperty;
25 import com.hp.hpl.jena.ontology.OntClass;
26 import com.hp.hpl.jena.ontology.OntResource;
27 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
28
29
30
31
32
33 public class ObjectPropertyImpl extends OntologyPropertyImpl implements ubic.basecode.ontology.model.ObjectProperty {
34
35
36
37
38 private static final long serialVersionUID = 1L;
39 private com.hp.hpl.jena.ontology.ObjectProperty resource;
40
41 public ObjectPropertyImpl( ObjectProperty resource ) {
42 this.isFunctional = resource.isFunctionalProperty();
43 this.resource = resource;
44 }
45
46 @Override
47 public String getLabel() {
48 return this.toString();
49 }
50
51 @Override
52 public Collection<OntologyTerm> getRange() {
53 ExtendedIterator<? extends OntResource> iterator = resource.listRange();
54 Collection<OntologyTerm> result = new HashSet<OntologyTerm>();
55 while ( iterator.hasNext() ) {
56 OntResource r = iterator.next();
57 if ( r.isClass() ) {
58 OntClass class1 = r.asClass();
59 result.add( new OntologyTermImpl( class1 ) );
60 } else {
61 log.warn( "Don't know how to deal with " + r );
62 }
63 }
64 return result;
65 }
66
67 @Override
68 public String getUri() {
69 return resource.getURI();
70 }
71
72 @Override
73 public String toString() {
74 String label = resource.getLabel( "EN" );
75 if ( label == null ) label = resource.getLabel( null );
76 if ( label == null ) label = resource.getLocalName();
77 if ( label == null ) label = resource.getURI();
78 if ( label == null ) label = resource.toString();
79 if ( label == null ) label = "[no string version available!]";
80 return label;
81 }
82 }