1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.synchronoss.cpo.exporter;
22
23 import org.synchronoss.cpo.MetaVisitor;
24 import org.synchronoss.cpo.core.cpoCoreMeta.*;
25 import org.synchronoss.cpo.meta.CpoMetaDescriptor;
26 import org.synchronoss.cpo.meta.domain.*;
27
28
29
30
31
32
33
34 public class CoreMetaXmlObjectExporter implements MetaXmlObjectExporter, MetaVisitor {
35
36 protected CpoMetaDataDocument cpoMetaDataDocument = null;
37 protected CtClass currentCtClass;
38 protected CtFunctionGroup currentCtFunctionGroup;
39 protected CtFunction currentCtFunction;
40
41 public CoreMetaXmlObjectExporter(CpoMetaDescriptor metaDescriptor) {
42 cpoMetaDataDocument = CpoMetaDataDocument.Factory.newInstance();
43 CtCpoMetaData ctCpoMetaData = cpoMetaDataDocument.addNewCpoMetaData();
44 ctCpoMetaData.setMetaDescriptor(metaDescriptor.getClass().getName());
45 ctCpoMetaData.setDefaultPackageName(metaDescriptor.getDefaultPackageName());
46 }
47
48 @Override
49 public CpoMetaDataDocument getCpoMetaDataDocument() {
50 return cpoMetaDataDocument;
51 }
52
53 @Override
54 public void visit(CpoClass cpoClass) {
55 CtClass ctClass = cpoMetaDataDocument.getCpoMetaData().addNewCpoClass();
56 ctClass.setName(cpoClass.getName());
57
58 if (cpoClass.getDescription() != null && cpoClass.getDescription().length() > 0) {
59 ctClass.setDescription(cpoClass.getDescription());
60 }
61
62
63 currentCtClass = ctClass;
64 }
65
66 @Override
67 public void visit(CpoAttribute cpoAttribute) {
68 if (currentCtClass != null) {
69 CtAttribute ctAttribute = currentCtClass.addNewCpoAttribute();
70
71 ctAttribute.setJavaName(cpoAttribute.getJavaName());
72 ctAttribute.setJavaType(cpoAttribute.getJavaType());
73 ctAttribute.setDataName(cpoAttribute.getDataName());
74 ctAttribute.setDataType(cpoAttribute.getDataType());
75
76 if (cpoAttribute.getTransformClassName() != null && cpoAttribute.getTransformClassName().length() > 0) {
77 ctAttribute.setTransformClass(cpoAttribute.getTransformClassName());
78 }
79
80 if (cpoAttribute.getDescription() != null && cpoAttribute.getDescription().length() > 0) {
81 ctAttribute.setDescription(cpoAttribute.getDescription());
82 }
83 }
84 }
85
86 @Override
87 public void visit(CpoFunctionGroup cpoFunctionGroup) {
88 if (currentCtClass != null) {
89 CtFunctionGroup ctFunctionGroup = currentCtClass.addNewCpoFunctionGroup();
90
91 if (cpoFunctionGroup.getName() != null && cpoFunctionGroup.getName().length() > 0) {
92 ctFunctionGroup.setName(cpoFunctionGroup.getName());
93 }
94
95 ctFunctionGroup.setType(StFunctionGroupType.Enum.forString(cpoFunctionGroup.getType()));
96
97 if (cpoFunctionGroup.getDescription() != null && cpoFunctionGroup.getDescription().length() > 0) {
98 ctFunctionGroup.setDescription(cpoFunctionGroup.getDescription());
99 }
100
101
102 currentCtFunctionGroup = ctFunctionGroup;
103 }
104 }
105
106 @Override
107 public void visit(CpoFunction cpoFunction) {
108 if (currentCtFunctionGroup != null) {
109 CtFunction ctFunction = currentCtFunctionGroup.addNewCpoFunction();
110
111 ctFunction.setName(cpoFunction.getName());
112 ctFunction.setExpression(cpoFunction.getExpression());
113
114 if (cpoFunction.getDescription() != null && cpoFunction.getDescription().length() > 0) {
115 ctFunction.setDescription(cpoFunction.getDescription());
116 }
117
118
119 currentCtFunction = ctFunction;
120 }
121 }
122
123 @Override
124 public void visit(CpoArgument cpoArgument) {
125 if (currentCtFunction != null) {
126 CtArgument ctArgument = currentCtFunction.addNewCpoArgument();
127
128 ctArgument.setAttributeName(cpoArgument.getAttribute().getJavaName());
129
130 if (cpoArgument.getDescription() != null && cpoArgument.getDescription().length() > 0) {
131 ctArgument.setDescription(cpoArgument.getDescription());
132 }
133 }
134 }
135 }