KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * (c) Copyright 2000, 2001, 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  * PropertyImpl.java
28  *
29  * Created on 03 August 2000, 13:47
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 import com.hp.hpl.jena.shared.*;
39
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.logging.LogFactory;
42
43 /** An implementation of Property.
44  *
45  * @author bwm
46  * @version Release='$Name: $' Revision='$Revision: 1.13 $' Date='$Date: 2005/02/21 12:14:48 $'
47  */

48
49 public class PropertyImpl extends ResourceImpl implements Property {
50
51     final static public Implementation factory = new Implementation() {
52         public boolean canWrap( Node n, EnhGraph eg )
53             { return n.isURI(); }
54         public EnhNode wrap(Node n,EnhGraph eg) {
55             return new PropertyImpl(n,eg);
56         }
57     };
58     protected static Log logger = LogFactory.getLog( PropertyImpl.class );
59         
60     protected int ordinal = 0;
61
62     /** Creates new PropertyImpl */
63     public PropertyImpl(String JavaDoc uri) {
64         super( uri );
65         checkLocalName();
66         checkOrdinal();
67     }
68
69     public RDFNode inModel( Model m )
70         { return getModel() == m ? this : m.createProperty( getURI() ); }
71           
72     private void checkLocalName()
73         {
74         String JavaDoc localName = getLocalName();
75         if (localName == null || localName.equals( "" ))
76             throw new InvalidPropertyURIException( getURI() );
77         }
78
79     public PropertyImpl(String JavaDoc nameSpace, String JavaDoc localName)
80        {
81         super(nameSpace, localName);
82         checkLocalName();
83         checkOrdinal();
84     }
85
86     public PropertyImpl(String JavaDoc uri, ModelCom m) {
87         super(uri, m);
88         checkOrdinal();
89     }
90
91     public PropertyImpl(String JavaDoc nameSpace, String JavaDoc localName, ModelCom m)
92        {
93         super(nameSpace, localName, m);
94         checkOrdinal();
95     }
96     
97     public PropertyImpl(Node n, EnhGraph m)
98        {
99         super(n, m);
100         checkOrdinal();
101     }
102
103     public PropertyImpl(String JavaDoc nameSpace,
104                         String JavaDoc localName,
105                         int ordinal,
106                         ModelCom m) {
107         super(nameSpace, localName, m);
108         checkLocalName();
109         this.ordinal = ordinal;
110     }
111
112     public boolean isProperty() {
113         return true;
114     }
115     
116     public int getOrdinal() {
117         return ordinal;
118     }
119
120     protected void checkOrdinal()
121     {
122         char c;
123         String JavaDoc nameSpace = getNameSpace();
124         String JavaDoc localName = getLocalName();
125         // check for an rdf:_xxx property
126
if (localName.length() > 0)
127             {
128             if (localName.charAt(0) == '_' && nameSpace.equals(RDF.getURI())
129                 && nameSpace.equals(RDF.getURI())
130                 && localName.length() > 1
131                 )
132                 {
133                 for (int i=1; i<localName.length(); i++) {
134                     c = localName.charAt(i);
135                     if (c < '0' || c > '9') return;
136                 }
137                 try {
138                   ordinal = Integer.parseInt(localName.substring(1));
139                 } catch (NumberFormatException JavaDoc e) {
140                     logger.error( "checkOrdinal fails on " + localName, e );
141                 }
142             }
143         }
144     }
145
146 }
147
Popular Tags