1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.sail.core.curnit;
24
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27
28 import java.beans.Expression;
29 import java.beans.Statement;
30 import java.io.OutputStream;
31
32 import net.sf.sail.core.beans.Pod;
33
34
35
36
37
38
39
40 public class PodXMLEncoder extends SAILXMLEncoder {
41
42
43
44 private static final Logger logger = Logger.getLogger(PodXMLEncoder.class
45 .getName());
46
47 private Pod pod;
48
49 public PodXMLEncoder(Pod pod, OutputStream out) {
50 super(out);
51 this.pod = pod;
52 }
53
54 public void writePod() {
55 if (logger.isLoggable(Level.FINE)) {
56 logger.fine("n===WRITING POD: " + pod);
57 }
58 writeObject(pod);
59 }
60
61 @Override
62 public void writeExpression(Expression oldExp) {
63 Object expValue = null;
64 try {
65 expValue = oldExp.getValue();
66 } catch (Exception e) {
67
68 logger.warning("exception: " + e);
69 }
70 if (logger.isLoggable(Level.FINER)) {
71 logger.finer("expr: " + oldExp + " has value " + expValue);
72 }
73 if (expValue instanceof Curnit) {
74 if (logger.isLoggable(Level.FINER)) {
75 logger
76 .finer("\\ skipping above because pods can't reference curnits");
77 }
78 return;
79 }
80 if (pod.isTransient(expValue)) {
81 if (logger.isLoggable(Level.FINER)) {
82 logger.finer("\\ skipping above because pod imports the value");
83 }
84 return;
85 }
86 super.writeExpression(oldExp);
87 }
88
89 @Override
90 public void writeStatement(Statement stm) {
91 if (logger.isLoggable(Level.FINEST)) {
92 logger.finest(pod + " " + stm);
93 }
94
95 Object target = stm.getTarget();
96 Object[] arguments = stm.getArguments();
97
98 if (target instanceof Pod && target != pod) {
99 if (logger.isLoggable(Level.FINEST)) {
100 logger.finest("ttskipped (target is different pod)");
101 }
102 return;
103 }
104
105
106 Object value = arguments[0];
107
108 if (value instanceof Pod && value != pod) {
109 if (logger.isLoggable(Level.FINEST)) {
110 logger.finest("ttskipped (value is different pod)");
111 }
112 return;
113 }
114
115 if (pod.isTransient(value)) {
116 if (logger.isLoggable(Level.FINEST)) {
117 logger.finest("ttskipped (value is transient in this pod)");
118 }
119 return;
120 }
121
122 if (logger.isLoggable(Level.FINEST)) {
123 logger.finest("");
124 }
125
126 super.writeStatement(stm);
127 }
128
129 }