View Javadoc
1   /*
2    * Copyright 2018-2024 Medical Information Systems Research Group (https://medical.zcu.cz),
3    * Department of Computer Science and Engineering, University of West Bohemia.
4    * Address: Univerzitni 8, 306 14 Plzen, Czech Republic.
5    *
6    * Author Petr Vcelak (vcelak@kiv.zcu.cz).
7    *
8    * This file is part of MRE SPARQL QueryBuilder project.
9    *
10   * MRE SPARQL QueryBuilder is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU General Public License as published by
12   * the Free Software Foundation, either version 3 of the License.
13   *
14   * MRE SPARQL QueryBuilder is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public License
20   * along with MRE SPARQL QueryBuilder. If not, see <http://www.gnu.org/licenses/>.
21   */
22  package cz.zcu.mre.qbuilder.model;
23  
24  import com.fasterxml.jackson.annotation.JsonProperty;
25  import java.io.Serializable;
26  import java.util.Objects;
27  import org.apache.jena.graph.Node;
28  import org.apache.jena.graph.NodeFactory;
29  import org.apache.jena.ontology.OntClass;
30  import org.apache.jena.rdf.model.Resource;
31  
32  /**
33   *
34   * @author Petr Vcelak (vcelak@kiv.zcu.cz)
35   */
36  public class RootNode implements Serializable {
37  
38      protected Node node;
39  
40      public RootNode() {
41      }
42  
43      public RootNode(OntClass clazz) {
44  
45          this.node = clazz.asNode();
46      }
47  
48      public RootNode(Resource clazz) {
49  
50          this.node = clazz.asNode();
51      }
52  
53      public RootNode(String clazz) {
54          setURI(clazz);
55      }
56  
57      @JsonProperty("node")
58      public String getURI() {
59          if (hasNode()) {
60              return getNode().getURI();
61          }
62  
63          return null;
64      }
65  
66      @JsonProperty("node")
67      public final void setURI(String uri) {
68  
69          this.node = NodeFactory.createURI(uri);
70      }
71  
72      public boolean hasNode() {
73          return !(this.node == null || this.node.getURI() == null);
74      }
75  
76      public Node getNode() {
77  
78          if (hasNode()) {
79              return node;
80          }
81  
82          return null;
83      }
84  
85      public void setNode(Node node) {
86  
87          this.node = node;
88      }
89  
90      @Override
91      public String toString() {
92          return "RootNode{" + "node=" + node + '}';
93      }
94  
95      @Override
96      public int hashCode() {
97          int hash = 5;
98          hash = 97 * hash + Objects.hashCode(this.node);
99          return hash;
100     }
101 
102     @Override
103     public boolean equals(Object obj) {
104         if (this == obj) {
105             return true;
106         }
107         if (obj == null) {
108             return false;
109         }
110         if (getClass() != obj.getClass()) {
111             return false;
112         }
113         final RootNode other = (RootNode) obj;
114         return Objects.equals(this.node, other.node);
115     }
116 
117 }