📄 javabeanwriter.java
字号:
typeName = Utils.getWrapperType(typeName); } // Make sure the property name is not reserved. variableName = JavaUtils.getUniqueValue( helper.reservedPropNames, variableName); names.add(typeName); names.add(variableName); if (type.isSimpleType() && (variableName.endsWith("Value") || variableName.equals("_value"))) { simpleValueTypes.add(typeName); } // bug 19069: need to generate code that access member variables that // are enum types through the class interface, not the constructor // this util method returns non-null if the type at node is an enum if (null != Utils.getEnumerationBaseAndValues(attr.getType().getNode(), emitter.getSymbolTable())) { enumerationTypes.add(typeName); } } } if ((extendType != null) && extendType.getDimensions().equals("[]")) { String typeName = extendType.getName(); String elemName = extendType.getQName().getLocalPart(); String variableName = Utils.xmlNameToJava(elemName); names.add(typeName); names.add(variableName); } if((extendType != null) && (Utils.getEnumerationBaseAndValues( extendType.getNode(), emitter.getSymbolTable()) != null)){ enableDefaultConstructor = false; } // Check for duplicate names and make them unique // Start at index 2 and go by twos for (int i = 1; i < names.size(); i +=2) { int suffix = 2; // the number we append to the name String s = (String) names.elementAt(i); if (i < names.size() - 2) { int dup = names.indexOf(s, i+1); while (dup > 0) { // duplicate name, tack a number on the end names.set(dup, names.get(dup) + Integer.toString(suffix)); suffix++; // get out if we don't have more if (i >= names.size() - 2) break; dup = names.indexOf(s, dup+1); } } } } /** * generate a name for the attribute * @param attr * @return name */ private String getAttributeName(ContainedAttribute attr) { String variableName = attr.getName(); if (variableName == null) { variableName = Utils.getLastLocalPart(attr.getQName().getLocalPart()); } return variableName; } /** * Check if we need to use the wrapper type or MessageElement * * @param elem * @param typeName * @return type name */ private String processTypeName(ElementDecl elem, String typeName) { if (elem.getAnyElement()) { typeName = "org.apache.axis.message.MessageElement []"; } else if (elem.getType().getUnderlTypeNillable() || (elem.getNillable() && elem.getMaxOccursIsUnbounded())) { /* * Soapenc arrays with nillable underlying type or * nillable="true" maxOccurs="unbounded" elements * should be mapped to a wrapper type. */ typeName = Utils.getWrapperType(elem.getType()); } else if (elem.getMinOccursIs0() && elem.getMaxOccursIsExactlyOne() || elem.getNillable() || elem.getOptional()) { /* * Quote from JAX-RPC 1.1, Section 4.2.1: * There are a number of cases in which a built-in simple * XML data type must be mapped to the corresponding Java * wrapper class for the Java primitive type: * * an element declaration with the nillable attribute * set to true; * * an element declaration with the minOccurs attribute * set to 0 (zero) and the maxOccurs attribute set * to 1 (one) or absent; * * an attribute declaration with the use attribute set * to optional or absent and carrying neither * the default nor the fixed attribute; */ typeName = Utils.getWrapperType(typeName); } return typeName; } /** * Returns the class name that should be used to serialize and * deserialize this binary element */ protected String getBinaryTypeEncoderName(String elementName) { TypeEntry type = getElementDecl(elementName); if (type != null) { String typeName = type.getQName().getLocalPart(); if (typeName.equals("base64Binary")) return "org.apache.axis.encoding.Base64"; if (typeName.equals("hexBinary")) return "org.apache.axis.types.HexBinary"; throw new java.lang.RuntimeException("Unknown binary type " + typeName + " for element " + elementName); } throw new java.lang.RuntimeException("Unknown element " + elementName); } /** * Returns the TypeEntry of the given element */ protected TypeEntry getElementDecl(String elementName) { if (elements != null) { for (int i = 0; i < elements.size(); i++) { ElementDecl elem = (ElementDecl) elements.get(i); String variableName; if (elem.getAnyElement()) { variableName = Constants.ANYCONTENT; } else { variableName = elem.getName(); } if (variableName.equals(elementName)) return elem.getType(); } } return null; } /** * Returns the appropriate extends text * * @return "" or "abstract " */ protected String getClassModifiers() { Node node = type.getNode(); if (node != null) { if (JavaUtils.isTrueExplicitly(Utils.getAttribute(node, "abstract"))) { return super.getClassModifiers() + "abstract "; } } return super.getClassModifiers(); } // getClassModifiers /** * Returns the appropriate extends text * * @return "" or " extends <class> " */ protected String getExtendsText() { // See if this class extends another class String extendsText = ""; if ((extendType != null) && !isUnion() && (!type.isSimpleType() || !extendType.isBaseType()) && (extendType.getDimensions().length() == 0)) { extendsText = " extends " + extendType.getName() + " "; } return extendsText; } /** * Returns the appropriate implements text * * @return " implements <classes> " */ protected String getImplementsText() { // See if this class extends another class String implementsText = " implements java.io.Serializable"; if (type.isSimpleType() && (isUnion() || extendType == null || extendType.isBaseType())) { implementsText += ", org.apache.axis.encoding.SimpleType"; } if (isAny) { implementsText += ", org.apache.axis.encoding.AnyContentType"; } if (isMixed) { implementsText += ", org.apache.axis.encoding.MixedContentType"; } implementsText += " "; return implementsText; } /** * Writes the member fields. */ protected void writeMemberFields() { // Define the member element of the bean if (isUnion()) { pw.println(" private java.lang.String _value;"); return; } for (int i = 0; i < names.size(); i += 2) { // get comments for this field String comments = ""; if (elements != null) { if (elements != null && i < (elements.size()*2)) { ElementDecl elem = (ElementDecl)elements.get(i/2); comments = elem.getDocumentation(); } } String typeName = (String) names.get(i); String variable = (String) names.get(i + 1); // Declare the bean element if (comments != null && comments.trim().length() > 0) { String flatComments = getJavadocDescriptionPart(comments, true).substring(7); // it will be flat if it fits on one line pw.println(" /* " + flatComments.trim() + " */"); } pw.print(" private " + typeName + " " + variable + ";"); // label the attribute fields. if ((elements == null) || (i >= (elements.size() * 2))) { pw.println(" // attribute"); } else { pw.println(); } pw.println(); } } /** * Writes the default constructor. */ protected void writeDefaultConstructor() { // Define the default constructor pw.println(" public " + className + "() {"); pw.println(" }"); pw.println(); } protected void writeMinimalConstructor() { if (isUnion() || names.size() == 0) { return; } pw.println(" public " + className + "("); for (int i = 0; i < names.size(); i += 2) { String typeName = (String) names.get(i); String variable = (String) names.get(i + 1); pw.print(" " + typeName + " " + variable); if (i >= names.size() - 2) { pw.println(") {"); } else { pw.println(","); } } for (int i = 0; i < names.size(); i += 2) { String variable = (String) names.get(i + 1); pw.println(" this." + variable + " = " + variable + ";"); if (i >= names.size() - 2) { break; } } pw.println(" }"); pw.println(); } /** * Writes the full constructor. * Note that this class is not recommended for * JSR 101 compliant beans, but is provided for * extended classes which may wish to generate a full * constructor. */ protected void writeFullConstructor() { if (type.isSimpleType()) { return; } // The constructor needs to consider all extended types Vector extendList = new Vector(); extendList.add(type); TypeEntry parent = extendType; while (parent != null) { if (parent.isSimpleType()) return; extendList.add(parent); parent = SchemaUtils.getComplexElementExtensionBase(parent.getNode(), emitter.getSymbolTable()); } // Now generate a list of names and types starting with // the oldest parent. (Attrs are considered before elements). Vector paramTypes = new Vector(); Vector paramNames = new Vector(); boolean gotAny = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -