This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
/
AttributeInfo.java
181 lines (158 loc) · 6.88 KB
/
AttributeInfo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.mgmt.generator;
import nu.xom.Attribute;
import nu.xom.Element;
import org.jboss.jdeparser.JDefinedClass;
import org.jboss.jdeparser.JMethod;
import org.jboss.mgmt.Access;
import org.jboss.mgmt.annotation.XmlRender;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;
/**
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
*/
final class AttributeInfo implements ResourceMember {
private final ExecutableElement executableElement;
/**
* Attribute names must always be stored using OriginalUpperCamelCase in order
* to preserve the original case of acronym CamelWords.
*/
private final String name;
private final AttributeValueInfo valueInfo;
private final Access access;
private final TypeMirror virtual;
private final boolean required;
private final VariableElement defaultVal;
private final TypeMirror[] validators;
private final String xmlName;
private final boolean wrapperElement;
private final XmlRender.As renderAs;
public AttributeInfo(final ExecutableElement executableElement, final String name, final AttributeValueInfo valueInfo, final Access access, final TypeMirror virtual, final boolean required, final VariableElement defaultVal, final TypeMirror[] validators, final String xmlName, final boolean wrapperElement, final XmlRender.As renderAs) {
this.executableElement = executableElement;
this.name = name;
this.valueInfo = valueInfo;
this.access = access;
this.virtual = virtual;
this.required = required;
this.defaultVal = defaultVal;
this.validators = validators;
this.xmlName = xmlName;
this.wrapperElement = wrapperElement;
this.renderAs = renderAs;
}
public ExecutableElement getExecutableElement() {
return executableElement;
}
public String getName() {
return name;
}
public AttributeValueInfo getValueInfo() {
return valueInfo;
}
public Access getAccess() {
return access;
}
public TypeMirror getVirtual() {
return virtual;
}
public boolean isRequired() {
return required;
}
public VariableElement getDefaultVal() {
return defaultVal;
}
public TypeMirror[] getValidators() {
return validators;
}
public String getXmlName() {
return xmlName;
}
public boolean isWrapperElement() {
return wrapperElement;
}
public XmlRender.As getRenderAs() {
return renderAs;
}
public void addToSchema(final SchemaGeneratorContext ctxt, final Element enclosingTypeElement, final Element enclosingSeqElement) {
if (renderAs == XmlRender.As.ATTRIBUTE) {
final Element attributeElement = new Element("xs:attribute", SchemaInfo.XS);
attributeElement.addAttribute(new Attribute("name", xmlName));
attributeElement.addAttribute(new Attribute("use", required ? "required" : "optional"));
valueInfo.addToSchemaAsAttribute(this, enclosingSeqElement, enclosingTypeElement, attributeElement);
GeneratorUtils.addDocumentation(attributeElement, "*** DOCS HERE ***");
enclosingTypeElement.appendChild(attributeElement);
} else {
final Element elementElement = new Element("xs:element", SchemaInfo.XS);
elementElement.addAttribute(new Attribute("name", xmlName));
valueInfo.addToSchemaAsElement(this, enclosingSeqElement, enclosingTypeElement, elementElement);
}
}
public void addToResourceClass(final JDefinedClass resourceClass, final JMethod constructor) {
valueInfo.addToResourceClass(resourceClass, constructor);
}
public void addToBuilderClass(final JDefinedClass builderClass) {
valueInfo.addToBuilderClass(builderClass);
}
public void addToResolvedResourceClass(final JDefinedClass resolvedClass, final JMethod constructor) {
valueInfo.addToResolvedResourceClass(resolvedClass, constructor);
}
public void addToResolvedInterface(final JDefinedClass resolvedInterface) {
valueInfo.addToResolvedInterface(resolvedInterface);
}
public void addToClass() {
// final SchemaGeneratorContext schemaGeneratorContext = resourceGeneratorContext.getContext();
// final GeneratorContext generatorContext = schemaGeneratorContext.getContext();
// final ProcessingEnvironment env = generatorContext.getEnv();
// final JDeparser deparser = generatorContext.getDeparser();
//
// // ---------------------------
// // Resource interface stuff
// // ---------------------------
//
// final JClass resourceInterface = resourceGeneratorContext.getResourceInterface();
//
// final JType attributeJType = JDeparserUtils.typeFor(env, deparser, executableElement.getReturnType());
// final String getterName = executableElement.getSimpleName().toString();
// final String attrVarName = fieldify(name);
//
// final JDefinedClass resourceImplClass = resourceGeneratorContext.getResourceImplClass();
// final JMethod resourceImplConstructor = resourceGeneratorContext.getResourceImplConstructor();
// final JBlock resourceImplConstructorInitBlock = resourceGeneratorContext.getResourceImplConstructorInitBlock();
//
// final JMethod getterMethod = resourceImplClass.method(PUBLIC, attributeJType, getterName);
// final JBlock getterMethodBody = getterMethod.body();
// if (access.isReadable()) {
//
// } else {
// getterMethodBody._throw(deparser.ref(AbstractResource.class).staticInvoke("notReadable"));
// }
//
// // ---------------------------
// // Builder class stuff
// // ---------------------------
//
// final JMethod setterDecl;
// final JBlock setterBody;
}
}