KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > db > impl > DBPrefixMappingImpl


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: DBPrefixMappingImpl.java,v 1.10 2005/02/21 12:02:45 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.db.impl;
8
9 import com.hp.hpl.jena.shared.PrefixMapping;
10 import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;
11
12 import java.util.*;
13
14 /**
15  * Implementation of prefix mapping specific to databases.
16  * This extends the base implementation, effectively turning it into
17  * a write-through cache - each new namespace is written to
18  * the database as it is added to the prefix map.
19  *
20  *
21     @author csayers
22     @version $Revision: 1.10 $
23 */

24 public class DBPrefixMappingImpl extends PrefixMappingImpl {
25
26     protected DBPropGraph m_graphProperties = null;
27     
28     /**
29      * Constructor for a persistent prefix mapping.
30      *
31      * Each GraphRDB has a set of associated properties
32      * which are, themselves, represented as triples in
33      * a system graph.
34      *
35      * The prefix mapping is persisted by converting it
36      * to triples and storing it along with the other
37      * properties of the GraphRDB in that system graph.
38      *
39      * @param graphProperties the system properties of a persistent graph.
40      */

41     public DBPrefixMappingImpl( DBPropGraph graphProperties) {
42         super();
43         m_graphProperties = graphProperties;
44         
45         // Populate the prefix map using data from the
46
// persistent graph properties
47
Iterator it = m_graphProperties.getAllPrefixes();
48         while( it.hasNext()) {
49             DBPropPrefix prefix = (DBPropPrefix)it.next();
50             super.setNsPrefix( prefix.getValue(), prefix.getURI() );
51         }
52     }
53
54     public PrefixMapping removeNsPrefix( String JavaDoc prefix )
55         {
56         String JavaDoc uri = getNsPrefixURI( prefix );
57         super.removeNsPrefix( prefix );
58         if (uri != null) m_graphProperties.removePrefix( prefix );
59         return this;
60         }
61     
62     /* (non-Javadoc)
63      * Override the default implementation so we can catch the write operation
64      * and update the persistent store.
65      * @see com.hp.hpl.jena.shared.PrefixMapping#setNsPrefix(java.lang.String, java.lang.String)
66      */

67     public PrefixMapping setNsPrefix(String JavaDoc prefix, String JavaDoc uri) {
68         // this avoids touching the database for existing maplets.
69
// if (uri.equals( super.getNsPrefixURI( prefix ) )) return this;
70
// Ordering is important here - we need to add it to the prefixMappingImpl
71
// first since it checks the validity of the prefix (it will throw
72
// an exception if there's any problem).
73
super.setNsPrefix(prefix, uri);
74         
75         // All went well, so persist the prefix by adding it to the graph properties
76
// (the addPrefix call will overwrite any existing mapping with the same prefix
77
// so it matches the behaviour of the prefixMappingImpl).
78
m_graphProperties.addPrefix(prefix, uri);
79         return this;
80     }
81
82     /* (non-Javadoc)
83      * Override the default implementation so we can catch all write operations
84      * @see com.hp.hpl.jena.shared.PrefixMapping#setNsPrefixes(com.hp.hpl.jena.shared.PrefixMapping)
85      */

86     public PrefixMapping setNsPrefixes(PrefixMapping other) {
87         return setNsPrefixes(other.getNsPrefixMap());
88     }
89
90     /* (non-Javadoc)
91      * Override the default implementation so we can catch all write operations
92      * @see com.hp.hpl.jena.shared.PrefixMapping#setNsPrefixes(java.util.Map)
93      */

94     public PrefixMapping setNsPrefixes(Map other) {
95         checkUnlocked();
96         Iterator it = other.entrySet().iterator();
97         while (it.hasNext()) {
98             Map.Entry e = (Map.Entry) it.next();
99             setNsPrefix((String JavaDoc) e.getKey(), (String JavaDoc) e.getValue());
100         }
101         return this;
102     }
103 }
104
105 /*
106     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
107     All rights reserved.
108
109     Redistribution and use in source and binary forms, with or without
110     modification, are permitted provided that the following conditions
111     are met:
112
113     1. Redistributions of source code must retain the above copyright
114        notice, this list of conditions and the following disclaimer.
115
116     2. Redistributions in binary form must reproduce the above copyright
117        notice, this list of conditions and the following disclaimer in the
118        documentation and/or other materials provided with the distribution.
119
120     3. The name of the author may not be used to endorse or promote products
121        derived from this software without specific prior written permission.
122
123     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
124     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
125     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
126     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
127     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
128     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
129     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
130     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
131     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
132     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
133 */
Popular Tags