Commit 9a6720855d6044552ade1b0e26aa985c6362734b

Renamed API06XMLObject to API06XMLItem
  
115115 {
116116 for(T cachedEnt : cached.values())
117117 {
118 if(cachedEnt instanceof API06XMLObject)
119 ((API06XMLObject)cachedEnt).setAPI(getAPI());
118 if(cachedEnt instanceof API06XMLItem)
119 ((API06XMLItem)cachedEnt).setAPI(getAPI());
120120 }
121121 return cached;
122122 }
140140 T cached = getCache().getObject(a_id, a_version);
141141 if(cached != null)
142142 {
143 if(cached instanceof API06XMLObject)
144 ((API06XMLObject)cached).setAPI(getAPI());
143 if(cached instanceof API06XMLItem)
144 ((API06XMLItem)cached).setAPI(getAPI());
145145 return cached;
146146 }
147147
  
3434 * Parent class for all geographical objects in OSM, currently Nodes, Ways and Relations.
3535*/
3636
37abstract public class API06Item extends API06XMLObject implements Item
37abstract public class API06Item extends API06XMLItem implements Item
3838{
3939 private Hashtable<String,String> m_tags = null;
4040
  
8484 toFetch.add(id);
8585 else
8686 {
87 if(cached instanceof API06XMLObject)
88 ((API06XMLObject)cached).setAPI(getAPI());
87 if(cached instanceof API06XMLItem)
88 ((API06XMLItem)cached).setAPI(getAPI());
8989 ret.put(id, cached);
9090 }
9191 }
  
3030import eu.cdauth.osm.lib.RelationMember;
3131import eu.cdauth.osm.lib.Way;
3232
33public class API06RelationMember extends API06XMLObject implements RelationMember
33public class API06RelationMember extends API06XMLItem implements RelationMember
3434{
3535 private Relation m_relation; // Not final because of serialization
3636
  
1/*
2 Copyright © 2010 Candid Dauth
3
4 Permission is hereby granted, free of charge, to any person obtaining
5 a copy of this software and associated documentation files (the “Software”),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and/or sell copies of the Software, and to permit persons to whom the Software
9 is furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20*/
21
22package eu.cdauth.osm.lib.api06;
23
24import org.w3c.dom.Element;
25import org.w3c.dom.bootstrap.DOMImplementationRegistry;
26import org.w3c.dom.ls.DOMImplementationLS;
27import org.w3c.dom.ls.LSInput;
28import org.w3c.dom.ls.LSParser;
29import org.w3c.dom.ls.LSSerializer;
30
31import java.io.*;
32
33/**
34 * Abstract class for all objects whose information is saved in an XML DOM element.
35 */
36abstract public class API06XMLObject implements Externalizable
37{
38 /** The DOM element containing the API XML response for this object. */
39 private Element m_dom;
40
41 private transient API06API m_api;
42
43 /**
44 * Only for serialization.
45 */
46 @Deprecated
47 public API06XMLObject()
48 {
49 }
50
51 /**
52 * @param a_dom The DOM element.
53 * @param a_api The API that creates this object.
54 */
55
56 protected API06XMLObject(Element a_dom, API06API a_api)
57 {
58 m_dom = a_dom;
59 m_api = a_api;
60 }
61
62 protected void setAPI(API06API a_api)
63 {
64 m_api = a_api;
65 }
66
67 /**
68 * @return The DOM element.
69 */
70
71 protected Element getDOM()
72 {
73 return m_dom;
74 }
75
76 protected API06API getAPI()
77 {
78 return m_api;
79 }
80
81 @Override
82 public void writeExternal(ObjectOutput out) throws IOException
83 {
84 String str = "";
85 if(m_dom != null)
86 {
87 try {
88 DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
89 DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
90 LSSerializer writer = impl.createLSSerializer();
91 str = writer.writeToString(m_dom);
92 } catch(Exception e) {
93 if(e instanceof IOException)
94 throw (IOException)e;
95 else
96 throw new IOException(e);
97 }
98 }
99 out.writeObject(str);
100 }
101
102 @Override
103 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
104 {
105 String str = (String)in.readObject();
106 if(!str.equals(""))
107 {
108 try {
109 DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
110 DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
111 LSParser parser = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
112 LSInput input = impl.createLSInput();
113 input.setStringData(str);
114 m_dom = (Element)parser.parse(input).getFirstChild();
115 } catch(Exception e) {
116 if(e instanceof IOException)
117 throw (IOException)e;
118 else
119 throw new IOException(e);
120 }
121 }
122 }
123}