KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > ontology > daml > impl > LiteralAccessorImpl


1 /*****************************************************************************
2  * Source code information
3  * -----------------------
4  * Original author Ian Dickinson, HP Labs Bristol
5  * Author email Ian.Dickinson@hp.com
6  * Package Jena
7  * Created 26 Jan 2001
8  * Filename $RCSfile: LiteralAccessorImpl.java,v $
9  * Revision $Revision: 1.8 $
10  * Release status Preview-release $State: Exp $
11  *
12  * Last modified on $Date: 2005/02/21 12:05:30 $
13  * by $Author: andy_seaborne $
14  *
15  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
16  * (see footer for full conditions)
17  *****************************************************************************/

18
19 // Package
20
///////////////
21
package com.hp.hpl.jena.ontology.daml.impl;
22
23
24 // Imports
25
///////////////
26
import com.hp.hpl.jena.ontology.*;
27 import com.hp.hpl.jena.ontology.daml.*;
28 import com.hp.hpl.jena.rdf.model.*;
29
30
31
32 /**
33  * <p>Encapsulates the standard methods of modifying a property on a DAML object, where
34  * the value of the property is an RDF literal (as opposed to another DAML value,
35  * see {@link PropertyAccessor}.<p>
36  *
37  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
38  * @version CVS info: $Id: LiteralAccessorImpl.java,v 1.8 2005/02/21 12:05:30 andy_seaborne Exp $
39  */

40 public class LiteralAccessorImpl
41     extends PropertyAccessorImpl
42     implements LiteralAccessor
43 {
44     // Constants
45
//////////////////////////////////
46

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

51
52     // Instance variables
53
//////////////////////////////////
54

55
56     // Constructors
57
//////////////////////////////////
58

59     /**
60      * <p>Construct a new accessor for literal values of the given property.</p>
61      *
62      * @param property The property that this accessor works on
63      * @param val The DAML value that has this property
64      */

65     public LiteralAccessorImpl( Property property, OntResource val ) {
66         super( property, val );
67     }
68
69
70
71     // External signature methods
72
//////////////////////////////////
73

74     /**
75      * <p>Answer the value of the encapsulated property. If it has no values, answer
76      * null. If it has one value, answer that value. Otherwise, answer an undetermined
77      * member of the set of values.<p>
78      *
79      * @return The literal value of the encapsulated property, or null.
80      */

81     public Literal getValue() {
82         NodeIterator i = null;
83         try {
84             i = getAll();
85             return (i == null || !i.hasNext()) ? null : ((Literal) i.nextNode());
86         }
87         finally {
88             if (i != null) {
89                 i.close();
90             }
91         }
92     }
93
94
95     /**
96      * <p>Add a value to the encapsulated property.</p>
97      *
98      * @param value The value to be added, as a string.
99      */

100     public void addValue( String JavaDoc value ) {
101         add( m_val.getModel().createLiteral( value ) );
102     }
103
104
105     /**
106      * <p>Remove a value from the encapsulated property.</p>
107      *
108      * @param value The value to be removed, as a string.
109      */

110     public void removeValue( String JavaDoc value ) {
111         remove( m_val.getModel().createLiteral( value ) );
112     }
113
114
115     /**
116      * <p>Answer true if the encapsulated property has the given value as one of its
117      * values.</p>
118      *
119      * @param value A String value to test for
120      * @return True if the RDF model contains a statement giving a value for
121      * the encapsulated property matching the given value.
122      */

123     public boolean hasValue( String JavaDoc value ) {
124         return hasValue( m_val.getModel().createLiteral( value ) );
125     }
126
127
128
129     // Internal implementation methods
130
//////////////////////////////////
131

132
133
134     //==============================================================================
135
// Inner class definitions
136
//==============================================================================
137

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

170
171
Popular Tags