View Javadoc
1   /*
2    * The basecode project
3    *
4    * Copyright (c) 2007-2019 University of British Columbia
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   *
18   */
19  package ubic.basecode.ontology.jena;
20  
21  import com.hp.hpl.jena.ontology.DatatypeProperty;
22  import com.hp.hpl.jena.ontology.OntProperty;
23  import com.hp.hpl.jena.ontology.OntResource;
24  import com.hp.hpl.jena.ontology.Restriction;
25  
26  import java.util.Set;
27  
28  /**
29   * @author pavlidis
30   */
31  class PropertyFactory {
32  
33      /**
34       * Convert a Jena property.
35       *
36       * @return new property or null if it could not be converted.
37       */
38      public static ubic.basecode.ontology.model.OntologyProperty asProperty( OntProperty property, Set<Restriction> additionalRestrictions ) {
39  
40          if ( property.isObjectProperty() ) {
41              return new ObjectPropertyImpl( property.asObjectProperty(), additionalRestrictions );
42          } else if ( property.isDatatypeProperty() ) {
43              return new DatatypePropertyImpl( property.asDatatypeProperty() );
44          } else {
45              return null;
46          }
47  
48      }
49  
50      public static Class<?> convertType( DatatypeProperty resource ) {
51          Class<?> type = java.lang.String.class;
52  
53          OntResource range = resource.getRange();
54          if ( range != null ) {
55              String uri = range.getURI();
56  
57              if ( uri == null ) {
58                  type = java.lang.String.class;
59              } else if ( uri.equals( "http://www.w3.org/2001/XMLSchema#&xsd;string" ) ) {
60                  type = java.lang.String.class;
61              } else if ( uri.equals( "http://www.w3.org/2001/XMLSchema#&xsd;boolean" ) ) {
62                  type = java.lang.Boolean.class;
63              } else if ( uri.equals( "http://www.w3.org/2001/XMLSchema#&xsd;float" ) ) {
64                  type = java.lang.Double.class;
65              } else if ( uri.equals( "http://www.w3.org/2001/XMLSchema#&xsd;double" ) ) {
66                  type = java.lang.Double.class;
67              } else if ( uri.equals( "http://www.w3.org/2001/XMLSchema#&xsd;int" ) ) {
68                  type = java.lang.Integer.class;
69              } else if ( uri.equals( "http://www.w3.org/2001/XMLSchema#&xsd;date" ) ) {
70                  type = java.util.Date.class;
71              }
72          }
73          return type;
74      }
75  }