1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.exolab.castor.builder.conflictresolution;
15
16 import java.util.Enumeration;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.exolab.castor.builder.SGStateInfo;
21 import org.exolab.castor.builder.binding.XPathHelper;
22 import org.exolab.castor.builder.info.ClassInfo;
23 import org.exolab.castor.builder.info.nature.XMLInfoNature;
24 import org.exolab.castor.util.dialog.ConsoleDialog;
25 import org.exolab.castor.xml.schema.Annotated;
26 import org.exolab.castor.xml.schema.ElementDecl;
27 import org.exolab.castor.xml.schema.SchemaNames;
28 import org.exolab.javasource.JClass;
29
30
31
32
33
34
35
36
37 public final class InformViaLogClassNameCRStrategy extends BaseClassNameCRStrategy
38 implements ClassNameCRStrategy {
39
40
41 private static final Log LOG = LogFactory.getLog(InformViaLogClassNameCRStrategy.class);
42
43 public static final String NAME = "informViaLog";
44
45
46
47
48
49 public InformViaLogClassNameCRStrategy() {
50
51 }
52
53
54
55
56
57
58
59
60
61
62
63
64 public SGStateInfo dealWithClassNameConflict(final SGStateInfo state,
65 final ClassInfo newClassInfo, final JClass conflict) {
66
67 ClassInfo oldClassInfo = state.resolve(conflict);
68 if (oldClassInfo == newClassInfo) {
69 return state;
70 }
71
72
73 Annotated a1 = null;
74 Annotated a2 = null;
75
76
77 Enumeration enumeration = state.keys();
78 while (enumeration.hasMoreElements() && (a1 == null || a2 == null)) {
79 Object key = enumeration.nextElement();
80 if (!(key instanceof Annotated)) {
81 continue;
82 }
83
84 ClassInfo cInfo = state.resolve(key);
85 if (newClassInfo == cInfo) {
86 a1 = (Annotated) key;
87 } else if (oldClassInfo == cInfo) {
88 a2 = (Annotated) key;
89 }
90 }
91
92 String annotated1XPath;
93 String annotated2XPath;
94
95 StringBuilder message = new StringBuilder();
96 message.append("Warning: A class name generation conflict has occured between ");
97
98 if (a1 != null) {
99 message.append(SchemaNames.getStructureName(a1));
100 message.append(" '");
101 if (a1 instanceof ElementDecl) {
102 ElementDecl element = (ElementDecl) a1;
103 annotated1XPath = XPathHelper.getSchemaLocation(a1) + "[/complexType:"
104 + element.getType().getName() + "]";
105 message.append(annotated1XPath);
106 } else {
107 message.append(XPathHelper.getSchemaLocation(a1));
108 }
109 } else {
110 if (newClassInfo.hasNature(XMLInfoNature.class.getName())) {
111 XMLInfoNature xmlNature = new XMLInfoNature(newClassInfo);
112 message.append(xmlNature.getNodeTypeName());
113 message.append(" '");
114 message.append(xmlNature.getNodeName());
115 }
116 }
117 message.append("' and ");
118 if (a2 != null) {
119 message.append(SchemaNames.getStructureName(a2));
120 message.append(" '");
121 if (a2 instanceof ElementDecl) {
122 ElementDecl element = (ElementDecl) a2;
123 annotated2XPath = XPathHelper.getSchemaLocation(a2) + "[/complexType:"
124 + element.getType().getName() + "]";
125 message.append(annotated2XPath);
126 } else {
127 message.append(XPathHelper.getSchemaLocation(a2));
128 }
129 } else {
130 if (oldClassInfo.hasNature(XMLInfoNature.class.getName())) {
131 XMLInfoNature xmlNature = new XMLInfoNature(oldClassInfo);
132 message.append(xmlNature.getNodeTypeName());
133 message.append(" '");
134 message.append(xmlNature.getNodeName());
135 }
136 }
137 message.append("'. Please use a Binding file to solve this problem.");
138 LOG.warn(message);
139 return state;
140 }
141
142
143
144
145
146
147
148 public String getName() {
149 return NAME;
150 }
151
152
153
154
155
156
157
158
159 public void setConsoleDialog(final ConsoleDialog dialog) {
160
161 }
162
163
164
165
166
167
168
169
170
171
172
173 public boolean dealWithFileOverwrite(final String filename) {
174 LOG.warn(filename + " already exists, but will be overwritten.");
175 return true;
176 }
177
178 }