1
|
|
/*
|
2
|
|
* JBind
|
3
|
|
*
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
5
|
|
*
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
8
|
|
* 'Apache Software License V 1.1'.
|
9
|
|
*/
|
10
|
|
package org.jbind.xml.schema.compiler;
|
11
|
|
|
12
|
|
import java.io.File;
|
13
|
|
import java.io.Reader;
|
14
|
|
|
15
|
|
import org.jbind.javaParser.ASTCompilationUnit;
|
16
|
|
import org.jbind.javaParser.ASTTypeDeclaration;
|
17
|
|
import org.jbind.javaParser.ASTUnmodifiedClassDeclaration;
|
18
|
|
import org.jbind.javaParser.ASTUnmodifiedInterfaceDeclaration;
|
19
|
|
import org.jbind.javaParser.JavaParser;
|
20
|
|
import org.jbind.message.IMessage;
|
21
|
|
import org.jbind.xml.base.IBindingAttributes;
|
22
|
|
import org.jbind.xml.core.cmp.IBinding;
|
23
|
|
import org.jbind.xml.core.cmp.IComponent;
|
24
|
|
import org.jbind.xml.core.type.IAnyType;
|
25
|
|
import org.jbind.xml.msg.XmlMessages;
|
26
|
|
|
27
|
|
public abstract class BehaviourCartridge extends BaseCartridge {
|
28
|
|
|
29
|
6
|
public BehaviourCartridge(String aCartridgeAttributePrefix, String aNamePrefix, String aNameSuffix) {
|
30
|
6
|
super(aCartridgeAttributePrefix, aNamePrefix, aNameSuffix);
|
31
|
|
}
|
32
|
|
|
33
|
16
|
public boolean overwrite() {
|
34
|
16
|
return false;
|
35
|
|
}
|
36
|
|
|
37
|
|
protected abstract String getDeclaration(IAnyType aType);
|
38
|
|
|
39
|
0
|
public IMessage getEditHint(File aFile, IComponent aComponent) {
|
40
|
0
|
return XmlMessages.fileMustBeEdited(aFile, getDeclaration((IAnyType)aComponent), null);
|
41
|
|
}
|
42
|
|
|
43
|
8
|
public boolean isUpToDate(Reader aReader, IFileInfo aFileInfo) throws Exception {
|
44
|
8
|
JavaParser parser = new JavaParser(aReader);
|
45
|
8
|
ASTCompilationUnit cu = parser.CompilationUnit();
|
46
|
8
|
ASTTypeDeclaration td = cu.getTypeDeclaration(0);
|
47
|
8
|
boolean match = false;
|
48
|
8
|
if (td != null) {
|
49
|
8
|
IAnyType t = (IAnyType)aFileInfo.getComponent();
|
50
|
8
|
String stringPackage = getBinding(t).getPackage();
|
51
|
8
|
if ("class".equals(interfaceOrClass()) && (td.getClassDeclaration() != null)) {
|
52
|
4
|
ASTUnmodifiedClassDeclaration cd = td.getClassDeclaration();
|
53
|
4
|
String stringInterface = getBehaviourInterfaceCartridge().getNameForPackage(t, stringPackage);
|
54
|
4
|
String baseClass = behaviourBaseClass(t.getBaseType(), stringPackage);
|
55
|
4
|
if (baseClass.equals(cd.getExtends().getName())) {
|
56
|
4
|
if (cd.getImplements().contains(stringInterface)) {
|
57
|
4
|
match = true;
|
58
|
|
}
|
59
|
|
}
|
60
|
4
|
} else if ("interface".equals(interfaceOrClass()) && (td.getInterfaceDeclaration() != null)) {
|
61
|
4
|
ASTUnmodifiedInterfaceDeclaration id = td.getInterfaceDeclaration();
|
62
|
4
|
String stringInterface = getDataInterfaceCartridge().getNameForPackage(t, stringPackage);
|
63
|
4
|
if (id.getExtends().contains(stringInterface)) {
|
64
|
4
|
match = true;
|
65
|
|
}
|
66
|
|
}
|
67
|
|
}
|
68
|
8
|
return match;
|
69
|
|
}
|
70
|
|
|
71
|
932
|
public IBinding createGlobalAnyTypeBinding(IComponent aComponent, String aRootPackage, boolean aUseBuiltInClassesOnly) {
|
72
|
932
|
IBinding res = null;
|
73
|
932
|
if ("true".equals(aComponent.getDefaultedLocalStringBindingAttribute(IBindingAttributes.HAS_BEHAVIOUR))) {
|
74
|
32
|
res = new GlobalBinding(aRootPackage, this, aComponent);
|
75
|
|
}
|
76
|
932
|
return res;
|
77
|
|
}
|
78
|
118
|
public IBinding createGlobalAttrDeclBinding(IComponent aComponent, String aRootPackage, boolean aUseBuiltInClassesOnly) {
|
79
|
118
|
return null;
|
80
|
|
}
|
81
|
70
|
public IBinding createGlobalGroupDeclBinding(IComponent aComponent, String aRootPackage, boolean aUseBuiltInClassesOnly) {
|
82
|
70
|
return null;
|
83
|
|
}
|
84
|
580
|
public IBinding createGlobalElemDeclBinding(IComponent aComponent, String aRootPackage, boolean aUseBuiltInClassesOnly) {
|
85
|
580
|
return null;
|
86
|
|
}
|
87
|
88
|
public IBinding createGlobalAttrGroupBinding(IComponent aComponent, String aRootPackage, boolean aUseBuiltInClassesOnly) {
|
88
|
88
|
return null;
|
89
|
|
}
|
90
|
|
|
91
|
470
|
public IBinding createInnerAnyTypeBinding(IComponent aComponent, IBinding aParentBinding, boolean aUseBuiltInClassesOnly) {
|
92
|
470
|
return null;
|
93
|
|
}
|
94
|
60
|
public IBinding createInnerAttrRefBinding(IComponent aComponent, IBinding aParentBinding, boolean aUseBuiltInClassesOnly) {
|
95
|
60
|
return null;
|
96
|
|
}
|
97
|
1120
|
public IBinding createInnerAttrDeclBinding(IComponent aComponent, IBinding aParentBinding, boolean aUseBuiltInClassesOnly) {
|
98
|
1120
|
return null;
|
99
|
|
}
|
100
|
132
|
public IBinding createInnerAttrWildcardBinding(IComponent aComponent, IBinding aParentBinding, boolean aUseBuiltInClassesOnly) {
|
101
|
132
|
return null;
|
102
|
|
}
|
103
|
772
|
public IBinding createInnerGroupRefOrDeclBinding(IComponent aComponent, IBinding aParentBinding, boolean aUseBuiltInClassesOnly) {
|
104
|
772
|
return null;
|
105
|
|
}
|
106
|
420
|
public IBinding createInnerElemRefBinding(IComponent aComponent, IBinding aParentBinding, boolean aUseBuiltInClassesOnly) {
|
107
|
420
|
return null;
|
108
|
|
}
|
109
|
740
|
public IBinding createInnerElemDeclBinding(IComponent aComponent, IBinding aParentBinding, boolean aUseBuiltInClassesOnly) {
|
110
|
740
|
return null;
|
111
|
|
}
|
112
|
54
|
public IBinding createInnerElemWildcardBinding(IComponent aComponent, IBinding aParentBinding, boolean aUseBuiltInClassesOnly) {
|
113
|
54
|
return null;
|
114
|
|
}
|
115
|
988
|
public IBinding createInnerAttrGroupBinding(IComponent aComponent, IBinding aParentBinding, boolean aUseBuiltInClassesOnly) {
|
116
|
988
|
return null;
|
117
|
|
}
|
118
|
|
|
119
|
8
|
protected boolean doVisitAnyTypeStart(IAnyType aType) {
|
120
|
8
|
if (!aType.isTopLevelComponent()) {
|
121
|
0
|
return true;
|
122
|
|
}
|
123
|
8
|
setNotEmpty();
|
124
|
8
|
writeLn(getDeclaration(aType) + " {");
|
125
|
8
|
setOuterComponent(aType);
|
126
|
8
|
return false;
|
127
|
|
}
|
128
|
|
|
129
|
8
|
protected void doVisitAnyTypeEnd(IAnyType aType) {
|
130
|
8
|
if (!aType.isTopLevelComponent()) {
|
131
|
0
|
return;
|
132
|
|
}
|
133
|
8
|
writeLn("}");
|
134
|
|
}
|
135
|
|
|
136
|
|
}
|
137
|
|
|