KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > impl > AltImpl


1 /*
2  * (c) Copyright 2000, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * AltImpl.java
28  *
29  * Created on 08 August 2000, 16:39
30  */

31
32 package com.hp.hpl.jena.rdf.model.impl;
33
34 import com.hp.hpl.jena.rdf.model.*;
35 import com.hp.hpl.jena.vocabulary.RDF;
36 import com.hp.hpl.jena.graph.*;
37 import com.hp.hpl.jena.enhanced.*;
38
39 /** An implementation of Alt.
40  *
41  * @author bwm
42  * @version Release='$Name: $' Revision='$Revision: 1.15 $' Date='$Date: 2005/03/17 13:52:57 $'
43  */

44 public class AltImpl extends ContainerImpl implements Alt {
45     
46     final static public Implementation factory = new Implementation() {
47         public boolean canWrap( Node n, EnhGraph eg )
48             { return true; }
49         public EnhNode wrap(Node n,EnhGraph eg) {
50             return new AltImpl(n,eg);
51         }
52     };
53     
54     /** Creates new AltMem */
55     public AltImpl( ModelCom model )
56         { super( model ); }
57     
58     public AltImpl( String JavaDoc uri, ModelCom model ) {
59         super( uri, model );
60     }
61     
62     public AltImpl( Resource r, ModelCom m ) {
63         super( r, m );
64     }
65     
66     public AltImpl(Node n, EnhGraph g) {
67         super( n, g );
68     }
69     
70     /** get the default statement, explode if there isn't one */
71     
72     private Statement needDefaultStatement()
73         {
74         Statement stmt = getDefaultStatement();
75         if (stmt == null) throw new AltHasNoDefaultException( this );
76         return stmt;
77         }
78         
79     public RDFNode getDefault() {
80         return needDefaultStatement().getObject();
81     }
82     
83     public Resource getDefaultResource() {
84         return needDefaultStatement().getResource();
85     }
86     
87     public Literal getDefaultLiteral() {
88         return needDefaultStatement().getLiteral();
89     }
90     
91     public boolean getDefaultBoolean() {
92         return needDefaultStatement().getBoolean();
93     }
94     
95     public byte getDefaultByte() {
96         return needDefaultStatement().getByte();
97     }
98     
99     public short getDefaultShort() {
100         return needDefaultStatement().getShort();
101     }
102     
103     public int getDefaultInt() {
104         return needDefaultStatement().getInt();
105     }
106     
107     public long getDefaultLong() {
108         return needDefaultStatement().getLong();
109     }
110     
111     public char getDefaultChar() {
112         return needDefaultStatement().getChar();
113     }
114     
115     public float getDefaultFloat() {
116         return needDefaultStatement().getFloat();
117     }
118     
119     public double getDefaultDouble() {
120         return needDefaultStatement().getDouble();
121     }
122     
123     public String JavaDoc getDefaultString() {
124         return needDefaultStatement().getString();
125     }
126     
127     public String JavaDoc getDefaultLanguage() {
128         return needDefaultStatement().getLanguage();
129     }
130     
131     public Resource getDefaultResource(ResourceF f) {
132         return needDefaultStatement().getResource();
133     }
134     
135     public Object JavaDoc getDefaultObject(ObjectF f) {
136         return needDefaultStatement().getObject( f );
137     }
138     
139     public Alt getDefaultAlt() {
140         return needDefaultStatement().getAlt();
141     }
142     
143     public Bag getDefaultBag() {
144         return needDefaultStatement().getBag();
145     }
146     
147     public Seq getDefaultSeq() {
148         return needDefaultStatement().getSeq();
149     }
150     
151     public Alt setDefault(RDFNode o) {
152         Statement stmt = getDefaultStatement();
153         if (stmt != null) getModel().remove( stmt );
154         getModel().add( this, RDF.li(1), o );
155         return this;
156     }
157     
158     public Alt setDefault(boolean o) {
159         return setDefault( String.valueOf( o ) );
160     }
161     
162     public Alt setDefault(long o) {
163         return setDefault( String.valueOf( o ) );
164     }
165     
166     public Alt setDefault(char o) {
167         return setDefault( String.valueOf( o ) );
168     }
169     
170     public Alt setDefault(float o) {
171         return setDefault( String.valueOf( o ) );
172     }
173     
174     public Alt setDefault(double o) {
175         return setDefault( String.valueOf( o ) );
176     }
177     
178     public Alt setDefault(Object JavaDoc o) {
179         return setDefault( String.valueOf( o ) );
180     }
181    
182     public Alt setDefault(String JavaDoc o) {
183         return setDefault( o, "" );
184     }
185     
186     public Alt setDefault(String JavaDoc o, String JavaDoc l) {
187         return setDefault( new LiteralImpl( Node.createLiteral( o,l, false ), getModelCom()) );
188     }
189         
190     protected Statement getDefaultStatement()
191         {
192         StmtIterator iter = getModel().listStatements( this, RDF.li(1), (RDFNode) null );
193         try { return iter.hasNext() ? iter.nextStatement() : null; }
194         finally { iter.close(); }
195         }
196
197 }
Popular Tags