KickJava   Java API By Example, From Geeks To Geeks.

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


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-May-2003
9  * Filename $RCSfile: BooleanClassDescriptionImpl.java,v $
10  * Revision $Revision: 1.10 $
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 java.util.Iterator JavaDoc;
29
30 import com.hp.hpl.jena.enhanced.EnhGraph;
31 import com.hp.hpl.jena.graph.Node;
32 import com.hp.hpl.jena.ontology.*;
33 import com.hp.hpl.jena.rdf.model.*;
34 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
35
36
37
38 /**
39  * <p>
40  * Shared implementation for implementations of Boolean clas expressions.
41  * </p>
42  *
43  * @author Ian Dickinson, HP Labs
44  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
45  * @version CVS $Id: BooleanClassDescriptionImpl.java,v 1.10 2005/02/21 12:06:16 andy_seaborne Exp $
46  */

47 public abstract class BooleanClassDescriptionImpl
48     extends OntClassImpl
49     implements BooleanClassDescription
50 {
51     // Constants
52
//////////////////////////////////
53

54     // Static variables
55
//////////////////////////////////
56

57     // Instance variables
58
//////////////////////////////////
59

60     // Constructors
61
//////////////////////////////////
62

63     /**
64      * <p>
65      * Construct an boolean class description represented by the given node in the given graph.
66      * </p>
67      *
68      * @param n The node that represents the resource
69      * @param g The enh graph that contains n
70      */

71     public BooleanClassDescriptionImpl( Node n, EnhGraph g ) {
72         super( n, g );
73     }
74
75
76     // External signature methods
77
//////////////////////////////////
78

79     // operand
80

81     /**
82      * <p>Assert that the operands for this boolean class expression are the classes
83      * in the given list. Any existing
84      * statements for the operator will be removed.</p>
85      * @param operands The list of operands to this expression.
86      * @exception OntProfileException If the operand property is not supported in the current language profile.
87      */

88     public void setOperands( RDFList operands ) {
89         setPropertyValue( operator(), getOperatorName(), operands );
90     }
91
92     /**
93      * <p>Add a class the operands of this boolean expression.</p>
94      * @param cls A class that will be added to the operands of this Boolean expression
95      * @exception OntProfileException If the operand property is not supported in the current language profile.
96      */

97     public void addOperand( Resource cls ) {
98         addListPropertyValue( operator(), getOperatorName(), cls );
99     }
100
101     /**
102      * <p>Add all of the classes from the given iterator to the operands of this boolean expression.</p>
103      * @param classes A iterator over classes that will be added to the operands of this Boolean expression
104      * @exception OntProfileException If the operand property is not supported in the current language profile.
105      */

106     public void addOperands( Iterator JavaDoc classes ) {
107         while (classes.hasNext()) {
108             addOperand( (Resource) classes.next() );
109         }
110     }
111
112     /**
113      * <p>Answer the list of operands for this Boolean class expression.</p>
114      * @return A list of the operands of this expression.
115      * @exception OntProfileException If the operand property is not supported in the current language profile.
116      */

117     public RDFList getOperands() {
118         return (RDFList) objectAs( operator(), getOperatorName(), RDFList.class );
119     }
120
121     /**
122      * <p>Answer an iterator over all of the clases that are the operands of this
123      * Boolean class expression. Each element of the iterator will be an {@link OntClass}.</p>
124      * @return An iterator over the operands of the expression.
125      * @exception OntProfileException If the operand property is not supported in the current language profile.
126      */

127     public ExtendedIterator listOperands() {
128         return getOperands().iterator().mapWith( new AsMapper( OntClass.class ) );
129     }
130
131     /**
132      * <p>Answer true if this Boolean class expression has the given class as an operand.</p>
133      * @param cls A class to test
134      * @return True if the given class is an operand to this expression.
135      * @exception OntProfileException If the operand property is not supported in the current language profile.
136      */

137     public boolean hasOperand( Resource cls ) {
138         return getOperands().contains( cls );
139     }
140     
141     
142     /**
143      * <p>Remove the given resource from the operands of this class expression.</p>
144      * @param res An resource to be removed from the operands of this class expression
145      */

146     public void removeOperand( Resource res ) {
147         setOperands( getOperands().remove( res ) );
148     }
149     
150     /**
151      * <p>Answer the property that is used to construct this boolean expression, for example
152      * {@link Profile#UNION_OF()}.</p>
153      * @return The property used to construct this Boolean class expression.
154      */

155     public abstract Property operator();
156
157     
158
159     // Internal implementation methods
160
//////////////////////////////////
161

162     /** Answer the name of the operator, so that we can give informative error messages */
163     protected abstract String JavaDoc getOperatorName();
164     
165     
166     //==============================================================================
167
// Inner class definitions
168
//==============================================================================
169

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

202
203
204
Popular Tags