1 | /** |
---|
2 | * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. |
---|
3 | * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior |
---|
4 | * |
---|
5 | * This program is free software: you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU Affero General Public License as |
---|
7 | * published by the Free Software Foundation, either version 3 of the |
---|
8 | * License, or (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU Affero General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU Affero General Public License |
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | */ |
---|
18 | |
---|
19 | /******************************************************************************\ |
---|
20 | * |
---|
21 | * This product was developed by |
---|
22 | * |
---|
23 | * SERVIÃO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), |
---|
24 | * |
---|
25 | * a government company established under Brazilian law (5.615/70), |
---|
26 | * at Department of Development of Porto Alegre. |
---|
27 | * |
---|
28 | \******************************************************************************/ |
---|
29 | |
---|
30 | package serpro.mailarchiver.domain.metaarchive; |
---|
31 | |
---|
32 | import javax.jdo.annotations.NotPersistent; |
---|
33 | import javax.jdo.annotations.PersistenceCapable; |
---|
34 | |
---|
35 | import org.apache.commons.lang3.exception.ExceptionUtils; |
---|
36 | |
---|
37 | import com.google.common.base.Strings; |
---|
38 | |
---|
39 | import serpro.mailarchiver.domain.BaseObject; |
---|
40 | import serpro.mailarchiver.util.Logger; |
---|
41 | |
---|
42 | @PersistenceCapable |
---|
43 | public abstract class Field |
---|
44 | extends BaseObject |
---|
45 | { |
---|
46 | @NotPersistent |
---|
47 | private static final Logger log = Logger.getLocalLogger(); |
---|
48 | |
---|
49 | //**** P E R S I S T E N T **** |
---|
50 | private String oid; |
---|
51 | private String name; |
---|
52 | private boolean valid = true; |
---|
53 | private String parseExceptionStackTrace; |
---|
54 | private Entity entity; |
---|
55 | private Integer entityIdx; |
---|
56 | //***************************** |
---|
57 | |
---|
58 | public Message getRootMessage() { |
---|
59 | if(getEntity() != null) { |
---|
60 | return getEntity().getRootMessage(); |
---|
61 | } |
---|
62 | return null; |
---|
63 | } |
---|
64 | |
---|
65 | public String getOid() { |
---|
66 | return oid; |
---|
67 | } |
---|
68 | |
---|
69 | public void setOid(String oid) { |
---|
70 | this.oid = oid; |
---|
71 | } |
---|
72 | |
---|
73 | public String getName() { |
---|
74 | return name; |
---|
75 | } |
---|
76 | |
---|
77 | public void setName(String name) { |
---|
78 | this.name = name; |
---|
79 | } |
---|
80 | |
---|
81 | public boolean isValid() { |
---|
82 | return valid; |
---|
83 | } |
---|
84 | |
---|
85 | public void setValid(boolean valid) { |
---|
86 | this.valid = valid; |
---|
87 | } |
---|
88 | |
---|
89 | public String getParseExceptionStackTrace() { |
---|
90 | return parseExceptionStackTrace; |
---|
91 | } |
---|
92 | |
---|
93 | public void setParseExceptionStackTrace(String parseExceptionStackTrace) { |
---|
94 | this.parseExceptionStackTrace = parseExceptionStackTrace; |
---|
95 | } |
---|
96 | |
---|
97 | //-------------------------------------------------------------------------- |
---|
98 | public Entity getEntity() { |
---|
99 | return entity; |
---|
100 | } |
---|
101 | |
---|
102 | public void setEntity(Entity entity) { |
---|
103 | if(this.entity != null) { |
---|
104 | this.entity.internal_removeField(this); |
---|
105 | } |
---|
106 | this.entity = entity; |
---|
107 | if(this.entity != null) { |
---|
108 | this.entity.internal_addField(this); |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | public final int getEntityIdx() { |
---|
113 | return (entityIdx != null) ? entityIdx |
---|
114 | : (getEntity() != null) ? getEntity().indexOf(this) |
---|
115 | : -1; |
---|
116 | } |
---|
117 | |
---|
118 | //-------------------------------------------------------------------------- |
---|
119 | public final String dumpPath() { |
---|
120 | StringBuilder sb = new StringBuilder(); |
---|
121 | dumpPath(sb, true); |
---|
122 | return sb.toString(); |
---|
123 | } |
---|
124 | |
---|
125 | final int dumpPath(StringBuilder sb, boolean quit) { |
---|
126 | int depth = (entity == null) ? 0 : entity.dumpPath(sb, false); |
---|
127 | String pad = Strings.repeat(" ", depth); |
---|
128 | if(quit) { |
---|
129 | sb.append(toString(pad + " ")); |
---|
130 | } |
---|
131 | else { |
---|
132 | sb.append(toString(pad + "| ")).append("\n") |
---|
133 | .append(pad).append("|\n") |
---|
134 | .append(pad).append("+---"); |
---|
135 | } |
---|
136 | return ++depth; |
---|
137 | } |
---|
138 | |
---|
139 | public final String dumpTree() { |
---|
140 | StringBuilder sb = new StringBuilder(); |
---|
141 | dumpTree(sb, ""); |
---|
142 | return sb.toString(); |
---|
143 | } |
---|
144 | |
---|
145 | abstract void dumpTree(StringBuilder sb, String pad); |
---|
146 | |
---|
147 | @Override |
---|
148 | public final String toString() { |
---|
149 | return toString(" "); |
---|
150 | } |
---|
151 | |
---|
152 | abstract String toString(String pad); |
---|
153 | |
---|
154 | //-------------------------------------------------------------------------- |
---|
155 | public void addParseExceptionStackTrace(Throwable t) { |
---|
156 | StringBuilder sb = new StringBuilder(); |
---|
157 | String st = getParseExceptionStackTrace(); |
---|
158 | if(st != null) { |
---|
159 | sb.append(st).append("\n\n"); |
---|
160 | } |
---|
161 | sb.append("######## PARSE EXCEPTION ########\n") |
---|
162 | .append(t.toString()).append("\n\n") |
---|
163 | .append(ExceptionUtils.getStackTrace(t)); |
---|
164 | |
---|
165 | setParseExceptionStackTrace(sb.toString()); |
---|
166 | } |
---|
167 | } |
---|