📄 bindingbuilder.java
字号:
} boolean hasval = !"void".equals(meth.getTypeName()); store = new NestedCollection.IndexedStore(meth, isdoub, hasval); } else if (cf.isArray()) { store = new NestedCollection.ArrayStore(itype, isdoub); } else { ctx.throwStartTagException ("Unknown collection " + "type with no add or store method defined"); } } if (bdef.isOutput()) { // define strategy for loading items from collection if (lname != null) { ClassItem smeth = cf.getMethod(szname, "()I"); if (smeth == null) { ctx.throwStartTagException ("Size method " + szname + " not found in collection type " + cf.getName()); } ClassItem lmeth = cf.getBestMethod(lname, itype, new String[] { "int" }); if (lmeth == null) { ctx.throwStartTagException ("Load method " + lname + " not found in collection type " + cf.getName()); } load = new NestedCollection. IndexedLoad(smeth, isdoub, lmeth); } else if (iname != null) { String mname = "hasNext"; String nname = "next"; ClassItem meth = cf.getMethod(iname, "()Ljava/util/Iterator;"); if (meth == null) { mname = "hasMoreElements"; nname = "nextElement"; meth = cf.getMethod(iname, "()Ljava/util/Enumeration;"); if (meth == null) { ctx.throwStartTagException ("Iterator method " + iname + " not found in collection type " + cf.getName()); } } load = new NestedCollection. IteratorLoad(meth, isdoub, "java.util.Iterator." + mname, "java.util.Iterator." + nname); } else if (cf.isArray()) { load = new NestedCollection.ArrayLoad(itype, isdoub); } else { ctx.throwStartTagException ("Unknown collection " + "type with no load method defined"); } } } // unmarshal basics of nested structure NestedBase nest; boolean ordered = ctx.attributeBoolean(URI_ATTRIBUTES, COMMON_ORDERED, true); boolean flex = ctx.attributeBoolean(URI_ATTRIBUTES, COMMON_FLEXIBLE, false); boolean nillable = ctx.attributeBoolean(URI_ATTRIBUTES, COMMON_NILLABLE, false); if (nillable) { contain.getBindingRoot().setSchemaInstanceUsed(); } if (coll) { // create collection definition nest = new NestedCollection(contain, icobj, ordered, opt, flex, itype, load, store); nest.unmarshal(ctx); ctx.parsePastStartTag(URI_ELEMENTS, COLLECTION_ELEMENT); } else { // create structure definition boolean choice = ctx.attributeBoolean(URI_ATTRIBUTES, COMMON_CHOICE, false); boolean dupl = ctx.attributeBoolean(URI_ATTRIBUTES, COMMON_DUPLICATES, false); nest = new NestedStructure(contain, icobj, ordered, choice, flex, false, hasobj, dupl); nest.unmarshal(ctx); ctx.parsePastStartTag(URI_ELEMENTS, STRUCTURE_ELEMENT); } // unmarshal child bindings with optional label String ctype = (itype == null) ? "java.lang.Object" : itype; unmarshalFormats(ctx, nest.getDefinitionContext()); unmarshalMappings(ctx, contain, null, uord); unmarshalStructureChildren(ctx, nest, icobj, coll | (implic && !hasobj), ctype); if (top == null) { top = nest; } // special check for structure wrapping value boolean impstruct = false; boolean childs = nest.hasContent(); if (implic && !coll && childs) { ArrayList contents = nest.getContents(); impstruct = true; for (int i = 0; i < contents.size(); i++) { if (!(contents.get(i) instanceof ValueChild)) { impstruct = false; break; } else { ValueChild vchild = (ValueChild)contents.get(i); if (!vchild.isImplicit()) { impstruct = false; break; } } } } if (impstruct) { comp = nest; nest.setObjectContext(cobj); if (name != null) { comp = new ElementWrapper(defc, name, comp, nillable); if (bind != null && implic) { if (!hasprop) { ArrayList contents = nest.getContents(); impstruct = true; for (int i = 0; i < contents.size(); i++) { if (contents.get(i) instanceof ValueChild) { ValueChild vchild = (ValueChild)contents.get(i); vchild.switchProperty(); } } } prop.setOptional(false); } } } else { // check for children defined boolean addref = false; if (!childs) { if (coll) { // add mapping as only child if (ctype.equals("java.lang.Object")) { nest.addComponent (new DirectGeneric(nest, null)); } else { nest.addComponent(new MappingReference(contain, new PropertyDefinition(ctype, cobj, false), ctype, null, null, icobj, null, true, false)); } childs = true; } else if (name != null) { // must be abstract mappping reference, create child addref = true; } } // handle nested children comp = top; if (childs || addref) { // define component property wrapping object binding boolean optprop = hasprop && prop.isOptional(); if (bind != null) { boolean skip = name != null && optprop; comp = new ComponentProperty(prop, comp, skip); bind.setWrappedComponent(nest); } // create reference to mapping as special case // this allows structure with name but no children to // use abstract mapping if (addref) { PropertyDefinition thisprop = new PropertyDefinition(bind, false); nest.addComponent(new MappingReference (nest, thisprop, comp.getType(), null, null, icobj, null, false, false)); } if (name != null) { comp = new ElementWrapper(defc, name, comp, nillable); if (bind != null && implic) { if (!hasprop) { ((ElementWrapper)comp).setDirect(true); } prop.setOptional(false); } if (optprop) { ((ElementWrapper)comp).setOptionalNormal(true); boolean isobj = bind != null; ((ElementWrapper)comp). setStructureObject(isobj); ((ElementWrapper)comp).setDirect(isobj); comp = new OptionalStructureWrapper(comp, prop, isobj); prop.setOptional(false); } else if (opt && !implic) { ((ElementWrapper)comp).setOptionalNormal(true); comp = new OptionalStructureWrapper(comp, prop, false); prop.setOptional(false); } } } else { // treat as mapping, with either type or generic String type = prop.getTypeName(); if (prop.equals("java.lang.Object")) { comp = new ComponentProperty(prop, new DirectGeneric(contain, null), false); } else { comp = new MappingReference(contain, prop, type, null, null, icobj, name, false, false); } } } // set object binding as definition for label if (label != null) { defc.addNamedStructure(label, top); } } } } else { // structure with no separate object, verify no forbidden attributes if (isObjectBinding(ctx)) { ctx.throwStartTagException("Object attributes not " + "allowed without property definition"); } else if (isDirectObject(ctx)) { ctx.throwStartTagException("Marshaller and unmarshaller not " + "allowed without property definition"); } // check for reference to structure defined elsewhere if (mapping) { // handle "this" reference as anonymous property PropertyDefinition prop = new PropertyDefinition(cobj, opt); // handle reference to defined mapping comp = unmarshalMappingRef(ctx, contain, cobj, prop, name); implic = true; } else if (ctx.hasAttribute(URI_ATTRIBUTES, COMMON_USING)) { // make sure forbidden attribute not used if (ctx.hasAttribute(URI_ATTRIBUTES, COMMON_ORDERED)) { ctx.throwStartTagException(COMMON_ORDERED + " attribute " + " not allowed with " + COMMON_USING + " attribute"); } // validate and configure reference to structure in context comp = unmarshalStructureRef(ctx, contain, name, null, cobj); } else { // unmarshal children as nested structure boolean ordered = ctx.attributeBoolean(URI_ATTRIBUTES, COMMON_ORDERED, true); boolean choice = ctx.attributeBoolean(URI_ATTRIBUTES, COMMON_CHOICE, false); boolean flex = ctx.attributeBoolean(URI_ATTRIBUTES, COMMON_FLEXIBLE, false); boolean dupl = ctx.attributeBoolean(URI_ATTRIBUTES, COMMON_DUPLICATES, false); NestedStructure nest = new NestedStructure(contain, cobj, ordered, choice, flex, false, hasprop, dupl); nest.unmarshal(ctx); // unmarshal child bindings with optional label String label = ctx.attributeText(URI_ATTRIBUTES, COMMON_LABEL, null); ctx.parsePastStartTag(URI_ELEM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -