KickJava   Java API By Example, From Geeks To Geeks.

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


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 08-Sep-2003
9  * Filename $RCSfile: CardinalityQRestrictionImpl.java,v $
10  * Revision $Revision: 1.4 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:06:16 $
14  * by $Author: andy_seaborne $
15  *
16  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17  * [See end of file]
18  *****************************************************************************/

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

41 public class CardinalityQRestrictionImpl
42     extends QualifiedRestrictionImpl
43     implements CardinalityQRestriction
44 {
45     // Constants
46
//////////////////////////////////
47

48     // Static variables
49
//////////////////////////////////
50

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

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

77     /**
78      * <p>
79      * Construct a qualified restriction node represented by the given node in the given graph.
80      * </p>
81      *
82      * @param n The node that represents the resource
83      * @param g The enh graph that contains n
84      */

85     public CardinalityQRestrictionImpl( Node n, EnhGraph g ) {
86         super( n, g );
87     }
88
89
90     // Constructors
91
//////////////////////////////////
92

93     // External signature methods
94
//////////////////////////////////
95

96     /**
97      * <p>Assert that this restriction restricts the property to have the given
98      * cardinality. Any existing statements for <code>cardinalityQ</code>
99      * will be removed.</p>
100      * @param cardinality The cardinality of the restricted property
101      * @exception OntProfileException If the {@link Profile#CARDINALITY_Q()} property is not supported in the current language profile.
102      */

103     public void setCardinalityQ( int cardinality ) {
104         setPropertyValue( getProfile().CARDINALITY_Q(), "CARDINALITY_Q", getModel().createTypedLiteral( cardinality ) );
105     }
106
107     /**
108      * <p>Answer the cardinality of the restricted property.</p>
109      * @return The cardinality of the restricted property
110      * @exception OntProfileException If the {@link Profile#CARDINALITY_Q()} property is not supported in the current language profile.
111      */

112     public int getCardinalityQ() {
113         return objectAsInt( getProfile().CARDINALITY_Q(), "CARDINALITY_Q" );
114     }
115
116     /**
117      * <p>Answer true if this property restriction has the given cardinality.</p>
118      * @param cardinality The cardinality to test against
119      * @return True if the given cardinality is the cardinality of the restricted property in this restriction
120      * @exception OntProfileException If the {@link Profile#CARDINALITY_Q()} property is not supported in the current language profile.
121      */

122     public boolean hasCardinalityQ( int cardinality ) {
123         return hasPropertyValue( getProfile().CARDINALITY_Q(), "CARDINALITY_Q", getModel().createTypedLiteral( cardinality ) );
124     }
125     
126     /**
127      * <p>Remove the statement that this restriction has the given cardinality
128      * for the restricted property. If this statement
129      * is not true of the current model, nothing happens.</p>
130      * @param cardinality A cardinality value to be removed from this restriction
131      * @exception OntProfileException If the {@link Profile#CARDINALITY_Q()} property is not supported in the current language profile.
132      */

133     public void removeCardinalityQ( int cardinality ) {
134         removePropertyValue( getProfile().CARDINALITY_Q(), "CARDINALITY_Q", getModel().createTypedLiteral( cardinality ) );
135     }
136     
137
138     // Internal implementation methods
139
//////////////////////////////////
140

141     //==============================================================================
142
// Inner class definitions
143
//==============================================================================
144

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

173
Popular Tags