KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > ontology > impl > HasValueRestrictionImpl


1 /*****************************************************************************
2  * Source code information
3  * -----------------------
4  * Original author Ian Dickinson, HP Labs Bristol
5  * Author email Ian.Dickinson@hp.com
6  * Package Jena 2
7  * Web http://sourceforge.net/projects/jena/
8  * Created 07-May-2003
9  * Filename $RCSfile: HasValueRestrictionImpl.java,v $
10  * Revision $Revision: 1.11 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:06:21 $
14  * by $Author: andy_seaborne $
15  *
16  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17  * (see footer for full conditions)
18  *****************************************************************************/

19
20 // Package
21
///////////////
22
package com.hp.hpl.jena.ontology.impl;
23
24
25
26 // Imports
27
///////////////
28
import com.hp.hpl.jena.enhanced.*;
29 import com.hp.hpl.jena.graph.*;
30 import com.hp.hpl.jena.ontology.*;
31 import com.hp.hpl.jena.rdf.model.*;
32
33
34 /**
35  * <p>
36  * Implementation of the hasValue restriction abstraction.
37  * </p>
38  *
39  * @author Ian Dickinson, HP Labs
40  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
41  * @version CVS $Id: HasValueRestrictionImpl.java,v 1.11 2005/02/21 12:06:21 andy_seaborne Exp $
42  */

43 public class HasValueRestrictionImpl
44     extends RestrictionImpl
45     implements HasValueRestriction
46 {
47     // Constants
48
//////////////////////////////////
49

50     // Static variables
51
//////////////////////////////////
52

53     /**
54      * A factory for generating HasValueRestriction facets from nodes in enhanced graphs.
55      * Note: should not be invoked directly by user code: use
56      * {@link com.hp.hpl.jena.rdf.model.RDFNode#as as()} instead.
57      */

58     public static Implementation factory = new Implementation() {
59         public EnhNode wrap( Node n, EnhGraph eg ) {
60             if (canWrap( n, eg )) {
61                 return new HasValueRestrictionImpl( n, eg );
62             }
63             else {
64                 throw new ConversionException( "Cannot convert node " + n + " to HasValueRestriction");
65             }
66         }
67             
68         public boolean canWrap( Node node, EnhGraph eg ) {
69             // node will support being a HasValueRestriction facet if it has rdf:type owl:Restriction or equivalent
70
// and the combination of owl:onProperty and owl:hasValue (or equivalents)
71
Profile profile = (eg instanceof OntModel) ? ((OntModel) eg).getProfile() : null;
72             return (profile != null) && profile.isSupported( node, eg, HasValueRestriction.class );
73         }
74     };
75
76
77     // Instance variables
78
//////////////////////////////////
79

80     // Constructors
81
//////////////////////////////////
82

83     /**
84      * <p>
85      * Construct a hasValue restriction node represented by the given node in the given graph.
86      * </p>
87      *
88      * @param n The node that represents the resource
89      * @param g The enh graph that contains n
90      */

91     public HasValueRestrictionImpl( Node n, EnhGraph g ) {
92         super( n, g );
93     }
94
95
96     // External signature methods
97
//////////////////////////////////
98

99     // hasValue
100

101     /**
102      * <p>Assert that this restriction restricts the property to have the given
103      * value. Any existing statements for <code>hasValue</code>
104      * will be removed.</p>
105      * @param value The RDF value (an individual or a literal)
106      * that is the value that the restricted property must have to be a member of the
107      * class defined by this restriction.
108      * @exception OntProfileException If the {@link Profile#HAS_VALUE()} property is not supported in the current language profile.
109      */

110     public void setHasValue( RDFNode value ) {
111         setPropertyValue( getProfile().HAS_VALUE(), "HAS_VALUE", value );
112     }
113
114     /**
115      * <p>Answer the RDF value that all values of the restricted property must be equal to.</p>
116      * @return An RDFNode that is the value of the restricted property
117      * @exception OntProfileException If the {@link Profile#HAS_VALUE()} property is not supported in the current language profile.
118      */

119     public RDFNode getHasValue() {
120         checkProfile( getProfile().HAS_VALUE(), "HAS_VALUE" );
121         RDFNode n = getPropertyValue( getProfile().HAS_VALUE() );
122         
123         // map to an individual in the case of a resource value
124
if (!(n instanceof Literal) && n.canAs( Individual.class )) {
125             n = n.as( Individual.class );
126         }
127         
128         return n;
129     }
130
131     /**
132      * <p>Answer true if this property restriction has the given RDF value as the value which all
133      * values of the restricted property must equal.</p>
134      * @param value An RDF value to test
135      * @return True if the given value is the value of the restricted property in this restriction
136      * @exception OntProfileException If the {@link Profile#HAS_VALUE()} property is not supported in the current language profile.
137      */

138     public boolean hasValue( RDFNode value ) {
139         return hasPropertyValue( getProfile().HAS_VALUE(), "HAS_VALUE", value );
140     }
141     
142     /**
143      * <p>Remove the statement that this restriction requires the restricted property to have
144      * the given value. If this statement
145      * is not true of the current model, nothing happens.</p>
146      * @param value An RDF value that is to be removed as the required value for the restricted property
147      */

148     public void removeHasValue( RDFNode value ) {
149         removePropertyValue( getProfile().HAS_VALUE(), "HAS_VALUE", value );
150     }
151     
152
153     // Internal implementation methods
154
//////////////////////////////////
155

156     //==============================================================================
157
// Inner class definitions
158
//==============================================================================
159

160 }
161
162
163 /*
164     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
165     All rights reserved.
166
167     Redistribution and use in source and binary forms, with or without
168     modification, are permitted provided that the following conditions
169     are met:
170
171     1. Redistributions of source code must retain the above copyright
172        notice, this list of conditions and the following disclaimer.
173
174     2. Redistributions in binary form must reproduce the above copyright
175        notice, this list of conditions and the following disclaimer in the
176        documentation and/or other materials provided with the distribution.
177
178     3. The name of the author may not be used to endorse or promote products
179        derived from this software without specific prior written permission.
180
181     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
182     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
183     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
184     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
185     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
186     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
187     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
188     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
189     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
190     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
191 */

192
193
Popular Tags