Revision 17705 branches/v10/extensions/extPublish/src/org/gvsig/publish/serversmodel/RemoteResource.java
RemoteResource.java | ||
---|---|---|
48 | 48 |
import org.gvsig.publish.PublishLogger; |
49 | 49 |
import org.gvsig.publish.PublishRegister; |
50 | 50 |
import org.gvsig.publish.infoproject.ILayerInfo; |
51 |
import org.gvsig.publish.infoproject.IProjectInfo;
|
|
51 |
import org.gvsig.publish.infoproject.ProjectInfoFactory;
|
|
52 | 52 |
|
53 |
import com.iver.utiles.IPersistance; |
|
53 | 54 |
import com.iver.utiles.XMLEntity; |
54 | 55 |
|
55 | 56 |
/** |
... | ... | |
58 | 59 |
* @author Jos? Vicente Hig?n (josevicente.higon@iver.es) |
59 | 60 |
* |
60 | 61 |
*/ |
61 |
public abstract class RemoteResource { |
|
62 |
public abstract class RemoteResource implements IPersistance { |
|
63 |
public static final String REMOTERESOURCE_TYPE_KEY = "Type"; |
|
64 |
|
|
62 | 65 |
/* |
63 |
* Constants |
|
64 |
*/ |
|
65 |
public static final String REMOTE_RESOURCE_TYPE_PROPERTIE="remoteresourceType"; |
|
66 |
public static final String REMOTE_RESOURCE_TITLE_PROPERTIE="remoteresourceTitle"; |
|
67 |
/* |
|
68 | 66 |
* Hashmap with its childs |
69 | 67 |
*/ |
70 | 68 |
private LinkedHashMap childs = null; |
... | ... | |
127 | 125 |
} |
128 | 126 |
/** |
129 | 127 |
* |
130 |
* @return the layer which represents this remote resource |
|
128 |
* @return the layer which represents this remote resource. I can be null if the remote resource has not a layerinfo associated. |
|
129 |
* |
|
131 | 130 |
*/ |
132 |
protected ILayerInfo getLayerInfo(){
|
|
131 |
public ILayerInfo getLayerInfo(){
|
|
133 | 132 |
return this.layerInfo; |
134 | 133 |
} |
135 | 134 |
/** |
... | ... | |
201 | 200 |
// PublishLogger.getLog().warn("WARNING RemoteResource: the getLayers in " + layer.getTitle() + " is null"); |
202 | 201 |
// } |
203 | 202 |
} |
203 |
|
|
204 | 204 |
/** |
205 | 205 |
* Puts all the properties into a XML in order to persist it |
206 | 206 |
* |
... | ... | |
208 | 208 |
*/ |
209 | 209 |
public XMLEntity getXMLEntity() { |
210 | 210 |
XMLEntity xml=new XMLEntity(); |
211 |
//Add properties |
|
212 |
xml.putProperty("className", RemoteResource.class.getName()); |
|
213 |
xml.putProperty(REMOTE_RESOURCE_TYPE_PROPERTIE, getType()); |
|
214 |
xml.putProperty(REMOTE_RESOURCE_TITLE_PROPERTIE, getTitle()); |
|
215 |
//Add ILayerInfo |
|
216 |
xml.addChild(getLayerInfo().getXMLEntity()); |
|
217 |
//TODO: Add childs |
|
211 |
//The version must be put by the extended classes |
|
212 |
//xml.putProperty("className", getClassName()); |
|
213 |
//put properties |
|
214 |
xml.putProperty(REMOTERESOURCE_TYPE_KEY, getType()); |
|
215 |
xml.putProperty("title", getTitle()); |
|
216 |
//put associations |
|
217 |
XMLEntity xmlLayerInfo = new XMLEntity(); |
|
218 |
xmlLayerInfo.putProperty("role", "ilayerinfo"); |
|
219 |
xmlLayerInfo.addChild(getLayerInfo().getXMLEntity()); |
|
220 |
xml.addChild(xmlLayerInfo); |
|
221 |
//to put children I create a new tag |
|
222 |
XMLEntity children=new XMLEntity(); |
|
223 |
children.putProperty("role", "children" ); |
|
218 | 224 |
for (int i = 0; i< getChildsCount(); i++){ |
219 | 225 |
RemoteResource child = getChild(i); |
220 |
xml.addChild(child.getXMLEntity());
|
|
226 |
children.addChild(child.getXMLEntity());
|
|
221 | 227 |
} |
228 |
xml.addChild(children); |
|
222 | 229 |
return xml; |
223 | 230 |
} |
224 | 231 |
/** |
... | ... | |
227 | 234 |
*/ |
228 | 235 |
public void setXMLEntity(XMLEntity xml) { |
229 | 236 |
|
230 |
//Set properties (REMOTE_RESOURCE_TITLE_PROPERTIE ...) |
|
231 |
setTitle(xml.getStringProperty(RemoteResource.REMOTE_RESOURCE_TITLE_PROPERTIE)); |
|
232 |
//Sets ILayerInfo. I use firstChild() because only one LayerInfo by RemoteResource is defined |
|
233 |
XMLEntity xmlLayerInfo = xml.firstChild("className", ILayerInfo.class.getName()); |
|
234 |
//TODO: change "layerName" by ILayerInfo.LAYERNAME_PROPERTIE |
|
235 |
String layerName = xmlLayerInfo.getStringProperty("layerName"); |
|
236 |
IProjectInfo info = getService().getServer().getProjectInfo(); |
|
237 |
layerInfo = info.findLayer(layerName); |
|
238 |
layerInfo.setXMLEntity(xmlLayerInfo); |
|
239 |
//Set childs |
|
240 |
Iterator i = xml.findChildren("className", RemoteResource.class.getName()); |
|
241 |
while (i.hasNext()){ |
|
242 |
XMLEntity child = (XMLEntity) i.next(); |
|
243 |
RemoteResource r = PublishRegister.register().getRemoteResource(getService(), child.getStringProperty(RemoteResource.REMOTE_RESOURCE_TYPE_PROPERTIE)); |
|
237 |
//Set properties |
|
238 |
setTitle(xml.getStringProperty("title")); |
|
239 |
//set associations |
|
240 |
XMLEntity xmlLayerInfo = xml.firstChild("role","ilayerinfo"); |
|
241 |
Object o = ProjectInfoFactory.createFromXML(xmlLayerInfo.getChild(0)); |
|
242 |
layerInfo = (ILayerInfo)o; |
|
243 |
|
|
244 |
XMLEntity children = xml.firstChild("role", "children"); |
|
245 |
for (int i=0; i<children.getChildrenCount(); i++){ |
|
246 |
XMLEntity child = children.getChild(i); |
|
247 |
RemoteResource r = PublishRegister.register().getRemoteResource(getService(), child.getStringProperty("type")); |
|
244 | 248 |
if (r == null){ |
245 | 249 |
PublishLogger.getLog().error("ERROR RemoteResource: I can't create a child from persistence"); |
246 | 250 |
} |
247 | 251 |
r.setXMLEntity(child); |
248 | 252 |
addChild(r); |
249 |
System.err.println("Toma child !! " + getLayerInfo().getName()); |
|
250 | 253 |
} |
251 | 254 |
} |
252 | 255 |
|
Also available in: Unified diff