📄 bindinggenerator.java
字号:
mapping.setExtendsName(intf); break; } } } } } } if (struct != null) { mapping.addChild(struct); } // add all details of class member handling to binding addMemberBindings(cust, mapping, hold); hold.getBinding().addTopChild(mapping); if (mapping.isAbstract()) { // check for both abstract and concrete mapping needed detail.setAbstractMapping(mapping); if (detail.isUseConcrete()) { // reference abstract mapping from concrete mapping mapping = new MappingElement(); mapping.setClassName(type); mapping.setCreateType(cust.getCreateType()); mapping.setFactoryName(cust.getFactoryMethod()); mapping.setName(cust.getElementName()); // set create type for concrete mapping of abstract class if (clas.isAbstract()) { mapping.setAbstract(true); } // define content as structure reference to abstract mapping struct = new StructureElement(); QName qname = detail.getTypeQName(); struct.setMapAsQName(qname); mapping.addChild(struct); hold = findBinding(qname.getUri()); hold.getBinding().addTopChild(mapping); detail.setConcreteMapping(mapping); } } else { detail.setConcreteMapping(mapping); } } /** * Find the binding to be used for a particular namespace. If this is the * first time a particular namespace was requested, a new binding will be * created for that namespace and returned. * * @param uri namespace URI (<code>null</code> if no namespace) * @return binding holder */ public BindingHolder findBinding(String uri) { BindingHolder hold = (BindingHolder)m_uriBindingMap.get(uri); if (hold == null) { hold = new BindingHolder(uri, m_uriBindingMap.size()+1); m_uriBindingMap.put(uri, hold); BindingElement binding = hold.getBinding(); binding.setForceClasses(m_global.isForceClasses()); binding.setTrackSource(m_global.isTrackSource()); binding.setAddConstructors(m_global.isAddConstructors()); binding.setInBinding(m_global.isInput()); binding.setOutBinding(m_global.isOutput()); } return hold; } /** * Add the details for mapping a class. * * @param abstr force abstract mapping flag * @param type fully-qualified class name * @return mapping details */ private MappingDetail addMappingDetails(Boolean abstr, String type) { // check for existing detail MappingDetail detail = (MappingDetail)m_mappingDetailsMap.get(type); if (detail == null) { // check if superclass is base for extension ClassCustom cust = m_global.getClassCustomization(type); String stype = null; IClass sclas = cust.getClassInformation().getSuperClass(); while (sclas != null) { if (m_directSet.contains(sclas.getName())) { stype = sclas.getName(); Boolean isabs = Boolean.valueOf(sclas.isAbstract()); MappingDetail sdetail = addMappingDetails(isabs, stype); sdetail.setExtended(true); break; } else { sclas = sclas.getSuperClass(); } } // create mapping details as specified boolean abs = (abstr == null) ? cust.isMapAbstract() : abstr.booleanValue(); detail = new MappingDetail(cust.getTypeQName(), cust.getElementQName(), stype); if (abs || !cust.isConcrete()) { detail.setUseAbstract(true); } else { detail.setUseConcrete(true); } m_mappingDetailsMap.put(type, detail); // force concrete mapping if extension or base for extension if (abs && (sclas != null || m_superSet.contains(type))) { detail.setUseConcrete(true); } // check if package usable as target for binding code if (m_targetPackage == null && cust.getClassInformation().isModifiable()) { m_targetPackage = ((PackageCustom)cust.getParent()).getName(); } } else if (abstr != null) { // mapping detail already generated, just make sure of variety if (abstr.booleanValue()) { detail.setUseAbstract(true); } else { detail.setUseConcrete(true); } } return detail; } /** * Find closure of references from a supplied list of classes. References * counted, and direct references are accumulated for handling. The supplied * list may include generic classes with type parameters. * * @param classes * @param refmap */ private void findReferences(List classes, ReferenceCountMap refmap) { for (int i = 0; i < classes.size(); i++) { String type = (String)classes.get(i); int split = type.indexOf('<'); if (split > 0) { type = type.substring(split+1, type.length()-1); } expandReferences(type, refmap); } } /** * Add mapping details for classes referenced more than once. * * @param refmap */ private void addReferencedMappings(ReferenceCountMap refmap) { for (Iterator iter = refmap.iterator(); iter.hasNext();) { String type = (String)iter.next(); if (refmap.getCount(type) > 1 && !m_mappingDetailsMap.containsKey(type)) { addMappingDetails(null, type); } } } /** * Fix all references between bindings. This needs to be called after the * generation of binding components is completed, in order to make sure that * required namespace definitions are included in the output bindings. */ private void fixBindingReferences() { ArrayList uris = getNamespaces(); for (int i = 0; i < uris.size(); i++) { String uri = (String)uris.get(i); BindingHolder holder = (BindingHolder)m_uriBindingMap.get(uri); holder.fixReferences(); } } /** * Generate the mapping definitions for classes referenced more than once. * * @param refmap */ private void generateReferencedMappings(ReferenceCountMap refmap) { for (Iterator iter = refmap.iterator(); iter.hasNext();) { String type = (String)iter.next(); if (refmap.getCount(type) > 1) { MappingDetail detail = (MappingDetail)m_mappingDetailsMap.get(type); if (!detail.isGenerated()) { addMapping(type, detail); detail.setGenerated(true); } } } } /** * Generate mappings for a list of classes. The mapping details must have * been configured before this method is called. * * @param classes */ private void generateMappings(List classes) { for (int i = 0; i < classes.size(); i++) { String type = (String)classes.get(i); MappingDetail detail = (MappingDetail)m_mappingDetailsMap.get(type); if (!detail.isGenerated()) { addMapping(type, detail); detail.setGenerated(true); } } } /** * Fix the base classes that are to be used as extension types. This step is * needed to generate the substitution group structures for classes which * are both referenced directly and extended by other classes. The method * must be called after all mapping details have been constucted but before * the actual binding generation. */ private void fixBaseClasses() { for (Iterator iter = m_directSet.iterator(); iter.hasNext();) { String type = (String)iter.next(); MappingDetail detail = (MappingDetail)m_mappingDetailsMap.get(type); if (detail != null && detail.isExtended()) { detail.setUseConcrete(true); } } } /** * Generate binding(s) for a list of classes. This creates a <mapping> * definition for each class in the list, and either embeds <structure> * definitions or creates separate <mapping>s for other classes * referenced by these classes. If all the classes use the same namespace * only the binding for that namespace will be created; otherwise, a * separate binding will be created for each namespace. * * @param abstr force abstract mapping flag (determined by class * customizations if <code>null</code>) * @param classes class list */ public void generate(Boolean abstr, List classes) { // start by expanding and counting references from supplied classes ReferenceCountMap refmap = new ReferenceCountMap(); findReferences(classes, refmap); // set the classes to be handled with <mapping> definitions for (int i = 0; i < classes.size(); i++) { addMappingDetails(abstr, (String)classes.get(i)); } addReferencedMappings(refmap); fixBaseClasses(); // generate the binding(s) generateMappings(classes); generateReferencedMappings(refmap); fixBindingReferences(); } /** * Generate binding(s) for lists of classes. This creates a <mapping> * definition for each class in the lists, and either embeds <structure> * definitions or creates separate <mapping>s for other classes * referenced by these classes. If all the classes use the same namespace * only the binding for that namespace will be created; otherwise, a * separate binding will be created for each namespace. * * @param qnames list of names for concrete mappings * @param concrs list of classes to be given concrete mappings * @param abstrs list of classes to be given abstract mappings */ public void generateSpecified(ArrayList qnames, List concrs, List abstrs) { // start by expanding and counting references from supplied classes ReferenceCountMap refmap = new ReferenceCountMap(); findReferences(concrs, refmap); findReferences(abstrs, refmap); // set classes to be handled with mapping definitions for (int i = 0; i < concrs.size(); i++) { MappingDetail detail = addMappingDetails(Boolean.FALSE, (String)concrs.get(i)); detail.setElementQName((QName)qnames.get(i)); } for (int i = 0; i < abstrs.size(); i++) { addMappingDetails(Boolean.TRUE, (String)abstrs.get(i)); } addReferencedMappings(refmap); fixBaseClasses(); // generate the binding(s) generateMappings(concrs); generateMappings(abstrs); generateReferencedMappings(refmap); fixBindingReferences(); } /** * Get the mapping details for a class. This method should only be used * after the {@link #generate(boolean, ArrayList)} method has * been called. * * @param type fully-qualified class name * @return mapping details, or <code>null</code> if none */ public MappingDetail getMappingDetail(String type) { return (MappingDetail)m_mappingDetailsMap.get(type); } /** * Get the binding definition for a namespace. This method should only be * used after the {@link #generate(boolean, ArrayList)} method * has been called.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -