📄 bindinggenerator.java
字号:
// check for standard library classes we can handle ClassFile pcf = ClassCache.getClassFile(tname); ClassItem init = pcf.getInitializerMethod ("(Ljava/lang/String;)"); if (init != null) { simple = pcf.getMethod("toString", "()Ljava/lang/String;") != null; attribute = false; } } // check type of handling to use for value if (m_enumerationNames.get(tname) != null) { // define a value using deserializer method String mname = (String)m_enumerationNames.get(tname); int split = mname.lastIndexOf('.'); ClassFile dcf = ClassCache.getClassFile(mname.substring(0, split)); ClassItem dser = dcf.getStaticMethod(mname.substring(split+1), "(Ljava/lang/String;)"); if (dser == null || !tname.equals(dser.getTypeName())) { throw new JiBXException("Deserializer method not " + "found for enumeration class " + tname); } ValueElement value = new ValueElement(); value.setFieldName(fname); value.setName(valueName(fname)); value.setUsageName("optional"); value.setStyleName("element"); value.setDeserializerName(mname); contain.addChild(value); } else if (m_mappedNames.get(tname) != null) { // use mapping definition for class StructureElement structure = new StructureElement(); structure.setUsageName("optional"); structure.setFieldName(fname); if (((String)m_mappedNames.get(tname)).length() == 0) { // add a name for reference to abstract mapping structure.setName(elementName(tname)); } contain.addChild(structure); if (m_verbose) { nestingIndent(System.out); System.out.println("referenced existing binding for " + tname); } } else if (simple) { // define a simple value ValueElement value = new ValueElement(); value.setFieldName(fname); value.setName(valueName(fname)); if (object) { value.setUsageName("optional"); } if (!attribute) { value.setStyleName("element"); } contain.addChild(value); } else if (tname.endsWith("[]")) { // array, check if item type has a mapping String bname = tname.substring(0, tname.length()-2); if (m_mappedNames.get(bname) == null) { // no mapping, use collection with inline structure // TODO: fill it in throw new JiBXException("Base element type " + bname + " must be mapped"); } else { // mapping for type, use direct collection // TODO: convert to simple collection StructureElement structure = new StructureElement(); structure.setUsageName("optional"); structure.setFieldName(fname); structure.setMarshallerName ("org.jibx.extras.TypedArrayMapper"); structure.setUnmarshallerName ("org.jibx.extras.TypedArrayMapper"); contain.addChild(structure); } } else { // no defined handling, check for collection vs. structure ClassFile pcf = ClassCache.getClassFile(tname); StructureElementBase element; if (pcf.isImplements("Ljava/util/List;")) { // create a collection for list subclass System.err.println("Warning: field " + fname + " requires mapped implementation of item classes"); element = new CollectionElement(); element.setComment(" add details of collection items " + "to complete binding definition "); element.setFieldName(fname); // specify factory method if just typed as interface if ("java.util.List".equals(tname)) { element.setFactoryName ("org.jibx.runtime.Utility.arrayListFactory"); } } else if (pcf.isInterface() || m_ignoreNames.contains(tname)) { // create mapping reference with warning for interface nestingIndent(System.err); System.err.println("Warning: reference to interface " + "or abstract class " + tname + " requires mapped implementation"); element = new StructureElement(); element.setFieldName(fname); } else { // handle other types of structures directly element = createStructure(pcf, fname); } // finish with common handling element.setUsageName("optional"); contain.addChild(element); } } } } /** * Construct the list of child binding components that define the binding * structure corresponding to properties of a particular class. This binds * the specified properties of the class, using get/set methods, if * necessary creating nested structure elements for unmapped classes * referenced by the properties. * * @param cf class information * @param props list of properties specified for class * @param internal allow private get/set methods flag * @param contain binding structure container element * @throws JiBXException on error in binding generation */ private void defineProperties(ClassFile cf, ArrayList props, boolean internal, ContainerElementBase contain) throws JiBXException { // process all properties of class for (int i = 0; i < props.size(); i++) { String pname = (String)props.get(i); String base = Character.toUpperCase(pname.charAt(0)) + pname.substring(1); String gname = "get" + base; ClassItem gmeth = cf.getMethod(gname, "()"); if (gmeth == null) { throw new JiBXException("No method " + gname + "() found for property " + base + " in class " + cf.getName()); } else { String tname = gmeth.getTypeName(); String sname = "set" + base; String sig = "(" + gmeth.getSignature().substring(2) + ")V"; ClassItem smeth = cf.getMethod(sname, sig); if (smeth == null) { throw new JiBXException("No method " + sname + "(" + tname + ") found for property " + base + " in class " + cf.getName()); } else { // find type of handling needed for field type boolean simple = false; boolean object = true; boolean attribute = true; if (ClassItem.isPrimitive(tname)) { simple = true; object = false; } else if (s_objectPrimitiveSet.contains(tname)) { simple = true; } else if (tname.equals("byte[]")) { simple = true; attribute = false; } else if (tname.startsWith("java.")) { // check for standard library classes we can handle ClassFile pcf = ClassCache.getClassFile(tname); if (pcf.getInitializerMethod("()") != null) { simple = pcf.getMethod("toString", "()Ljava/lang/String;") != null; attribute = false; } } if (simple) { // define a simple value ValueElement value = new ValueElement(); value.setGetName(gname); value.setSetName(sname); value.setName(valueName(pname)); if (object) { value.setUsageName("optional"); } if (!attribute) { value.setStyleName("element"); } contain.addChild(value); } else if (m_enumerationNames.get(tname) != null) { // define a value using deserializer method String mname = (String)m_enumerationNames.get(tname); int split = mname.lastIndexOf('.'); ClassFile dcf = ClassCache.getClassFile(mname.substring(0, split)); ClassItem dser = dcf.getStaticMethod(mname.substring(split+1), "(Ljava/lang/String;)"); if (dser == null || !tname.equals(dser.getTypeName())) { throw new JiBXException("Deserializer method not " + "found for enumeration class " + tname); } ValueElement value = new ValueElement(); value.setGetName(gname); value.setSetName(sname); value.setName(valueName(pname)); value.setUsageName("optional"); value.setStyleName("element"); value.setDeserializerName(mname); contain.addChild(value); } else if (m_mappedNames.get(tname) != null) { // use mapping definition for class StructureElement structure = new StructureElement(); structure.setUsageName("optional"); structure.setGetName(gname); structure.setSetName(sname); if (((String)m_mappedNames.get(tname)).length() == 0) { // add a name for reference to abstract mapping structure.setName(elementName(tname)); } contain.addChild(structure); if (m_verbose) { nestingIndent(System.out); System.out.println ("referenced existing binding for " + tname); } } else if (tname.endsWith("[]")) { // array, only supported for mapped base type String bname = tname.substring(0, tname.length()-2); if (m_mappedNames.get(bname) == null) { throw new JiBXException("Base element type " + bname + " must be mapped"); } else { StructureElement structure = new StructureElement(); structure.setUsageName("optional"); structure.setGetName(gname); structure.setSetName(sname); structure.setMarshallerName ("org.jibx.extras.TypedArrayMapper"); structure.setUnmarshallerName ("org.jibx.extras.TypedArrayMapper"); contain.addChild(structure); } } else { // no defined handling, check collection vs. structure ClassFile pcf = ClassCache.getClassFile(tname); StructureElementBase element; if (pcf.isImplements("Ljava/util/List;")) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -