KickJava   Java API By Example, From Geeks To Geeks.

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


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 28-Apr-2003
9  * Filename $RCSfile: ComplementClassImpl.java,v $
10  * Revision $Revision: 1.13 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:06:17 $
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 // Imports
26
///////////////
27
import java.util.Iterator JavaDoc;
28
29 import com.hp.hpl.jena.enhanced.*;
30 import com.hp.hpl.jena.graph.Node;
31 import com.hp.hpl.jena.ontology.*;
32 import com.hp.hpl.jena.rdf.model.*;
33 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
34
35
36 /**
37  * <p>
38  * Implementation of a node representing a complement class description.
39  * </p>
40  *
41  * @author Ian Dickinson, HP Labs
42  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
43  * @version CVS $Id: ComplementClassImpl.java,v 1.13 2005/02/21 12:06:17 andy_seaborne Exp $
44  */

45 public class ComplementClassImpl
46     extends OntClassImpl
47     implements ComplementClass
48 {
49     // Constants
50
//////////////////////////////////
51

52     // Static variables
53
//////////////////////////////////
54

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

60     public static Implementation factory = new Implementation() {
61         public EnhNode wrap( Node n, EnhGraph eg ) {
62             if (canWrap( n, eg )) {
63                 return new ComplementClassImpl( n, eg );
64             }
65             else {
66                 throw new ConversionException( "Cannot convert node " + n + " to ComplementClass");
67             }
68         }
69             
70         public boolean canWrap( Node node, EnhGraph eg ) {
71             // node will support being an ComplementClass facet if it has rdf:type owl:Class and an owl:complementOf statement (or equivalents)
72
Profile profile = (eg instanceof OntModel) ? ((OntModel) eg).getProfile() : null;
73             Property comp = (profile == null) ? null : profile.COMPLEMENT_OF();
74
75             return (profile != null) &&
76                    profile.isSupported( node, eg, OntClass.class ) &&
77                    comp != null &&
78                    eg.asGraph().contains( node, comp.asNode(), Node.ANY );
79         }
80     };
81
82
83     // Instance variables
84
//////////////////////////////////
85

86     // Constructors
87
//////////////////////////////////
88

89     /**
90      * <p>
91      * Construct a complement class node represented by the given node in the given graph.
92      * </p>
93      *
94      * @param n The node that represents the resource
95      * @param g The enh graph that contains n
96      */

97     public ComplementClassImpl( Node n, EnhGraph g ) {
98         super( n, g );
99     }
100
101
102     // External signature methods
103
//////////////////////////////////
104

105     // operand
106

107     /**
108      * <p>Assert that the operands for this boolean class expression are the classes
109      * in the given list. Any existing
110      * statements for the operator will be removed.</p>
111      * @param operands The list of operands to this expression.
112      * @exception Always throws UnsupportedOperationException since a complement expression takes only
113      * a single argument.
114      */

115     public void setOperands( RDFList operands ) {
116         throw new UnsupportedOperationException JavaDoc( "ComplementClass takes a single operand, not a list.");
117     }
118     
119     
120     /**
121      * <p>Set the class that the class represented by this class expression is
122      * a complement of. Any existing value for <code>complementOf</code> will
123      * be replaced.</p>
124      * @return The class that this class is a complement of.
125      */

126     public void setOperand( Resource cls ) {
127         setPropertyValue( getProfile().COMPLEMENT_OF(), "COMPLEMENT_OF", cls );
128     }
129
130     /**
131      * <p>Add a class the operands of this boolean expression.</p>
132      * @param cls A class that will be added to the operands of this Boolean expression
133      * @exception Always throws UnsupportedOperationException since a complement expression takes only
134      * a single argument.
135      */

136     public void addOperand( Resource cls ) {
137         throw new UnsupportedOperationException JavaDoc( "ComplementClass is only defined for a single operand.");
138     }
139
140     /**
141      * <p>Add all of the classes from the given iterator to the operands of this boolean expression.</p>
142      * @param classes A iterator over classes that will be added to the operands of this Boolean expression
143      * @exception Always throws UnsupportedOperationException since a complement expression takes only
144      * a single argument.
145      */

146     public void addOperands( Iterator JavaDoc classes ) {
147         throw new UnsupportedOperationException JavaDoc( "ComplementClass is only defined for a single operand.");
148     }
149
150     /**
151      * <p>Answer the list of operands for this Boolean class expression.</p>
152      * @return A list of the operands of this expression.
153      * @exception OntProfileException If the operand property is not supported in the current language profile.
154      */

155     public RDFList getOperands() {
156         throw new UnsupportedOperationException JavaDoc( "ComplementClass takes a single operand, not a list.");
157     }
158
159     /**
160      * <p>Answer an iterator over all of the clases that are the operands of this
161      * Boolean class expression. Each element of the iterator will be an {@link OntClass}.</p>
162      * @return An iterator over the operands of the expression.
163      * @exception OntProfileException If the operand property is not supported in the current language profile.
164      */

165     public ExtendedIterator listOperands() {
166         return listAs( getProfile().COMPLEMENT_OF(), "COMPLEMENT_OF", OntClass.class );
167     }
168
169     /**
170      * <p>Answer true if this Boolean class expression has the given class as an operand.</p>
171      * @param cls A class to test
172      * @return True if the given class is an operand to this expression.
173      * @exception OntProfileException If the operand property is not supported in the current language profile.
174      */

175     public boolean hasOperand( Resource cls ) {
176         return hasPropertyValue( getProfile().COMPLEMENT_OF(), "COMPLEMENT_OF", cls );
177     }
178     
179     /**
180      * <p>Answer the class that the class described by this class description
181      * is a complement of.</p>
182      * @return The class that this class is a complement of.
183      */

184     public OntClass getOperand() {
185         return (OntClass) objectAs( getProfile().COMPLEMENT_OF(), "COMPLEMENT_OF", OntClass.class );
186     }
187     
188     /**
189      * <p>Remove the given resource from the operands of this class expression.</p>
190      * @param res An resource to be removed from the operands of this class expression
191      */

192     public void removeOperand( Resource res ) {
193         removePropertyValue( getProfile().COMPLEMENT_OF(), "COMPLEMENT_OF", res );
194     }
195     
196     
197     /**
198      * <p>Answer the property that is used to construct this boolean expression, for example
199      * {@link Profile#UNION_OF()}.</p>
200      * @return {@link Profile#COMPLEMENT_OF()}
201      */

202     public Property operator() {
203         return getProfile().COMPLEMENT_OF();
204     }
205
206
207
208     // Internal implementation methods
209
//////////////////////////////////
210

211     //==============================================================================
212
// Inner class definitions
213
//==============================================================================
214

215 }
216
217
218 /*
219     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
220     All rights reserved.
221
222     Redistribution and use in source and binary forms, with or without
223     modification, are permitted provided that the following conditions
224     are met:
225
226     1. Redistributions of source code must retain the above copyright
227        notice, this list of conditions and the following disclaimer.
228
229     2. Redistributions in binary form must reproduce the above copyright
230        notice, this list of conditions and the following disclaimer in the
231        documentation and/or other materials provided with the distribution.
232
233     3. The name of the author may not be used to endorse or promote products
234        derived from this software without specific prior written permission.
235
236     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
237     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
238     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
239     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
240     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
241     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
244     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
245     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
246 */

247
248
249
Popular Tags