1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.exolab.castor.builder.conflict.strategy;
15
16
17 import org.exolab.castor.xml.schema.Annotated;
18 import org.exolab.castor.xml.schema.ElementDecl;
19 import org.exolab.castor.xml.schema.XMLType;
20 import org.exolab.javasource.JClass;
21
22
23
24
25
26
27
28 public class TypeClassNameConflictResolver extends BaseClassNameConflictResolver
29 implements ClassNameConflictResolver {
30
31
32
33
34
35
36
37
38
39 public void changeClassInfoAsResultOfConflict(final JClass jClass, final String xpath,
40 final String typedXPath, final Annotated annotated) {
41 String typeString = typedXPath.substring(typedXPath.indexOf("[") + 1, typedXPath.indexOf("]"));
42 if (annotated instanceof ElementDecl) {
43 ElementDecl element = (ElementDecl) annotated;
44
45 if (element.getParent() == element.getSchema()) {
46 return;
47 }
48
49 if (element.isReference()) {
50 return;
51 }
52
53
54 XMLType xmlType = element.getType();
55 ElementDecl globalElement = element.getSchema().getElementDecl(element.getName());
56 if (globalElement != null) {
57 XMLType globalElementType = globalElement.getType();
58 if (globalElementType.getName() != null
59 && globalElementType.getName().equals(xmlType.getName())) {
60 return;
61 }
62 }
63 if (xmlType.isComplexType() && xmlType.getName() == null) {
64 typeString = "/complexType:anon";
65 }
66 }
67 if (typeString.startsWith("/complexType:anon")) {
68
69 String newClassName = calculateXPathPrefix(xpath) + jClass.getLocalName();
70 jClass.changeLocalName(newClassName);
71 } else if (typeString.startsWith("/complexType:")) {
72
73 String newClassName =
74 jClass.getLocalName() + getSourceGenerator().getAutomaticConflictResolutionTypeSuffix()
75 + typeString.substring(typeString.indexOf(":") + 1);
76 jClass.changeLocalName(newClassName);
77 }
78 }
79
80 }