cstructwriter.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,100 行 · 第 1/3 页
JAVA
1,100 行
Element rootElt = XSLTUtils.getElement(model, "class");
XSLTUtils.addAttribute(model, "name", className, rootElt);
XSLTUtils.addAttribute(model, "caps-name", className.toUpperCase(), rootElt);
XSLTUtils.addAttribute(model, "originalName", originalName, rootElt);
XSLTUtils.addAttribute(model, "nsuri", qName.getNamespaceURI(), rootElt);
XSLTUtils.addAttribute(model, "nsprefix", getPrefixForURI(qName.getNamespaceURI(), qName.getPrefix()), rootElt);
/* use caps for macros */
String capsName = className.toUpperCase();
XSLTUtils.addAttribute(model, "caps-name", capsName, rootElt);
if (!wrapClasses) {
XSLTUtils.addAttribute(model, "unwrapped", "yes", rootElt);
}
if (!writeClasses) {
XSLTUtils.addAttribute(model, "skip-write", "yes", rootElt);
}
if (!isElement) {
XSLTUtils.addAttribute(model, "type", "yes", rootElt);
}
if (metainf.isAnonymous()) {
XSLTUtils.addAttribute(model, "anon", "yes", rootElt);
}
if (metainf.isExtension()) {
XSLTUtils.addAttribute(model, "extension", metainf.getExtensionClassName(), rootElt);
}
if (metainf.isRestriction()) {
XSLTUtils.addAttribute(model, "restriction", metainf
.getRestrictionClassName(), rootElt);
}
if (metainf.isChoice()) {
XSLTUtils.addAttribute(model, "choice", "yes", rootElt);
}
if (metainf.isSimple()) {
XSLTUtils.addAttribute(model, "simple", "yes", rootElt);
}
if (metainf.isUnion()) {
XSLTUtils.addAttribute(model, "union", "yes", rootElt);
}
if (metainf.isList()) {
XSLTUtils.addAttribute(model, "list", "yes", rootElt);
}
if (metainf.isOrdered()) {
XSLTUtils.addAttribute(model, "ordered", "yes", rootElt);
}
if (isElement && metainf.isNillable(qName)) {
XSLTUtils.addAttribute(model, "nillable", "yes", rootElt);
}
//populate all the information
populateInfo(metainf, model, rootElt, propertyNames, typeMap, false);
if (metainf.isSimple() && metainf.isUnion()) {
populateMemberInfo(metainf, model, rootElt, typeMap);
}
if (metainf.isSimple() && metainf.isList()) {
populateListInfo(metainf, model, rootElt, typeMap);
}
return rootElt;
}
protected void populateListInfo(BeanWriterMetaInfoHolder metainf,
Document model,
Element rootElement,
Map typeMap) {
String cName = makeUniqueCStructName(new ArrayList(), metainf.getItemTypeQName().getLocalPart());
Element itemType = XSLTUtils.addChildElement(model, "itemtype", rootElement);
XSLTUtils.addAttribute(model, "type", metainf.getItemTypeClassName(), itemType);
XSLTUtils.addAttribute(model, "nsuri", metainf.getItemTypeQName().getNamespaceURI(), itemType);
XSLTUtils.addAttribute(model, "originalName", metainf.getItemTypeQName().getLocalPart(), itemType);
XSLTUtils.addAttribute(model, "cname", cName, itemType);
if (typeMap.containsKey(metainf.getItemTypeQName())) {
XSLTUtils.addAttribute(model, "ours", "true", itemType);
}
if (PrimitiveTypeFinder.isPrimitive(metainf.getItemTypeClassName())) {
XSLTUtils.addAttribute(model, "primitive", "yes", itemType);
}
}
protected void populateMemberInfo(BeanWriterMetaInfoHolder metainf,
Document model,
Element rootElement,
Map typeMap) {
Map memberTypes = metainf.getMemberTypes();
QName memberQName;
for (Iterator iter = memberTypes.keySet().iterator(); iter.hasNext();) {
memberQName = (QName) iter.next();
String memberClass = (String) memberTypes.get(memberQName);
if (PrimitiveTypeFinder.isPrimitive(memberClass)) {
memberClass = PrimitiveTypeWrapper.getWrapper(memberClass);
}
// add member type element
Element memberType = XSLTUtils.addChildElement(model, "memberType", rootElement);
XSLTUtils.addAttribute(model, "type", memberClass, memberType);
XSLTUtils.addAttribute(model, "nsuri", memberQName.getNamespaceURI(), memberType);
XSLTUtils.addAttribute(model, "originalName", memberQName.getLocalPart(), memberType);
XSLTUtils.addAttribute(model, "caps-originalName", memberQName.getLocalPart().toUpperCase(), memberType);
if (typeMap.containsKey(memberQName)) {
XSLTUtils.addAttribute(model, "ours", "true", memberType);
}
}
}
/**
* @param metainf
* @param model
* @param rootElt
* @param propertyNames
* @param typeMap
* @throws org.apache.axis2.schema.SchemaCompilationException
*
*/
private void populateInfo(BeanWriterMetaInfoHolder metainf,
Document model,
Element rootElt,
ArrayList propertyNames,
Map typeMap, boolean isInherited) throws SchemaCompilationException {
if (metainf.getParent() != null) {
populateInfo(metainf.getParent(), model, rootElt, propertyNames, typeMap, true);
}
addPropertyEntries(metainf, model, rootElt, propertyNames, typeMap, isInherited);
}
/**
* @param metainf
* @param model
* @param rootElt
* @param propertyNames
* @param typeMap
* @throws org.apache.axis2.schema.SchemaCompilationException
- *
*/
private void addPropertyEntries(BeanWriterMetaInfoHolder metainf, Document model, Element rootElt, ArrayList propertyNames,
Map typeMap,
boolean isInherited) throws SchemaCompilationException {
// go in the loop and add the part elements
QName[] qName;
ArrayList missingQNames = new ArrayList();
ArrayList qNames = new ArrayList();
BeanWriterMetaInfoHolder parentMetaInf = metainf.getParent();
if (metainf.isOrdered()) {
qName = metainf.getOrderedQNameArray();
} else {
qName = metainf.getQNameArray();
}
for (int i = 0; i < qName.length; i++) {
qNames.add(qName[i]);
}
//adding missing QNames to the end, including elements & attributes.
// for the simple types we have already add the parent elements
// it is almost consider as an extension
if (metainf.isRestriction() && !metainf.isSimple()) {
addMissingQNames(metainf, qNames, missingQNames);
}
QName name;
for (int i = 0; i < qName.length; i++) {
Element property = XSLTUtils.addChildElement(model, "property", rootElt);
name = qName[i];
String xmlName = makeUniqueCStructName(new ArrayList(), name.getLocalPart());
XSLTUtils.addAttribute(model, "name", xmlName, property);
XSLTUtils.addAttribute(model, "originalName", name.getLocalPart(), property);
XSLTUtils.addAttribute(model, "nsuri", name.getNamespaceURI(), property);
XSLTUtils.addAttribute(model, "prefix", name.getPrefix(), property);
XSLTUtils.addAttribute(model, "cname", xmlName, property);
String CClassNameForElement = metainf.getClassNameForQName(name);
if (CClassNameForElement == null) {
CClassNameForElement = CStructWriter.DEFAULT_C_CLASS_NAME;
}
CClassNameForElement = getShortTypeName(CClassNameForElement);
XSLTUtils.addAttribute(model, "type", CClassNameForElement, property);
/**
* Caps for use in C macros
*/
XSLTUtils.addAttribute(model, "caps-cname", xmlName.toUpperCase(), property);
XSLTUtils.addAttribute(model, "caps-type", CClassNameForElement.toUpperCase(), property);
if (PrimitiveTypeFinder.isPrimitive(CClassNameForElement)) {
XSLTUtils.addAttribute(model, "primitive", "yes", property);
}
//add an attribute that says the type is default
if (isDefault(CClassNameForElement)) {
XSLTUtils.addAttribute(model, "default", "yes", property);
}
if (typeMap.containsKey(metainf.getSchemaQNameForQName(name))) {
XSLTUtils.addAttribute(model, "ours", "yes", property);
}
if (metainf.getAttributeStatusForQName(name)) {
XSLTUtils.addAttribute(model, "attribute", "yes", property);
}else{
XSLTUtils.addAttribute(model, "notattribute", "yes", property);
}
if (metainf.isNillable(name)) {
XSLTUtils.addAttribute(model, "nillable", "yes", property);
}
String shortTypeName;
if (metainf.getSchemaQNameForQName(name) != null) {
//see whether the QName is a basetype
if (baseTypeMap.containsKey(metainf.getSchemaQNameForQName(name))) {
shortTypeName = metainf.getSchemaQNameForQName(name).getLocalPart();
} else {
shortTypeName = getShortTypeName(CClassNameForElement);
}
} else {
shortTypeName = getShortTypeName(CClassNameForElement);
}
XSLTUtils.addAttribute(model, "shorttypename", shortTypeName, property);
if (isInherited) {
XSLTUtils.addAttribute(model, "inherited", "yes", property);
}
QName schemaQName = metainf.getSchemaQNameForQName(name);
if(!schemaQName.getNamespaceURI().equals(name.getNamespaceURI())){
XSLTUtils.addAttribute(model, "child-nsuri", schemaQName.getNamespaceURI(), property);
XSLTUtils.addAttribute(model, "child-nsprefix", getPrefixForURI(schemaQName.getNamespaceURI(), null), property);
}
if (metainf.getAnyStatusForQName(name)) {
XSLTUtils.addAttribute(model, "any", "yes", property);
}
if (metainf.getBinaryStatusForQName(name)) {
XSLTUtils.addAttribute(model, "binary", "yes", property);
}
if (metainf.getSimpleStatusForQName(name)) {
XSLTUtils.addAttribute(model, "simple", "yes", property);
}
//put the min occurs count irrespective of whether it's an array or not
long minOccurs = metainf.getMinOccurs(name);
XSLTUtils.addAttribute(model, "minOccurs", minOccurs + "", property);
if (metainf.getArrayStatusForQName(name)) {
String attrName = name.getLocalPart();
int arrayTokenStart = attrName.indexOf("Array");
if (arrayTokenStart >= 0) {
String arrayEle = attrName.substring(0, arrayTokenStart);
XSLTUtils.addAttribute(model, "arrayele", arrayEle, property);
}
XSLTUtils.addAttribute(model, "isarray", "yes", property);
XSLTUtils.addAttribute(
model,
"arrayBaseType",
CClassNameForElement,
property);
long maxOccurs = metainf.getMaxOccurs(name);
if (maxOccurs == Long.MAX_VALUE) {
XSLTUtils.addAttribute(model, "unbound", "yes", property);
}
XSLTUtils.addAttribute(model, "maxOccurs", maxOccurs + "", property);
}
if ((parentMetaInf != null) && metainf.isRestriction() && missingQNames.contains(name)) {
// this element details should be there with the parent meta Inf
addAttributesToProperty(
parentMetaInf,
name,
model,
property,
typeMap,
CClassNameForElement);
} else {
addAttributesToProperty(
metainf,
name,
model,
property,
typeMap,
CClassNameForElement);
}
}
}
private void addAttributesToProperty(BeanWriterMetaInfoHolder metainf,
QName name,
Document model,
Element property,
Map typeMap,
String javaClassNameForElement) {
// add an attribute that says the type is default
if (metainf.getDefaultStatusForQName(name)) {
XSLTUtils.addAttribute(model, "default", "yes", property);
}
if (typeMap.containsKey(metainf.getSchemaQNameForQName(name))) {
XSLTUtils.addAttribute(model, "ours", "yes", property);
}
if (metainf.getAttributeStatusForQName(name)) {
XSLTUtils.addAttribute(model, "attribute", "yes", property);
}
if (metainf.isNillable(name)) {
XSLTUtils.addAttribute(model, "nillable", "yes", property);
}
if (metainf.getOptionalAttributeStatusForQName(name)) {
XSLTUtils.addAttribute(model, "optional", "yes", property);
}
String shortTypeName;
if (metainf.getSchemaQNameForQName(name) != null) {
// see whether the QName is a basetype
if (baseTypeMap.containsKey(metainf.getSchemaQNameForQName(name))) {
shortTypeName = metainf.getSchemaQNameForQName(name).getLocalPart();
} else {
shortTypeName = getShortTypeName(javaClassNameForElement);
}
} else {
shortTypeName = getShortTypeName(javaClassNameForElement);
}
XSLTUtils.addAttribute(model, "shorttypename", shortTypeName, property);
if (metainf.getAnyStatusForQName(name)) {
XSLTUtils.addAttribute(model, "any", "yes", property);
}
if (metainf.getBinaryStatusForQName(name)) {
XSLTUtils.addAttribute(model, "binary", "yes", property);
}
if (metainf.isSimple() || metainf.getSimpleStatusForQName(name)) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?