bindinggenerator.java
来自「对xml很好的java处理引擎,编译中绑定xml」· Java 代码 · 共 1,293 行 · 第 1/4 页
JAVA
1,293 行
// add <value> for simple type ValueElement value = new ValueElement(); value.setName(iname); value.setDeclaredType(itype); coll.addChild(value); } else { // embed structure definition within the collection StructureElement struct = new StructureElement(); struct.setDeclaredType(itype); ClassCustom icust = m_global.getClassCustomization(itype); struct.setCreateType(icust.getCreateType()); struct.setFactoryName(icust.getFactoryMethod()); if (iname == null) { iname = icust.getElementName(); } struct.setName(iname); addMemberBindings(icust, struct, hold); coll.addChild(struct); } } /** * Add binding details for all members of a class. * * @param cust class customization information * @param parent containing binding component * @param hold binding holder */ private void addMemberBindings(ClassCustom cust, NestingElementBase parent, BindingHolder hold) { // generate binding component for each member of class for (Iterator iter = cust.getMembers().iterator(); iter.hasNext();) { MemberCustom memb = (MemberCustom)iter.next(); if (memb.isCollection()) { // create collection element for field or property CollectionElement coll = new CollectionElement(); if (memb.getFieldName() == null) { coll.setGetName(memb.getGetName()); coll.setSetName(memb.getSetName()); } else { coll.setFieldName(memb.getFieldName()); } setTypes(memb, coll); // set the element name, if defined String name = memb.getXmlName(); if (name != null) { coll.setName(name); } // check for optional value if (!memb.isRequired()) { coll.setUsageName("optional"); } // check for type defined String itype = memb.getItemType(); if (itype != null) { // set name to be used for items in collection String iname = memb.getItemName(); if (iname == null) { // check for collection name that looks like a plural if (name != null && name.endsWith("s")) { // convert plural ending to singular if (name.endsWith("ies")) { iname = name.substring(0, name.length()-3) + "y"; } else { iname = name.substring(0, name.length()-1); } } else { // use name based on item type String simple = itype; int split = simple.lastIndexOf('.'); if (split >= 0) { simple = simple.substring(0, split); } iname = cust.convertName(simple); } } // define the collection details defineCollection(itype, iname, coll, hold); } parent.addChild(coll); } else { // check whether value or structure String wtype = memb.getWorkingType(); if (Types.isSimpleValue(wtype) || isValueClass(wtype)) { // add <value> for simple type ValueElement value = new ValueElement(); if (memb.getFieldName() == null) { value.setGetName(memb.getGetName()); value.setSetName(memb.getSetName()); } else { value.setFieldName(memb.getFieldName()); } value.setName(memb.getXmlName()); // check for optional value if (!memb.isRequired()) { value.setUsageName("optional"); } // configure added property values int style = memb.getStyle(); if (style == NestingBase.ATTRIBUTE_VALUE_STYLE) { value.setStyleName("attribute"); } else if (style == NestingBase.ELEMENT_VALUE_STYLE) { value.setStyleName("element"); } else { value.setStyleName("text"); } if (memb.getActualType() != null) { value.setDeclaredType(memb.getActualType()); } parent.addChild(value); } else { // create <structure> with name and access information StructureElement struct = new StructureElement(); if (memb.getFieldName() == null) { struct.setGetName(memb.getGetName()); struct.setSetName(memb.getSetName()); } else { struct.setFieldName(memb.getFieldName()); } setTypes(memb, struct); // check for optional value if (!memb.isRequired()) { struct.setUsageName("optional"); } // set details based on class handling MappingDetail detail = (MappingDetail)m_mappingDetailsMap.get(wtype); if (detail != null) { if (detail.isUseAbstract() && !detail.isExtended()) { // add 'map-as' and 'name' for abstract mapping QName qname = detail.getTypeQName(); if (qname == null) { struct.setMapAsName(wtype); } else { // set type name reference from structure struct.setMapAsQName(qname); // create binding dependency, if needed checkDependency(qname.getUri(), hold); } struct.setName(memb.getXmlName()); } else { // create binding dependency, if needed checkDependency(detail.getElementQName().getUri(), hold); } } else if (!m_global.isKnownMapping(wtype)){ // check for type needed if (memb.getActualType() != null) { struct.setDeclaredType(memb.getActualType()); } if (memb.getCreateType() != null) { struct.setCreateType(memb.getCreateType()); } if (memb.getFactoryMethod() != null) { struct.setFactoryName(memb.getFactoryMethod()); } // add a name if an optional value if (!memb.isRequired()) { struct.setName(memb.getXmlName()); } // handle inline structure definition ClassCustom icust = m_global.getClassCustomization(memb.getWorkingType()); addMemberBindings(icust, struct, hold); } parent.addChild(struct); } } } } /** * Add the <mapping> definition for a class to a binding. This creates * either an abstract mapping with a type name, or a concrete mapping with * an element name, as determined by the passed-in mapping information. If * the class is a concrete mapping that extends or implements another class * with an anonymous abstract mapping, the created <mapping> will extend * that base mapping. * TODO: type substitution requires extending the binding definition * * @param type fully qualified class name * @param detail mapping details */ private void addMapping(String type, MappingDetail detail) { // create the basic mapping structure ClassCustom cust = m_global.forceClassCustomization(type); MappingElement mapping = new MappingElement(); mapping.setClassName(type); mapping.setCreateType(cust.getCreateType()); mapping.setFactoryName(cust.getFactoryMethod()); // check type of definition required BindingHolder hold; if (detail.isUseAbstract()) { // create abstract mapping mapping.setAbstract(true); QName qname = detail.getTypeQName(); mapping.setTypeQName(qname); hold = findBinding(qname.getUri()); } else { // concrete mapping, just need simple name (namespace from binding) QName qname = detail.getElementQName(); mapping.setName(qname.getName()); hold = findBinding(qname.getUri()); } // check for superclass mapping to be extended (do this first for // compatibility with schema type extension) IClass clas = cust.getClassInformation(); StructureElement struct = null; String ptype = detail.getExtendsType(); if (ptype != null) { // create reference to parent mapping struct = new StructureElement(); MappingDetail pdetail = (MappingDetail)m_mappingDetailsMap.get(ptype); if (pdetail.isUseAbstract()) { // reference abstract mapped superclass QName qname = pdetail.getTypeQName(); if (qname == null) { throw new IllegalStateException("Internal error: unimplemented case"); // anonymous // struct.setMapAsName(ptype); } else { // set extension base type and reference mapping.setExtendsName(ptype); struct.setMapAsQName(qname); // create binding dependency, if needed checkDependency(qname.getUri(), hold); } } else { // reference concrete mapped superclass struct.setMapAsName(ptype); mapping.setExtendsName(ptype); } } else { // not extending a base mapping, check if need to include superclass IClass parent = clas.getSuperClass(); if (cust.isUseSuper() && parent != null) { ptype = parent.getName(); ClassCustom scust = m_global.getClassCustomization(ptype); if (scust != null && scust.getMembers().size() > 0) { MappingDetail pdetail = (MappingDetail)m_mappingDetailsMap.get(ptype); if (pdetail == null) { // handle parent details inline, if needed struct = new StructureElement(); struct.setDeclaredType(ptype); addMemberBindings(scust, struct, hold); if (struct.children().size() == 0) { struct = null; } } else { throw new IllegalStateException("Internal error: unsupported combination"); } } if (struct == null) { // check for interface with abstract mapping to extend if (!detail.isUseAbstract() && mapping.getExtendsName() == null) { String[] intfs = parent.getInterfaces(); for (int i = 0; i < intfs.length; i++) { String intf = intfs[i]; MappingDetail idetail = (MappingDetail)m_mappingDetailsMap.get(intf); if (idetail != null && idetail.isUseAbstract() && idetail.getTypeQName() == null) { // reference abstract mapped interface struct = new StructureElement(); struct.setMapAsName(intf);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?