📄 globalcustom.java
字号:
*/ public boolean isClassUsed(String type) { int split = type.lastIndexOf('.'); if (split < 0) { split = 0; } PackageCustom pack = (PackageCustom)m_packageMap.get(type.substring(0, split)); if (pack == null) { return false; } else { return pack.getClassCustomization(type.substring(split+1)) != null; } } /** * Get class customization information. * * @param type fully qualified class name * @return class information (<code>null</code> if not defined) */ public ClassCustom getClassCustomization(String type) { int split = type.lastIndexOf('.'); if (split < 0) { split = 0; } PackageCustom pack = (PackageCustom)m_packageMap.get(type.substring(0, split)); if (pack == null) { return null; } else { return pack.getClassCustomization(type.substring(split+1)); } } /** * Add new class customization information. This creates the customization * information and adds it to the internal structures, initializing all * values based on the settings inherited from <package> and <global> * elements of the structure. This method should only be used after first * calling {@link #getClassCustomization(String)} and obtaining a * <code>null</code> result. * * @param type fully qualified class name * @return class information */ public ClassCustom addClassCustomization(String type) { int split = type.lastIndexOf('.'); if (split < 0) { split = 0; } PackageCustom pack = getPackage(type.substring(0, split)); ClassCustom clas = pack.addClassCustomization(type.substring(split+1)); clas.apply(m_classLocator); return clas; } /** * Get class customization information, creating it if it doesn't already * exist. * * @param type fully qualified class name * @return class information */ public ClassCustom forceClassCustomization(String type) { ClassCustom custom = getClassCustomization(type); if (custom == null) { custom = addClassCustomization(type); } return custom; } /** * Check if type represents a known mapping. * * @param type fully qualified class name * @return known mapping flag */ public boolean isKnownMapping(String type) { // TODO: add known mappings for org.w3c.dom.*, etc. return false; } /** * Direction set text method. This is intended for use during unmarshalling. * TODO: add validation * * @param text * @param ictx */ private void setDirectionText(String text, IUnmarshallingContext ictx) { int direct = s_directionEnum.getValue(text); if (direct < 0) { throw new IllegalArgumentException("Value '" + text + "' not recognized for 'direction' attribute"); } else { m_isInput = direct != OUT_BINDING; m_isOutput = direct != IN_BINDING; } } /** * Direction get text method. This is intended for use during marshalling. * * @return text */ private String getDirectionText() { if (m_isInput && m_isOutput) { return s_directionEnum.getName(BOTH_BINDING); } else if (m_isInput) { return s_directionEnum.getName(IN_BINDING); } else { return s_directionEnum.getName(OUT_BINDING); } } /** * Fills in class information based on inspection of the actual class data. * This needs to be done as a separate step following unmarshalling, so that * the full details of the unmarshalled customizations are available. */ public void fillClasses() { // fix the namespace used as base for packages (if not set by override) if (getNamespace() == null) { setNamespace(getSpecifiedNamespace()); } // create information for some special classes ClassCustom custom = forceClassCustomization("java.util.List"); if (custom.getCreateType() == null && custom.getFactoryMethod() == null) { custom.setCreateType("java.util.ArrayList"); } custom = forceClassCustomization("java.util.Set"); if (custom.getCreateType() == null && custom.getFactoryMethod() == null) { custom.setCreateType("java.util.HashSet"); } custom = forceClassCustomization("java.util.Collection"); if (custom.getCreateType() == null && custom.getFactoryMethod() == null) { custom.setCreateType("java.util.ArrayList"); } // fill in details for all packages for (Iterator iter = m_packageMap.values().iterator(); iter.hasNext();) { PackageCustom pack = (PackageCustom)iter.next(); pack.apply(m_classLocator); } // fill in details for any extension elements if (m_extensionChildren != null) { for (int i = 0; i < m_extensionChildren.size(); i++) { Object child = m_extensionChildren.get(i); if (child instanceof IApply) { ((IApply)child).apply(m_classLocator); } } } } // // Package structure support /** * Get package customizations. If the requested package is already defined * the existing instance will be returned, otherwise a new instance will be * created (along with any ancestor packages) and added to the structure. * * @param name * @return package */ public PackageCustom getPackage(String name) { // find existing package information PackageCustom pack = (PackageCustom)m_packageMap.get(name); if (pack == null) { // create new package information PackageCustom parent = null; int split = name.lastIndexOf('.'); String simple = name; String full = name; if (split > 0) { parent = getPackage(name.substring(0, split)); simple = name.substring(split+1); full = parent.getName() + '.' + simple; } else if (name.length() > 0) { parent = getPackage(""); } pack = new PackageCustom(simple, full, parent); m_packageMap.put(name, pack); pack.apply(m_classLocator); } return pack; } /** * Unmarshaller implementation for class. This handles the nested structure * of packages and classes, using the abstract mappings defined by the * binding to handle all the actual details. */ public static class Mapper implements IUnmarshaller { private int m_packageIndex; private int m_classIndex; public boolean isPresent(IUnmarshallingContext ictx) throws JiBXException { return true; } /** * Build the fully-qualified name for a package or class by appending * the supplied name attribute value to the fully-qualified name of the * containing package. * * @param contain * @param ctx * @throws JiBXException */ private String buildFullName(PackageCustom contain, UnmarshallingContext ctx) throws JiBXException { String lead = ""; if (contain != null) { lead = contain.getName() + '.'; } return lead + ctx.attributeText(null, "name"); } private PackageCustom unmarshalPackage(GlobalCustom global, PackageCustom contain, UnmarshallingContext ctx) throws JiBXException { // create class instance and populate mapped values PackageCustom inst = global.getPackage(buildFullName(contain, ctx)); ctx.pushTrackedObject(inst); ctx.getUnmarshaller(m_packageIndex).unmarshal(inst, ctx); // handle nested package and class information while (ctx.isStart()) { String element = ctx.getName(); if (PackageCustom.ELEMENT_NAME.equals(element)) { unmarshalPackage(global, inst, ctx); } else if (ClassCustom.ELEMENT_NAME.equals(element)) { unmarshalClass(global, inst, ctx); } } ctx.popObject(); ctx.parsePastEndTag(null, PackageCustom.ELEMENT_NAME); return inst; } private ClassCustom unmarshalClass(GlobalCustom global, PackageCustom contain, UnmarshallingContext ctx) throws JiBXException { // create class instance and populate mapped values String name = buildFullName(contain, ctx); int split = name.lastIndexOf('.'); if (split < 0) { split = 0; } PackageCustom pack = global.getPackage(name.substring(0, split)); String simple = name.substring(split+1); ClassCustom inst = pack.getClassCustomization(simple); if (inst == null) { inst = pack.addClassCustomization(simple); } ctx.pushTrackedObject(inst); ctx.getUnmarshaller(m_classIndex).unmarshal(inst, ctx); ctx.popObject(); ctx.parsePastEndTag(null, ClassCustom.ELEMENT_NAME); return inst; } public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // set up the mapping indexes UnmarshallingContext ctx = (UnmarshallingContext)ictx; IBindingFactory factory = ((UnmarshallingContext)ictx).getFactory(); m_packageIndex = factory.getTypeIndex(PackageCustom.ELEMENT_NAME); m_classIndex = factory.getTypeIndex(ClassCustom.ELEMENT_NAME); if (m_packageIndex < 0 || m_classIndex < 0) { throw new JiBXException("Missing required abstract mappings"); } // process all child elements GlobalCustom global = (GlobalCustom)obj; while (ctx.isStart()) { // check type of child present String element = ctx.getName(); if (PackageCustom.ELEMENT_NAME.equals(element)) { unmarshalPackage(global, null, ctx); } else if (ClassCustom.ELEMENT_NAME.equals(element)) { unmarshalClass(global, null, ctx); } else { global.internalAddExtensionChild(ctx.unmarshalElement()); } } return global; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -