Package org.eclipse.persistence.oxm

Examples of org.eclipse.persistence.oxm.XMLField


        return true;
    }

    public void marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object value, AbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
      NodeValue associatedNodeValue = null;
      XMLField associatedField = null;
      Object fieldValue = value;
      if(value instanceof XMLRoot) {
        XMLRoot rootValue = (XMLRoot)value;
        String localName = rootValue.getLocalName();
        String namespaceUri = rootValue.getNamespaceURI();
        fieldValue = rootValue.getObject();
        associatedField = getFieldForName(localName, namespaceUri);
        if(associatedField == null) {
          associatedField = xmlChoiceCollectionMapping.getClassToFieldMappings().get(value.getClass());
        }
      } else {
        associatedField = xmlChoiceCollectionMapping.getClassToFieldMappings().get(value.getClass());
      }

      if(associatedField != null) {
      associatedNodeValue = this.fieldToNodeValues.get(associatedField);
    }
     
      if(associatedNodeValue != null) {
        //Find the correct fragment
        XPathFragment frag = associatedField.getXPathFragment();
        while(frag != null) {
          if(associatedNodeValue.isOwningNode(frag)) {
            ContainerValue nestedNodeValue = (ContainerValue)((XMLChoiceCollectionMappingUnmarshalNodeValue)associatedNodeValue).getChoiceElementNodeValue();
            nestedNodeValue.marshalSingleValue(frag, marshalRecord, object, fieldValue, session, namespaceResolver, marshalContext);
            break;
View Full Code Here


    }

    private XMLField getFieldForName(String localName, String namespaceUri) {
      Iterator<XMLField> fields = fieldToNodeValues.keySet().iterator();
      while(fields.hasNext()) {
        XMLField nextField = fields.next();
        XPathFragment fragment = nextField.getXPathFragment();
        while(fragment != null && (!fragment.nameIsText())) {
          if(fragment.getNextFragment() == null || fragment.getHasText()) {
            if(fragment.getLocalName().equals(localName)) {
              String fragUri = fragment.getNamespaceURI();
              if((namespaceUri == null && fragUri == null) || (namespaceUri != null && fragUri != null && namespaceUri.equals(fragUri))) {
View Full Code Here

                    }
                    else {
                        xdm.setAttributeAccessor(new BaseEntityAccessor(attributeName, idx));
                        if (xdm.isDirectToFieldMapping()) {
                            XMLDirectMapping xmlDM = (XMLDirectMapping)xdm;
                            XMLField xmlField = (XMLField)xmlDM.getField();
                            Class clz = SCHEMA_2_CLASS.get(xmlField.getSchemaType());
                            if (clz != null) {
                                xmlField.setType(clz);
                            }
                            else {
                                xmlField.setType(OBJECT);
                            }
                        }
                        else if (xdm.isAbstractCompositeDirectCollectionMapping()) {
                            AbstractCompositeDirectCollectionMapping acdcm =
                                (AbstractCompositeDirectCollectionMapping)xdm;
                            XMLField xmlField = (XMLField)acdcm.getField();
                            Class clz = SCHEMA_2_CLASS.get(xmlField.getSchemaType());
                            if (clz != null) {
                                xmlField.setType(clz);
                            }
                            else {
                                xmlField.setType(OBJECT);
                            }
                        }
                    }
                }
                idx++;
View Full Code Here

        if (property.isOpenContent()) {
            uri = ((SDOProperty)property).getUri();
        } else {
            DatabaseMapping mapping = ((SDOProperty)property).getXmlMapping();
            if (mapping != null) {
                XMLField xmlField = (XMLField) mapping.getField();
                if (xmlField != null && xmlField.getXPathFragment() != null) {
                    uri = xmlField.getXPathFragment().getNamespaceURI();
                }
            }
        }
        return uri == null ? "" : uri;
    }
View Full Code Here

     * Return the JAXB mapping for the SDO property.  They are matched
     * on their XML schema representation.
     */
    DatabaseMapping getJAXBMappingForProperty(SDOProperty sdoProperty) {
        DatabaseMapping sdoMapping = sdoProperty.getXmlMapping();
        XMLField field;
        if (sdoMapping instanceof XMLObjectReferenceMapping) {
            XMLObjectReferenceMapping referenceMapping = (XMLObjectReferenceMapping) sdoMapping;
            field = (XMLField) referenceMapping.getFields().get(0);
        } else {
            field = (XMLField) sdoMapping.getField();
        }
        TreeObjectBuilder treeObjectBuilder = (TreeObjectBuilder) descriptor.getObjectBuilder();
        XPathNode xPathNode = treeObjectBuilder.getRootXPathNode();
        XPathFragment xPathFragment = field.getXPathFragment();
        while (xPathNode != null && xPathFragment != null) {
            if (xPathFragment.isAttribute()) {
                if (sdoProperty.isMany() && !sdoProperty.isContainment() && !sdoProperty.getType().isDataType()) {
                    xPathFragment = null;
                    break;
                }
                Map attributeChildrenMap = xPathNode.getAttributeChildrenMap();
                if (null == attributeChildrenMap) {
                    xPathNode = null;
                } else {
                    xPathNode = (XPathNode) xPathNode.getAttributeChildrenMap().get(xPathFragment);
                }
            } else {
                Map nonAttributeChildrenMap = xPathNode.getNonAttributeChildrenMap();
                if (null == nonAttributeChildrenMap) {
                    xPathNode = null;
                } else {
                    xPathNode = (XPathNode) xPathNode.getNonAttributeChildrenMap().get(xPathFragment);
                }
            }
            xPathFragment = xPathFragment.getNextFragment();
            if (xPathFragment != null && xPathFragment.nameIsText()) {
                if (sdoProperty.isMany() && !sdoProperty.isContainment()) {
                    xPathFragment = null;
                    break;
                }
            }
        }
        if (null == xPathFragment && xPathNode != null) {
            if (xPathNode.getNodeValue().isMappingNodeValue()) {
                MappingNodeValue mappingNodeValue = (MappingNodeValue) xPathNode.getNodeValue();
                return mappingNodeValue.getMapping();
            }
        }
        throw SDOException.sdoJaxbNoMappingForProperty(sdoProperty.getName(), field.getXPath());
    }
View Full Code Here

                    QName ctxQName = xmlRef.getSchemaContextAsQName(xmlDescriptor.getNamespaceResolver());
                    if (ctxQName.equals(record.getLeafElementType())) {
                        // don't write out xsi:type attribute
                    } else {
                        // write out the target descriptor's schema context as xsi:type
                        XMLField xmlField = (XMLField)xmlDescriptor.getInheritancePolicy().getClassIndicatorField();
                        if (xmlField.getLastXPathFragment().isAttribute()) {
                            writeXsiTypeAttribute(xmlDescriptor, (DOMRecord)record, xmlRef.getSchemaContext().substring(1));
                        } else {
                            writeXsiTypeAttribute(xmlDescriptor, (DOMRecord)record, xmlRef.getSchemaContext().substring(1));
                        }
                    }

                    // if the user has set the element type, but the target descriptor's
                    // schema context in not a global complex type or is null, delegate
                    // the work to the inheritance policy
                } else {
                    // no user-set element type, so proceed via inheritance policy
                    if (!xmlDescriptor.getInheritancePolicy().hasClassExtractor()) {
                      XMLField xmlField = (XMLField)xmlDescriptor.getInheritancePolicy().getClassIndicatorField();
                      if (xmlField.getLastXPathFragment().isAttribute()) {
                          getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(row);
                      } else {
                          getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(row);
                      }
                    }
View Full Code Here

        if (xsiPrefix == null) {
            xsiPrefix = xmlDescriptor.getNonNullNamespaceResolver().generatePrefix(XMLConstants.SCHEMA_INSTANCE_PREFIX);
            generated = true;
            writeXsiNamespace(row, xsiPrefix);
        }
        XMLField xmlField = (XMLField)xmlDescriptor.buildField("@" + xsiPrefix + ":" + XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
        if (generated) {
            xmlField.getLastXPathFragment().setGeneratedPrefix(true);
        }
        xmlField.getLastXPathFragment().setNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
        row.add(xmlField, typeValue);
    }
View Full Code Here

    private Setting convertToSetting(DatabaseMapping mapping, Object value) {
        XMLDescriptor xmlDescriptor = (XMLDescriptor) mapping.getDescriptor();
        NamespaceResolver nsResolver = xmlDescriptor.getNamespaceResolver();
        Setting rootSetting = new Setting();
        XMLField xmlField = (XMLField) mapping.getField();
        if (xmlField == null) {
            if (mapping instanceof XMLObjectReferenceMapping) {
                xmlField = (XMLField) ((XMLObjectReferenceMapping) mapping).getFields().get(0);
            } else if (mapping instanceof XMLCollectionReferenceMapping) {
                xmlField = (XMLField) ((XMLCollectionReferenceMapping) mapping).getFields().get(0);
            }
        }
        Setting setting = rootSetting;
        if (xmlField != null) {
            XPathFragment xPathFragment = xmlField.getXPathFragment();
            rootSetting = convertToSetting(xPathFragment, nsResolver);
            setting = rootSetting;

            while (xPathFragment.getNextFragment() != null) {
                xPathFragment = xPathFragment.getNextFragment();
View Full Code Here

     * @param seq
     * @param ct
     * @param workingSchema
     */
    private void processXMLCompositeDirectCollectionMapping(XMLCompositeDirectCollectionMapping mapping, Sequence seq, ComplexType ct, Schema workingSchema) {
        XMLField field = ((XMLField) (mapping).getField());

        String schemaTypeString = getSchemaTypeForElement(field, mapping.getAttributeElementClass(), workingSchema);
        Element element;
        if (field.usesSingleNode()) {
            SimpleType st = new SimpleType();
            org.eclipse.persistence.internal.oxm.schema.model.List list = new org.eclipse.persistence.internal.oxm.schema.model.List();

            if (schemaTypeString == null) {
                schemaTypeString = getSchemaTypeString(XMLConstants.ANY_SIMPLE_TYPE_QNAME, workingSchema);
            }
            list.setItemType(schemaTypeString);
            st.setList(list);

            element = buildElement(field.getXPathFragment(), null, Occurs.ZERO, null);
            element.setSimpleType(st);
        } else {
            element = buildElement(field.getXPathFragment(), schemaTypeString, Occurs.ZERO, null);
            element.setMaxOccurs(Occurs.UNBOUNDED);
        }
        seq.addElement(element);
    }
View Full Code Here

        targetNamespaceMapping.setXPath("@targetNamespace");
        descriptor.addMapping(targetNamespaceMapping);

        XMLDirectMapping defaultNamespaceMapping = new XMLDirectMapping();
        defaultNamespaceMapping.setAttributeName("defaultNamespace");
        XMLField xmlField = new XMLField();
        xmlField.setXPath("@xmlns");
        xmlField.getXPathFragment().setNamespaceURI(XMLConstants.XMLNS_URL);
        defaultNamespaceMapping.setField(xmlField);
        descriptor.addMapping(defaultNamespaceMapping);

        XMLAnyAttributeMapping attributesMapMapping = new XMLAnyAttributeMapping();
        attributesMapMapping.setAttributeName("attributesMap");
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.oxm.XMLField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.