public void setChild(Object wrapper, int i, ElementInfo childElement, Object value) { Object wrapperValue = wrapper; Class<?> wrapperClass = wrapperValue.getClass(); // FIXME: We probably should use the jaxb-reflection to handle the properties try { String prop = childElement.getQName().getLocalPart(); boolean collection = (value instanceof Collection); Method getter = null; for (Method m : wrapperClass.getMethods()) { Class<?>[] paramTypes = m.getParameterTypes(); if (paramTypes.length == 1 && m.getName().equals("set" + capitalize(prop))) { m.invoke(wrapperValue, new Object[] {value}); return; } if (collection && paramTypes.length == 0 && m.getName().equals("get" + capitalize(prop))) { getter = m; } } if (getter != null && Collection.class.isAssignableFrom(getter.getReturnType())) { ((Collection)getter.invoke(wrapperValue)).addAll((Collection)value); } } catch (Throwable e) { throw new TransformationException(e); } }
List<OMElement> elements = groupedElementList.get(index); ElementInfo childElement = childElements.get(index); if (!childElement.isMany()) { Object next = elements.isEmpty() ? null : attachXSIType(childElement, elements.get(0)); retVal.add(next);
private static ElementInfo getElementInfo(XmlSchemaElement element) { if (element == null) { return null; } ElementInfo elementInfo = new ElementInfo(element.getQName(), getTypeInfo(element.getSchemaType())); elementInfo.setMany(element.getMaxOccurs() > 1); elementInfo.setNillable(element.isNillable()); elementInfo.setOmissible(element.getMinOccurs()==0); return elementInfo; }
private void addChild(OMElement wrapper, ElementInfo childElement, OMElement element) { if (element == null) { // Prefer xsi:nil="true" if (childElement.isNillable()) { OMElement e = wrapper.getOMFactory().createOMElement(childElement.getQName(), wrapper); attachXSINil(e); } // else, we might have minOccurs="0", so don't add anything to the wrapper. return; } QName elementName = childElement.getQName(); // Make it a bit tolerating of element QName if (!elementName.equals(element.getQName())) { OMNamespace namespace = factory.createOMNamespace(elementName.getNamespaceURI(), elementName.getPrefix()); element.setNamespace(namespace); element.setLocalName(childElement.getQName().getLocalPart()); } wrapper.addChild(element); }
schema.appendChild(wrapper); wrapper.setAttribute("name", entry.getKey().getLocalPart()); if (entry.getValue().size() == 1 && entry.getValue().get(0).getQName() == null) { QName typeName = entry.getValue().get(0).getType().getQName(); String nsURI = typeName.getNamespaceURI(); if ("".equals(nsURI)) { for (ElementInfo element: entry.getValue()) { Element xsElement = schemaDoc.createElementNS(SCHEMA_NS, "xs:element"); if (element.isMany()) { xsElement.setAttribute("maxOccurs", "unbounded"); xsElement.setAttribute("name", element.getQName().getLocalPart()); if (element.isNillable()) { xsElement.setAttribute("nillable", "true"); QName typeName = element.getType().getQName(); String nsURI = typeName.getNamespaceURI(); if ("".equals(nsURI)) {
boolean matchedLastElementGroup = false; for (ElementInfo currentElementInfo : elementInfoList) { currentElementInfoQName = currentElementInfo.getQName(); logger.fine("Iterating to next ElementInfo child with QName: " + currentElementInfoQName + ". Control variables lookAtNextElementGroup = " + lookAtNextElementGroup + matchedLastElementGroup = true; if (currentElementInfo.isMany()) { if (currentElementInfo.isOmissible()) { logger.fine("Child ElementInfo 'isOmissible' = true, so look at next ElementInfo.");
return new ElementInfo(element, new TypeInfo(ANYTYPE_QNAME, false, null)); if (byte[].class == javaType){ typeInfo = helper.getTypeInfo(javaType, dataType.getLogical()); element = new ElementInfo(name, typeInfo); element.setMany(false); } else { typeInfo = helper.getTypeInfo(javaType.isArray() ? javaType.getComponentType() : javaType, dataType.getLogical()); element = new ElementInfo(name, typeInfo); element.setMany(javaType.isArray()); element.setMany(true); element.setNillable(!javaType.isPrimitive()); return element;
/** * Create xis:type if required * @param childElement * @param element * @return */ private OMElement attachXSIType(ElementInfo childElement, OMElement element) { TypeInfo type = childElement.getType(); if (type != null && type.getQName() != null) { OMAttribute attr = element.getAttribute(XSI_TYPE_QNAME); if (attr == null) { String typeNS = type.getQName().getNamespaceURI(); if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(typeNS)) { return element; } OMNamespace ns = element.getOMFactory().createOMNamespace(typeNS, "_typens_"); element.declareNamespace(ns); OMNamespace xsiNS = element.getOMFactory().createOMNamespace(XSI_TYPE_QNAME.getNamespaceURI(), XSI_TYPE_QNAME.getPrefix()); element.declareNamespace(xsiNS); attr = element.getOMFactory().createOMAttribute("type", xsiNS, "_typens_:" + type.getQName().getLocalPart()); element.addAttribute(attr); } } return element; }
type = ((XMLType)logical).getTypeName(); outputElements.add(new ElementInfo(element, new TypeInfo(type, false, null))); inputElements.add(new ElementInfo(element, new TypeInfo(type, false, null))); outputElements.add(new ElementInfo(element, new TypeInfo(type, false, null))); } else if (mode.equals(ParameterMode.OUT)) { outputElements.add(new ElementInfo(element, new TypeInfo(type, false, null))); } else { inputElements.add(new ElementInfo(element, new TypeInfo(type, false, null))); String dbOut = outputWrapperDT != null ? outputWrapperDT.getDataBinding() : JAXB_DATABINDING; WrapperInfo inputWrapperInfo = new WrapperInfo(dbIn, new ElementInfo(inputWrapper, null), inputElements); WrapperInfo outputWrapperInfo = new WrapperInfo(dbOut, new ElementInfo(outputWrapper, null), outputElements);
schema.appendChild(wrapper); wrapper.setAttribute("name", entry.getKey().getLocalPart()); if (entry.getValue().size() == 1 && entry.getValue().get(0).getQName() == null) { QName typeName = entry.getValue().get(0).getType().getQName(); String nsURI = typeName.getNamespaceURI(); if ("".equals(nsURI)) { for (ElementInfo element: entry.getValue()) { Element xsElement = schemaDoc.createElementNS(SCHEMA_NS, "xs:element"); if (element.isMany()) { xsElement.setAttribute("maxOccurs", "unbounded"); xsElement.setAttribute("name", element.getQName().getLocalPart()); if (element.isNillable()) { xsElement.setAttribute("nillable", "true"); QName typeName = element.getType().getQName(); String nsURI = typeName.getNamespaceURI(); if ("".equals(nsURI)) {
private static ElementInfo getElementInfo(XmlSchemaElement element) { if (element == null) { return null; } ElementInfo elementInfo = new ElementInfo(element.getQName(), getTypeInfo(element.getSchemaType())); elementInfo.setMany(element.getMaxOccurs() > 1); elementInfo.setNillable(element.isNillable()); elementInfo.setOmissible(element.getMinOccurs()==0); return elementInfo; }
return new ElementInfo(element, new TypeInfo(ANYTYPE_QNAME, false, null)); if (byte[].class == javaType){ typeInfo = helper.getTypeInfo(javaType, dataType.getLogical()); element = new ElementInfo(name, typeInfo); element.setMany(false); } else { typeInfo = helper.getTypeInfo(javaType.isArray() ? javaType.getComponentType() : javaType, dataType.getLogical()); element = new ElementInfo(name, typeInfo); element.setMany(javaType.isArray()); element.setMany(true); element.setNillable(!javaType.isPrimitive()); return element;
public void setChild(Object wrapper, int i, ElementInfo childElement, Object value) { Object wrapperValue = wrapper; Class<?> wrapperClass = wrapperValue.getClass(); // FIXME: We probably should use the jaxb-reflection to handle the properties try { String prop = childElement.getQName().getLocalPart(); boolean collection = (value instanceof Collection); Method getter = null; for (Method m : wrapperClass.getMethods()) { Class<?>[] paramTypes = m.getParameterTypes(); if (paramTypes.length == 1 && m.getName().equals("set" + capitalize(prop))) { m.invoke(wrapperValue, new Object[] {value}); return; } if (collection && paramTypes.length == 0 && m.getName().equals("get" + capitalize(prop))) { getter = m; } } if (getter != null && Collection.class.isAssignableFrom(getter.getReturnType())) { ((Collection)getter.invoke(wrapperValue)).addAll((Collection)value); } } catch (Throwable e) { throw new TransformationException(e); } }
public void setChild(OMElement wrapper, int i, ElementInfo childElement, Object value) { if (childElement.isMany()) { Object[] elements = (Object[])value; if (value != null) { for (Object e : elements) { addChild(wrapper, childElement, (OMElement)e); } } } else { OMElement element = (OMElement)value; addChild(wrapper, childElement, element); } }