BrightSide Workbench Full Report + Source Code
XMLSerializer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
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 published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (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 package org.turro.jpa.entity;
19 
20 import java.lang.reflect.Field;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import javax.persistence.Lob;
24 import org.turro.elephant.context.ElephantContext;
25 import org.turro.reflection.Mapping;
26 
31 public class XMLSerializer extends org.turro.reflection.XMLSerializer {
32 
33  public XMLSerializer(Object object) {
34  super(object);
35  }
36 
37  @Override
38  protected boolean acceptObject(Object currentObject) {
39  boolean accept = super.acceptObject(currentObject);
40  //accept = accept && currentObject.getClass().isAnnotationPresent(Entity.class);
41  return accept;
42  }
43 
44  @Override
45  protected String getObjectName(Class clazz) {
46  String name = super.getObjectName(clazz);
47  String s[] = name.split("[^a-zA-Z0-9]");
48  return s.length == 0 ? name : s[0];
49  }
50 
51  @Override
52  protected boolean acceptField(Object currentObject, Field f, Mapping map) {
53  boolean accept = super.acceptField(currentObject, f, map);
54  accept = accept && !f.isAnnotationPresent(Lob.class);
55  //accept = accept && f.getAnnotations() != null;
56  return accept;
57  }
58 
59  @Override
60  protected Class convertClass(Class javaClass) {
61  try {
62  return Class.forName(getClassName(javaClass));
63  } catch (ClassNotFoundException ex) {
64  Logger.getLogger(XMLSerializer.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
65  }
66  return null;
67  }
68 
69  @Override
70  protected String getClassName(Class javaClass) {
71  String name = super.getClassName(javaClass);
72  String s[] = name.split("[^a-zA-Z0-9\\.]");
73  return s.length == 0 ? name : s[0];
74  }
75 
76 }
Class convertClass(Class javaClass)
boolean acceptField(Object currentObject, Field f, Mapping map)
String getClassName(Class javaClass)
boolean acceptObject(Object currentObject)