01: /*
02: * Copyright 2006 Giordano Maestro (giordano.maestro@assetdata.it) Licensed
03: * under the Apache License, Version 2.0 (the "License"); you may not use this
04: * file except in compliance with the License. You may obtain a copy of the
05: * License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
06: * applicable law or agreed to in writing, software distributed under the
07: * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
08: * OF ANY KIND, either express or implied. See the License for the specific
09: * language governing permissions and limitations under the License.
10: */
11: package org.romaframework.module.designer.serializer.xml;
12:
13: import java.util.Iterator;
14: import java.util.Map;
15: import org.apache.xmlbeans.XmlObject;
16: import org.romaframework.aspect.view.echo2.area.AreaInstance;
17: import org.romaframework.core.serializer.RomaObjectSerializer;
18: import org.romaframework.core.serializer.RomaSerializationException;
19: import org.romaframework.core.serializer.RomaSerializerComponent;
20: import org.romaframework.xml.config.XmlConfigAreaType;
21:
22: class AreaInstanceSerializerXml extends RomaObjectSerializer {
23: protected final static AreaInstanceSerializerXml instance = new AreaInstanceSerializerXml();
24: protected final static String PLACEHOLDER = "placeholder";
25:
26: public static RomaObjectSerializer getInstace() {
27: return instance;
28: }
29:
30: AreaInstanceSerializerXml() {
31: }
32:
33: @Override
34: public XmlObject serialize(Object iContainer)
35: throws RomaSerializationException {
36: AreaInstance container = (AreaInstance) iContainer;
37: XmlConfigAreaType areaNode = XmlConfigAreaType.Factory
38: .newInstance();
39: areaNode.setName(container.getRootArea().getName());
40: if (container.getRootArea().getAreaSize() != null) {
41: areaNode.setSize(container.getRootArea().getAreaSize());
42: }
43: if (container.getAreaMode() != null
44: && !container.getAreaMode().toString().equals(
45: PLACEHOLDER)) {
46: areaNode.setType(container.getAreaMode().toString());
47: }
48: if (container.getRootArea().getChildren() != null) {
49: Iterator childsIterator = container.getRootArea()
50: .getChildren().iterator();
51: while (childsIterator.hasNext()) {
52: Object child = childsIterator.next();
53: areaNode.addNewArea().set(
54: RomaSerializerComponent.getInstance()
55: .serialize(child));
56: }
57: }
58: return areaNode;
59: }
60:
61: @Override
62: public XmlObject serialize(Object iToSerialize,
63: Map<String, Object> options)
64: throws RomaSerializationException {
65: return serialize(iToSerialize);
66: }
67: }
|