KickJava   Java API By Example, From Geeks To Geeks.

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


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-May-2003
9  * Filename $RCSfile: CardinalityRestrictionImpl.java,v $
10  * Revision $Revision: 1.6 $
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 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
32
33 /**
34  * <p>
35  * Implementation of the cardinality restriction abstraction.
36  * </p>
37  *
38  * @author Ian Dickinson, HP Labs
39  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
40  * @version CVS $Id: CardinalityRestrictionImpl.java,v 1.6 2005/02/21 12:06:16 andy_seaborne Exp $
41  */

42 public class CardinalityRestrictionImpl
43     extends RestrictionImpl
44     implements CardinalityRestriction
45 {
46     // Constants
47
//////////////////////////////////
48

49     // Static variables
50
//////////////////////////////////
51

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

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

79     // Constructors
80
//////////////////////////////////
81

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

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

97     // cardinality
98

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

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

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

125     public boolean hasCardinality( int cardinality ) {
126         return hasPropertyValue( getProfile().CARDINALITY(), "CARDINALITY", getModel().createTypedLiteral( cardinality ) );
127     }
128     
129     /**
130      * <p>Remove the statement that this restriction has the given cardinality
131      * for the restricted property. If this statement
132      * is not true of the current model, nothing happens.</p>
133      * @param cardinality A cardinality value to be removed from this restriction
134      */

135     public void removeCardinality( int cardinality ) {
136         removePropertyValue( getProfile().CARDINALITY(), "CARDINALITY", getModel().createTypedLiteral( cardinality ) );
137     }
138     
139
140     // Internal implementation methods
141
//////////////////////////////////
142

143     //==============================================================================
144
// Inner class definitions
145
//==============================================================================
146

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

179
Popular Tags