Search in sources :

Example 1 with NamespaceResolver

use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.

the class JAXBUnmarshaller method setProperty.

/**
 * Set a property on the JAXBUnmarshaller. Attempting to set any unsupported
 * property will result in a jakarta.xml.bind.PropertyException.
 * @see org.eclipse.persistence.jaxb.UnmarshallerProperties
 */
@Override
public void setProperty(String key, Object value) throws PropertyException {
    if (key == null) {
        throw new IllegalArgumentException();
    }
    SessionLog logger = AbstractSessionLog.getLog();
    if (logger.shouldLog(SessionLog.FINE, SessionLog.MOXY)) {
        logger.log(SessionLog.FINE, SessionLog.MOXY, "moxy_set_unmarshaller_property", new Object[] { key, value });
    }
    if (MOXySystemProperties.moxyLogPayload != null && xmlUnmarshaller.isLogPayload() == null) {
        xmlUnmarshaller.setLogPayload(MOXySystemProperties.moxyLogPayload);
    }
    if (key.equals(UnmarshallerProperties.MEDIA_TYPE)) {
        MediaType mType = null;
        if (value instanceof MediaType) {
            mType = (MediaType) value;
        } else if (value instanceof String) {
            mType = MediaType.getMediaType((String) value);
        }
        if (mType == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        xmlUnmarshaller.setMediaType(mType);
    } else if (key.equals(UnmarshallerProperties.UNMARSHALLING_CASE_INSENSITIVE)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        xmlUnmarshaller.setCaseInsensitive((Boolean) value);
    } else if (key.equals(UnmarshallerProperties.AUTO_DETECT_MEDIA_TYPE)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        xmlUnmarshaller.setAutoDetectMediaType((Boolean) value);
    } else if (key.equals(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX)) {
        xmlUnmarshaller.setAttributePrefix((String) value);
    } else if (UnmarshallerProperties.JSON_INCLUDE_ROOT.equals(key)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        xmlUnmarshaller.setIncludeRoot((Boolean) value);
    } else if (UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER.equals(key)) {
        if (value == null) {
            xmlUnmarshaller.setNamespaceResolver(null);
        } else if (value instanceof Map) {
            Map<String, String> namespaces = (Map<String, String>) value;
            NamespaceResolver nr = new NamespaceResolver();
            Iterator<Entry<String, String>> namesapcesIter = namespaces.entrySet().iterator();
            for (int i = 0; i < namespaces.size(); i++) {
                Entry<String, String> nextEntry = namesapcesIter.next();
                nr.put(nextEntry.getValue(), nextEntry.getKey());
            }
            xmlUnmarshaller.setNamespaceResolver(nr);
        } else if (value instanceof NamespacePrefixMapper) {
            xmlUnmarshaller.setNamespaceResolver(new PrefixMapperNamespaceResolver((NamespacePrefixMapper) value, null));
        }
    } else if (UnmarshallerProperties.JSON_VALUE_WRAPPER.equals(key)) {
        xmlUnmarshaller.setValueWrapper((String) value);
    } else if (UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR.equals(key)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        xmlUnmarshaller.setNamespaceSeparator((Character) value);
    } else if (UnmarshallerProperties.JSON_USE_XSD_TYPES_WITH_PREFIX.equals(key)) {
        xmlUnmarshaller.getJsonTypeConfiguration().setUseXsdTypesWithPrefix((Boolean) value);
    } else if (UnmarshallerProperties.JSON_TYPE_COMPATIBILITY.equals(key)) {
        xmlUnmarshaller.getJsonTypeConfiguration().setJsonTypeCompatibility((Boolean) value);
    } else if (UnmarshallerProperties.JSON_TYPE_ATTRIBUTE_NAME.equals(key)) {
        xmlUnmarshaller.getJsonTypeConfiguration().setJsonTypeAttributeName((String) value);
    } else if (UnmarshallerProperties.ID_RESOLVER.equals(key)) {
        setIDResolver((IDResolver) value);
    } else if (SUN_ID_RESOLVER.equals(key) || SUN_JSE_ID_RESOLVER.equals(key)) {
        if (value == null) {
            setIDResolver(null);
        } else {
            setIDResolver(new IDResolverWrapper(value));
        }
    } else if (UnmarshallerProperties.OBJECT_GRAPH.equals(key)) {
        if (value instanceof ObjectGraphImpl) {
            xmlUnmarshaller.setUnmarshalAttributeGroup(((ObjectGraphImpl) value).getAttributeGroup());
        } else if (value instanceof String || value == null) {
            xmlUnmarshaller.setUnmarshalAttributeGroup(value);
        } else {
            throw org.eclipse.persistence.exceptions.JAXBException.invalidValueForObjectGraph(value);
        }
    } else if (UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME.equals(key)) {
        xmlUnmarshaller.setWrapperAsCollectionName((Boolean) value);
    } else if (UnmarshallerProperties.BEAN_VALIDATION_MODE.equals(key)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        this.beanValidationMode = ((BeanValidationMode) value);
    } else if (UnmarshallerProperties.BEAN_VALIDATION_FACTORY.equals(key)) {
        // Null value is allowed
        this.prefValidatorFactory = value;
    } else if (UnmarshallerProperties.BEAN_VALIDATION_GROUPS.equals(key)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        this.beanValidationGroups = ((Class<?>[]) value);
    } else if (UnmarshallerProperties.BEAN_VALIDATION_NO_OPTIMISATION.equals(key)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        this.bvNoOptimisation = ((boolean) value);
    } else if (UnmarshallerProperties.DISABLE_SECURE_PROCESSING.equals(key)) {
        if (value == null) {
            throw new PropertyException(key, Constants.EMPTY_STRING);
        }
        boolean disabled = value instanceof String ? Boolean.parseBoolean((String) value) : (boolean) value;
        xmlUnmarshaller.setDisableSecureProcessing(disabled);
    } else if (UnmarshallerProperties.MOXY_LOG_PAYLOAD.equals(key)) {
        xmlUnmarshaller.setLogPayload(((boolean) value));
    } else if (UnmarshallerProperties.MOXY_LOGGING_LEVEL.equals(key)) {
        if (value instanceof String) {
            AbstractSessionLog.getLog().setLevel(LogLevel.toValue((String) value).getId(), SessionLog.MOXY);
        } else {
            AbstractSessionLog.getLog().setLevel(((LogLevel) value).getId(), SessionLog.MOXY);
        }
    } else {
        throw new PropertyException(key, value);
    }
}
Also used : IDResolver(org.eclipse.persistence.oxm.IDResolver) PropertyException(jakarta.xml.bind.PropertyException) ObjectGraphImpl(org.eclipse.persistence.internal.jaxb.ObjectGraphImpl) LogLevel(org.eclipse.persistence.logging.LogLevel) PrefixMapperNamespaceResolver(org.eclipse.persistence.internal.oxm.record.namespaces.PrefixMapperNamespaceResolver) SessionLog(org.eclipse.persistence.logging.SessionLog) AbstractSessionLog(org.eclipse.persistence.logging.AbstractSessionLog) Entry(java.util.Map.Entry) IDResolverWrapper(org.eclipse.persistence.internal.jaxb.IDResolverWrapper) MediaType(org.eclipse.persistence.oxm.MediaType) PrefixMapperNamespaceResolver(org.eclipse.persistence.internal.oxm.record.namespaces.PrefixMapperNamespaceResolver) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) Map(java.util.Map) HashMap(java.util.HashMap) NamespacePrefixMapper(org.eclipse.persistence.oxm.NamespacePrefixMapper)

Example 2 with NamespaceResolver

use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.

the class DynamicJAXBUsingXMLNamesTestCases method testCreateEntityByXPathNameCollision2.

public void testCreateEntityByXPathNameCollision2() throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream iStream = classLoader.getResourceAsStream(EXAMPLE_XSD_2);
    if (iStream == null) {
        fail("Couldn't load metadata file [" + EXAMPLE_XSD_2 + "]");
    }
    Map<String, InputStream> properties = new HashMap<String, InputStream>();
    properties.put(DynamicJAXBContextFactory.XML_SCHEMA_KEY, iStream);
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("ns0", "mynamespace");
    DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.eclipse.persistence.testing.jaxb.dynamic", classLoader, properties);
    DynamicEntity person = (DynamicEntity) jaxbContext.createByQualifiedName("mynamespace", "person", false);
    assertNotNull("Could not create Dynamic Entity.", person);
    // Set name by XPath
    jaxbContext.setValueByXPath(person, "ns0:first-name/text()", nsResolver, "Larry");
    // Create address by XPath, set street by XPath
    DynamicEntity address = jaxbContext.createByXPath(person, "ns0:address", nsResolver, DynamicEntity.class);
    jaxbContext.setValueByXPath(address, "ns0:street/text()", nsResolver, "400 CNN Plaza");
    // Create person's address by XPath
    jaxbContext.setValueByXPath(person, "ns0:address", nsResolver, address);
    Document marshalDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    jaxbContext.createMarshaller().marshal(person, marshalDoc);
    DynamicEntity person2 = (DynamicEntity) jaxbContext.createUnmarshaller().unmarshal(marshalDoc);
    DynamicEntity address2 = jaxbContext.getValueByXPath(person2, "ns0:address", nsResolver, DynamicEntity.class);
    String newName = jaxbContext.getValueByXPath(person2, "ns0:first-name/text()", nsResolver, String.class);
    String newStreet = jaxbContext.getValueByXPath(address2, "ns0:street/text()", nsResolver, String.class);
    String newStreet2 = jaxbContext.getValueByXPath(person2, "ns0:address/ns0:street/text()", nsResolver, String.class);
    assertEquals("Larry", newName);
    assertEquals("400 CNN Plaza", newStreet);
    assertEquals("400 CNN Plaza", newStreet2);
}
Also used : DynamicJAXBContext(org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext) HashMap(java.util.HashMap) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) InputStream(java.io.InputStream) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) Document(org.w3c.dom.Document)

Example 3 with NamespaceResolver

use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.

the class DynamicJAXBUsingXMLNamesTestCases method testCreateEntityByXMLName.

public void testCreateEntityByXMLName() throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream iStream = classLoader.getResourceAsStream(EXAMPLE_OXM);
    if (iStream == null) {
        fail("Couldn't load metadata file [" + EXAMPLE_OXM + "]");
    }
    HashMap<String, Source> metadataSourceMap = new HashMap<String, Source>();
    metadataSourceMap.put("org.eclipse.persistence.testing.jaxb.dynamic", new StreamSource(iStream));
    Map<String, Map<String, Source>> properties = new HashMap<String, Map<String, Source>>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataSourceMap);
    DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.eclipse.persistence.testing.jaxb.dynamic", classLoader, properties);
    DynamicEntity employee = (DynamicEntity) jaxbContext.createByQualifiedName(EMPLOYEE_NAMESPACE, EMPLOYEE_TYPE_NAME, false);
    assertNotNull("Could not create Dynamic Entity.", employee);
    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("ns0", "mynamespace");
    jaxbContext.setValueByXPath(employee, "name/text()", nsResolver, "Larry King");
    jaxbContext.setValueByXPath(employee, "employee-id/text()", nsResolver, "CA34287");
    Document marshalDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    jaxbContext.createMarshaller().marshal(employee, marshalDoc);
    DynamicEntity employee2 = (DynamicEntity) jaxbContext.createUnmarshaller().unmarshal(marshalDoc);
    String newName = jaxbContext.getValueByXPath(employee2, "name/text()", nsResolver, String.class);
    String newId = jaxbContext.getValueByXPath(employee2, "employee-id/text()", nsResolver, String.class);
    assertEquals("Larry King", newName);
    assertEquals("CA34287", newId);
}
Also used : HashMap(java.util.HashMap) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Document(org.w3c.dom.Document) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) DynamicJAXBContext(org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with NamespaceResolver

use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.

the class AnnotationsProcessor method generateWrapperForMapClass.

private Class<?> generateWrapperForMapClass(JavaClass mapClass, JavaClass keyClass, JavaClass valueClass, TypeMappingInfo typeMappingInfo) {
    String packageName = JAXB_DEV;
    NamespaceResolver combinedNamespaceResolver = new NamespaceResolver();
    if (!helper.isBuiltInJavaType(keyClass)) {
        String keyPackageName = keyClass.getPackageName();
        packageName = packageName + DOT_CHR + keyPackageName;
        NamespaceInfo keyNamespaceInfo = getPackageInfoForPackage(keyClass).getNamespaceInfo();
        if (keyNamespaceInfo != null) {
            java.util.Vector<Namespace> namespaces = keyNamespaceInfo.getNamespaceResolver().getNamespaces();
            for (Namespace n : namespaces) {
                combinedNamespaceResolver.put(n.getPrefix(), n.getNamespaceURI());
            }
        }
    }
    if (!helper.isBuiltInJavaType(valueClass)) {
        String valuePackageName = valueClass.getPackageName();
        packageName = packageName + DOT_CHR + valuePackageName;
        NamespaceInfo valueNamespaceInfo = getPackageInfoForPackage(valueClass).getNamespaceInfo();
        if (valueNamespaceInfo != null) {
            java.util.Vector<Namespace> namespaces = valueNamespaceInfo.getNamespaceResolver().getNamespaces();
            for (Namespace n : namespaces) {
                combinedNamespaceResolver.put(n.getPrefix(), n.getNamespaceURI());
            }
        }
    }
    String namespace = this.defaultTargetNamespace;
    if (namespace == null) {
        namespace = EMPTY_STRING;
    }
    PackageInfo packageInfo = packageToPackageInfoMappings.get(mapClass.getPackageName());
    if (packageInfo == null) {
        packageInfo = getPackageToPackageInfoMappings().get(packageName);
    } else {
        if (packageInfo.getNamespace() != null) {
            namespace = packageInfo.getNamespace();
        }
        getPackageToPackageInfoMappings().put(packageName, packageInfo);
    }
    if (packageInfo == null) {
        packageInfo = new PackageInfo();
        packageInfo.setNamespaceInfo(new NamespaceInfo());
        packageInfo.setNamespace(namespace);
        packageInfo.setNamespaceResolver(combinedNamespaceResolver);
        getPackageToPackageInfoMappings().put(packageName, packageInfo);
    }
    int beginIndex = keyClass.getName().lastIndexOf(DOT_CHR) + 1;
    String keyName = keyClass.getName().substring(beginIndex);
    int dollarIndex = keyName.indexOf(DOLLAR_SIGN_CHR);
    if (dollarIndex > -1) {
        keyName = keyName.substring(dollarIndex + 1);
    }
    beginIndex = valueClass.getName().lastIndexOf(DOT_CHR) + 1;
    String valueName = valueClass.getName().substring(beginIndex);
    dollarIndex = valueName.indexOf(DOLLAR_SIGN_CHR);
    if (dollarIndex > -1) {
        valueName = valueName.substring(dollarIndex + 1);
    }
    String collectionClassShortName = mapClass.getRawName().substring(mapClass.getRawName().lastIndexOf(DOT_CHR) + 1);
    String suggestedClassName = keyName + valueName + collectionClassShortName;
    String qualifiedClassName = packageName + DOT_CHR + suggestedClassName;
    qualifiedClassName = getNextAvailableClassName(qualifiedClassName);
    String qualifiedInternalClassName = qualifiedClassName.replace(DOT_CHR, SLASH_CHR);
    String internalKeyName = keyClass.getQualifiedName().replace(DOT_CHR, SLASH_CHR);
    String internalValueName = valueClass.getQualifiedName().replace(DOT_CHR, SLASH_CHR);
    Type mapType = Type.getType(L + mapClass.getRawName().replace(DOT_CHR, SLASH_CHR) + SEMI_COLON);
    EclipseLinkASMClassWriter cw = new EclipseLinkASMClassWriter();
    String sig = "Lorg/eclipse/persistence/internal/jaxb/many/MapValue<L" + mapType.getInternalName() + "<L" + internalKeyName + ";L" + internalValueName + ";>;>;";
    cw.visit(Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, qualifiedInternalClassName, sig, "org/eclipse/persistence/internal/jaxb/many/MapValue", null);
    // Write Field: @... public Map entry
    String fieldSig = L + mapType.getInternalName() + "<L" + internalKeyName + ";L" + internalValueName + ";>;";
    FieldVisitor fv = cw.visitField(Opcodes.ACC_PUBLIC, "entry", L + mapType.getInternalName() + SEMI_COLON, fieldSig, null);
    fv.visitAnnotation(Type.getDescriptor(XmlElement.class), true);
    if (typeMappingInfo != null) {
        Annotation[] annotations = typeMappingInfo.getAnnotations();
        if (annotations != null) {
            for (Annotation nextAnnotation : annotations) {
                if (nextAnnotation != null && !(nextAnnotation instanceof XmlElement) && !(nextAnnotation instanceof XmlJavaTypeAdapter)) {
                    String annotationClassName = nextAnnotation.annotationType().getName();
                    AnnotationVisitor av = fv.visitAnnotation(L + annotationClassName.replace(DOT_CHR, SLASH_CHR) + SEMI_COLON, true);
                    for (Method next : nextAnnotation.annotationType().getDeclaredMethods()) {
                        try {
                            Object nextValue = next.invoke(nextAnnotation);
                            if (nextValue instanceof Class) {
                                Type nextType = Type.getType(L + ((Class) nextValue).getName().replace(DOT_CHR, SLASH_CHR) + SEMI_COLON);
                                nextValue = nextType;
                            }
                            av.visit(next.getName(), nextValue);
                        } catch (InvocationTargetException ignored) {
                        // ignore the invocation target exception here.
                        } catch (IllegalAccessException ignored) {
                        // ignore the illegal access exception here.
                        }
                    }
                    av.visitEnd();
                }
            }
        }
    }
    fv.visitEnd();
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "org/eclipse/persistence/internal/jaxb/many/MapValue", "<init>", "()V", false);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
    // Write: @XmlTransient public void setItem(???)
    String methodSig = "(L" + mapType.getInternalName() + "<L" + internalKeyName + ";L" + internalValueName + ";>;)V";
    mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setItem", "(L" + mapType.getInternalName() + ";)V", methodSig, null);
    // TODO: Verify that we really want to put @XmlTranient on setItem
    // method
    mv.visitAnnotation("Ljakarta/xml/bind/annotation/XmlTransient;", true);
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitFieldInsn(Opcodes.PUTFIELD, qualifiedInternalClassName, "entry", L + mapType.getInternalName() + SEMI_COLON);
    mv.visitInsn(Opcodes.RETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    // Replacement?:LocalVariableTypeTableAttribute cvAttr = new
    // LocalVariableTypeTableAttribute();
    // mv.visitAttribute(cvAttr);
    mv.visitMaxs(2, 2);
    mv.visitEnd();
    // Write @XmlTransient public ??? getItem()
    methodSig = "()L" + mapType.getInternalName() + "<L" + internalKeyName + ";L" + internalValueName + ";>;";
    mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getItem", "()L" + mapType.getInternalName() + SEMI_COLON, methodSig, null);
    mv.visitAnnotation("Ljakarta/xml/bind/annotation/XmlTransient;", true);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, qualifiedInternalClassName, "entry", L + mapType.getInternalName() + SEMI_COLON);
    mv.visitInsn(Opcodes.ARETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
    mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_BRIDGE + Opcodes.ACC_SYNTHETIC, "getItem", "()Ljava/lang/Object;", null, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, qualifiedInternalClassName, "getItem", "()L" + mapType.getInternalName() + SEMI_COLON, false);
    mv.visitInsn(Opcodes.ARETURN);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
    mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_BRIDGE + Opcodes.ACC_SYNTHETIC, "setItem", "(Ljava/lang/Object;)V", null, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitTypeInsn(Opcodes.CHECKCAST, mapType.getInternalName());
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, qualifiedInternalClassName, "setItem", "(L" + mapType.getInternalName() + ";)V", false);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(2, 2);
    mv.visitEnd();
    // Write @XmlType(namespace)
    AnnotationVisitor av = cw.visitAnnotation("Ljakarta/xml/bind/annotation/XmlType;", true);
    av.visit("namespace", namespace);
    cw.visitEnd();
    byte[] classBytes = cw.toByteArray();
    return generateClassFromBytes(qualifiedClassName, classBytes);
}
Also used : XmlJavaTypeAdapter(jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter) Label(org.eclipse.persistence.internal.libraries.asm.Label) EclipseLinkASMClassWriter(org.eclipse.persistence.internal.libraries.asm.EclipseLinkASMClassWriter) Method(java.lang.reflect.Method) JavaMethod(org.eclipse.persistence.jaxb.javamodel.JavaMethod) FieldVisitor(org.eclipse.persistence.internal.libraries.asm.FieldVisitor) Namespace(org.eclipse.persistence.internal.oxm.Namespace) JavaAnnotation(org.eclipse.persistence.jaxb.javamodel.JavaAnnotation) Annotation(java.lang.annotation.Annotation) InvocationTargetException(java.lang.reflect.InvocationTargetException) MethodVisitor(org.eclipse.persistence.internal.libraries.asm.MethodVisitor) Type(org.eclipse.persistence.internal.libraries.asm.Type) XmlType(jakarta.xml.bind.annotation.XmlType) XmlAccessorType(jakarta.xml.bind.annotation.XmlAccessorType) ParameterizedType(java.lang.reflect.ParameterizedType) XmlMimeType(jakarta.xml.bind.annotation.XmlMimeType) XmlAccessType(org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType) XmlSchemaType(jakarta.xml.bind.annotation.XmlSchemaType) AnnotationVisitor(org.eclipse.persistence.internal.libraries.asm.AnnotationVisitor) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XmlElement(jakarta.xml.bind.annotation.XmlElement) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass)

Example 5 with NamespaceResolver

use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.

the class Property method isPositional.

/**
 * Indicates if this property is mapped by position, i.e. 'name="data[1]"',
 * or is mapped by attribute value (predicate mapping), i.e.
 * 'personal-info[@pi-type='last-name']/name[@name-type='surname']/text()'
 */
public boolean isPositional() {
    if (getXmlPath() == null) {
        return false;
    }
    Field<XMLConversionManager, NamespaceResolver> field = new XMLField(getXmlPath());
    XPathFragment frag = field.getXPathFragment();
    // loop until we have the last non-null, non-attribute, non-text fragment
    while (true) {
        if (frag.getNextFragment() != null && !frag.getNextFragment().isAttribute() && !frag.getNextFragment().nameIsText()) {
            frag = frag.getNextFragment();
        } else {
            break;
        }
    }
    return frag.containsIndex() || frag.getPredicate() != null;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Aggregations

NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)227 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)142 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)74 XMLField (org.eclipse.persistence.oxm.XMLField)36 XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)36 Document (org.w3c.dom.Document)35 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)23 QName (javax.xml.namespace.QName)20 InputStream (java.io.InputStream)17 StringReader (java.io.StringReader)17 StringWriter (java.io.StringWriter)17 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)16 InputSource (org.xml.sax.InputSource)14 Element (org.w3c.dom.Element)13 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)12 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)12 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)10 HashMap (java.util.HashMap)9 Project (org.eclipse.persistence.sessions.Project)9 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)8