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.OntProperty;
22  import com.hp.hpl.jena.ontology.Restriction;
23  import com.hp.hpl.jena.rdf.model.Property;
24  import ubic.basecode.ontology.model.OntologyRestriction;
25  
26  import java.util.Set;
27  
28  /**
29   * @author pavlidis
30   * 
31   */
32  class RestrictionFactory {
33  
34      public static OntologyRestriction asRestriction( Restriction restriction, Set<Restriction> additionalRestrictions ) {
35  
36          OntProperty onProperty = restriction.getOnProperty();
37  
38          if ( onProperty.isDatatypeProperty() ) {
39              return new OntologyDatatypeRestrictionImpl( restriction, additionalRestrictions );
40          } else if ( onProperty.isObjectProperty() ) {
41              if ( restriction.isCardinalityRestriction() ) {
42                  return new OntologyCardinalityRestrictionImpl( restriction, additionalRestrictions );
43              }
44              return new OntologyClassRestrictionImpl( restriction, additionalRestrictions );
45  
46          } else {
47              throw new UnsupportedOperationException( "Sorry, can't convert "
48                      + restriction.getOnProperty().getClass().getName() );
49          }
50  
51      }
52  
53  }