KickJava   Java API By Example, From Geeks To Geeks.

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


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 01-Apr-2003
9  * Filename $RCSfile: AllDifferentImpl.java,v $
10  * Revision $Revision: 1.16 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:06:14 $
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.*;
31 import com.hp.hpl.jena.ontology.*;
32 import com.hp.hpl.jena.rdf.model.*;
33 import com.hp.hpl.jena.rdf.model.Resource;
34 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
35
36
37 /**
38  * <p>
39  * Implementation of the abstraction of axioms that denote the single name assumption.
40  * </p>
41  *
42  * @author Ian Dickinson, HP Labs
43  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
44  * @version CVS $Id: AllDifferentImpl.java,v 1.16 2005/02/21 12:06:14 andy_seaborne Exp $
45  */

46 public class AllDifferentImpl
47     extends OntResourceImpl
48     implements AllDifferent
49 {
50     // Constants
51
//////////////////////////////////
52

53     // Static variables
54
//////////////////////////////////
55

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

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

82     // Constructors
83
//////////////////////////////////
84

85     /**
86      * <p>
87      * Construct an all different axiom represented by the given node in the given graph.
88      * </p>
89      *
90      * @param n The node that represents the axiom
91      * @param g The enhanced graph that contains n
92      */

93     public AllDifferentImpl( Node n, EnhGraph g ) {
94         super( n, g );
95     }
96
97
98
99     // External signature methods
100
//////////////////////////////////
101

102     /**
103      * <p>Assert that the list of distinct individuals in this AllDifferent declaration
104      * is the given list. Any existing
105      * statements for <code>distinctMembers</code> will be removed.</p>
106      * @param members A list of the members that are declared to be distinct.
107      * @exception OntProfileException If the {@link Profile#DISTINCT_MEMBERS()} property is not supported in the current language profile.
108      */

109     public void setDistinctMembers( RDFList members ) {
110         setPropertyValue( getProfile().DISTINCT_MEMBERS(), "DISTINCT_MEMBERS", members );
111     }
112
113     /**
114      * <p>Add the given individual to the list of distinct members of this AllDifferent declaration.</p>
115      * @param res A resource that will be added to the list of all different members.
116      * @exception OntProfileException If the {@link Profile#DISTINCT_MEMBERS()} property is not supported in the current language profile.
117      */

118     public void addDistinctMember( Resource res ) {
119         addListPropertyValue( getProfile().DISTINCT_MEMBERS(), "DISTINCT_MEMBERS", res );
120     }
121
122     /**
123      * <p>Add the given individuals to the list of distinct members of this AllDifferent declaration.</p>
124      * @param individuals An iterator over the distinct invididuals that will be added
125      * @exception OntProfileException If the {@link Profile#DISTINCT_MEMBERS()} property is not supported in the current language profile.
126      */

127     public void addDistinctMembers( Iterator JavaDoc individuals ) {
128         while (individuals.hasNext()) {
129             addDistinctMember( (Resource) individuals.next() );
130         }
131     }
132
133     /**
134      * <p>Answer the list of distinct members for this AllDifferent declaration.</p>
135      * @return The list of individuals declared distinct by this AllDifferent declaration.
136      * @exception OntProfileException If the {@link Profile#DISTINCT_MEMBERS()} property is not supported in the current language profile.
137      */

138     public RDFList getDistinctMembers() {
139         return (RDFList) objectAs( getProfile().DISTINCT_MEMBERS(), "DISTINCT_MEMBERS", RDFList.class );
140     }
141
142     /**
143      * <p>Answer an iterator over all of the individuals that are declared to be distinct by
144      * this AllDifferent declaration. Each element of the iterator will be an {@link OntResource}.</p>
145      * @return An iterator over distinct individuals.
146      * @exception OntProfileException If the {@link Profile#DISTINCT_MEMBERS()} property is not supported in the current language profile.
147      */

148     public ExtendedIterator listDistinctMembers() {
149         return getDistinctMembers().iterator();
150     }
151
152     /**
153      * <p>Answer true if this AllDifferent declaration includes <code>res</code> as one of the distinct individuals.</p>
154      * @param res A resource to test against
155      * @return True if <code>res</code> is declared to be distinct from the other individuals in this declation.
156      * @exception OntProfileException If the {@link Profile#DISTINCT_MEMBERS()} property is not supported in the current language profile.
157      */

158     public boolean hasDistinctMember( Resource res ) {
159         return getDistinctMembers().contains( res );
160     }
161     
162     /**
163      * <p>Remove the given resource from the list of distinct individuals. If this statement
164      * is not true of the current model, nothing happens.</p>
165      * @param res A resource that is no longer distinct from the other listed individuals
166      */

167     public void removeDistinctMember( Resource res ) {
168         setDistinctMembers( getDistinctMembers().remove( res ) );
169     }
170     
171
172
173     // Internal implementation methods
174
//////////////////////////////////
175

176     //==============================================================================
177
// Inner class definitions
178
//==============================================================================
179

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

212
213
Popular Tags