Search in sources :

Example 1 with ConversionException

use of org.eclipse.persistence.exceptions.ConversionException in project eclipselink by eclipse-ee4j.

the class ContentTypeTestCases method testImageJpegSpecified_ConentTypeImageGif.

public void testImageJpegSpecified_ConentTypeImageGif() throws JAXBException {
    RootImageJpeg root = new RootImageJpeg();
    root.setMimeType(IMAGE_GIF);
    root.setImage(IMAGE);
    try {
        marshaller.marshal(root, new StringWriter());
    } catch (MarshalException ex) {
        ConversionException ce = (ConversionException) ex.getLinkedException();
        XMLMarshalException me = (XMLMarshalException) ce.getInternalException();
        if (me.getErrorCode() != XMLMarshalException.NO_ENCODER_FOR_MIME_TYPE) {
            throw ex;
        } else {
            return;
        }
    }
    assertEquals(IMAGE_GIF, attachmentMarshaller.getMimeType());
}
Also used : ConversionException(org.eclipse.persistence.exceptions.ConversionException) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) MarshalException(jakarta.xml.bind.MarshalException) StringWriter(java.io.StringWriter) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException)

Example 2 with ConversionException

use of org.eclipse.persistence.exceptions.ConversionException in project eclipselink by eclipse-ee4j.

the class ContentTypeTestCases method testNoMimeTypeSpecied_ContentTypeImageGif.

public void testNoMimeTypeSpecied_ContentTypeImageGif() throws JAXBException {
    Root root = new Root();
    root.setMimeType(IMAGE_GIF);
    root.setImage(IMAGE);
    try {
        marshaller.marshal(root, new StringWriter());
    } catch (MarshalException ex) {
        ConversionException ce = (ConversionException) ex.getLinkedException();
        XMLMarshalException me = (XMLMarshalException) ce.getInternalException();
        if (me.getErrorCode() != XMLMarshalException.NO_ENCODER_FOR_MIME_TYPE) {
            throw ex;
        } else {
            return;
        }
    }
    assertEquals(IMAGE_GIF, attachmentMarshaller.getMimeType());
}
Also used : ConversionException(org.eclipse.persistence.exceptions.ConversionException) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) MarshalException(jakarta.xml.bind.MarshalException) StringWriter(java.io.StringWriter) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException)

Example 3 with ConversionException

use of org.eclipse.persistence.exceptions.ConversionException in project eclipselink by eclipse-ee4j.

the class ContentTypeTestCases method testImageStarSpecified_ConentTypeImageGif.

public void testImageStarSpecified_ConentTypeImageGif() throws JAXBException {
    RootImageStar root = new RootImageStar();
    root.setMimeType(IMAGE_GIF);
    root.setImage(IMAGE);
    try {
        marshaller.marshal(root, new StringWriter());
    } catch (MarshalException ex) {
        ConversionException ce = (ConversionException) ex.getLinkedException();
        XMLMarshalException me = (XMLMarshalException) ce.getInternalException();
        if (me.getErrorCode() != XMLMarshalException.NO_ENCODER_FOR_MIME_TYPE) {
            throw ex;
        } else {
            return;
        }
    }
    assertEquals(IMAGE_GIF, attachmentMarshaller.getMimeType());
}
Also used : ConversionException(org.eclipse.persistence.exceptions.ConversionException) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) MarshalException(jakarta.xml.bind.MarshalException) StringWriter(java.io.StringWriter) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException)

Example 4 with ConversionException

use of org.eclipse.persistence.exceptions.ConversionException in project eclipselink by eclipse-ee4j.

the class EntityManagerSetupImpl method preInitializeCanonicalMetamodel.

/**
 * INTERNAL:
 * First phase of canonical metamodel initialization.  For each class the metamodel is aware of, check
 * for a canonical metamodel class and initialize each attribute in it with a proxy that can cause the
 * rest of the metamodel population.  Attributes are found reflectively rather than through the metamodel
 * to avoid having to further initialize the metamodel.
 */
public void preInitializeCanonicalMetamodel(EntityManagerFactoryImpl factory) {
    // 338837: verify that the collection is not empty - this would mean entities did not make it into the search path
    if (null == metaModel.getManagedTypes() || metaModel.getManagedTypes().isEmpty()) {
        getSession().log(SessionLog.FINER, SessionLog.METAMODEL, "metamodel_type_collection_empty");
    }
    for (ManagedType manType : metaModel.getManagedTypes()) {
        boolean classInitialized = false;
        String className = MetadataHelper.getQualifiedCanonicalName(((ManagedTypeImpl) manType).getJavaTypeName(), getSession());
        try {
            Class<?> clazz = this.getSession().getDatasourcePlatform().convertObject(className, ClassConstants.CLASS);
            classInitialized = true;
            this.getSession().log(SessionLog.FINER, SessionLog.METAMODEL, "metamodel_canonical_model_class_found", className);
            Field[] fields = null;
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
                fields = AccessController.doPrivileged(new PrivilegedGetDeclaredFields(clazz));
            } else {
                fields = PrivilegedAccessHelper.getDeclaredFields(clazz);
            }
            for (Field attribute : fields) {
                if (Attribute.class.isAssignableFrom(attribute.getType())) {
                    Object assignedAttribute = null;
                    if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
                        assignedAttribute = AccessController.doPrivileged(new PrivilegedGetValueFromField(attribute, null));
                    } else {
                        assignedAttribute = PrivilegedAccessHelper.getValueFromField(attribute, null);
                    }
                    AttributeProxyImpl proxy = null;
                    if (assignedAttribute == null) {
                        if (SingularAttribute.class.isAssignableFrom(attribute.getType())) {
                            proxy = new SingularAttributeProxyImpl();
                        } else if (MapAttribute.class.isAssignableFrom(attribute.getType())) {
                            proxy = new MapAttributeProxyImpl();
                        } else if (SetAttribute.class.isAssignableFrom(attribute.getType())) {
                            proxy = new SetAttributeProxyImpl();
                        } else if (ListAttribute.class.isAssignableFrom(attribute.getType())) {
                            proxy = new ListAttributeProxyImpl();
                        } else if (CollectionAttribute.class.isAssignableFrom(attribute.getType())) {
                            proxy = new CollectionAttributeProxyImpl();
                        }
                        if (proxy != null) {
                            attribute.setAccessible(true);
                            attribute.set(null, proxy);
                        }
                    } else if (assignedAttribute instanceof AttributeProxyImpl) {
                        proxy = (AttributeProxyImpl) assignedAttribute;
                    }
                    if (proxy != null) {
                        proxy.addFactory(factory);
                    }
                }
            }
        } catch (PrivilegedActionException pae) {
            getSession().logThrowable(SessionLog.FINEST, SessionLog.METAMODEL, pae);
        } catch (IllegalAccessException iae) {
            getSession().logThrowable(SessionLog.FINEST, SessionLog.METAMODEL, iae);
        } catch (ConversionException ce) {
        }
        if (!classInitialized) {
            getSession().log(SessionLog.FINER, SessionLog.METAMODEL, "metamodel_canonical_model_class_not_found", className);
        }
    }
}
Also used : ConversionException(org.eclipse.persistence.exceptions.ConversionException) ManagedType(jakarta.persistence.metamodel.ManagedType) PrivilegedActionException(java.security.PrivilegedActionException) MapAttributeProxyImpl(org.eclipse.persistence.internal.jpa.metamodel.proxy.MapAttributeProxyImpl) CollectionAttributeProxyImpl(org.eclipse.persistence.internal.jpa.metamodel.proxy.CollectionAttributeProxyImpl) EntityManagerFactoryProvider.getConfigPropertyAsString(org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString) SingularAttributeProxyImpl(org.eclipse.persistence.internal.jpa.metamodel.proxy.SingularAttributeProxyImpl) Field(java.lang.reflect.Field) PrivilegedGetDeclaredField(org.eclipse.persistence.internal.security.PrivilegedGetDeclaredField) PrivilegedGetValueFromField(org.eclipse.persistence.internal.security.PrivilegedGetValueFromField) MapAttribute(jakarta.persistence.metamodel.MapAttribute) ListAttributeProxyImpl(org.eclipse.persistence.internal.jpa.metamodel.proxy.ListAttributeProxyImpl) PrivilegedGetValueFromField(org.eclipse.persistence.internal.security.PrivilegedGetValueFromField) SingularAttributeProxyImpl(org.eclipse.persistence.internal.jpa.metamodel.proxy.SingularAttributeProxyImpl) CollectionAttributeProxyImpl(org.eclipse.persistence.internal.jpa.metamodel.proxy.CollectionAttributeProxyImpl) AttributeProxyImpl(org.eclipse.persistence.internal.jpa.metamodel.proxy.AttributeProxyImpl) MapAttributeProxyImpl(org.eclipse.persistence.internal.jpa.metamodel.proxy.MapAttributeProxyImpl) ListAttributeProxyImpl(org.eclipse.persistence.internal.jpa.metamodel.proxy.ListAttributeProxyImpl) SetAttributeProxyImpl(org.eclipse.persistence.internal.jpa.metamodel.proxy.SetAttributeProxyImpl) PrivilegedGetDeclaredFields(org.eclipse.persistence.internal.security.PrivilegedGetDeclaredFields) SetAttributeProxyImpl(org.eclipse.persistence.internal.jpa.metamodel.proxy.SetAttributeProxyImpl) ListAttribute(jakarta.persistence.metamodel.ListAttribute)

Example 5 with ConversionException

use of org.eclipse.persistence.exceptions.ConversionException in project eclipselink by eclipse-ee4j.

the class XPathEngine method getDataObjectFromQuery.

// extract value from query and acquire dataobject that meets this requirement
/**
 *Access the DataObject value by using the fragment containing query informations.
 *
 * @param frag                  one string fragment in the path
 * @param openBracketIndex      the index of open bracket in a fragment
 * @param closeBracketIndex     the index of close bracket in a fragment
 * @param equalsignIndex        the index of equalsign in string fragment quoted by brackets
 * @param caller                the DataObject that passes the path information in
 * @param callerProperty        the name of the property
 * @return                      the DataObject as value of the property having name as the above callerProperty
 */
private DataObject getDataObjectFromQuery(String frag, int openBracketIndex, int closeBracketIndex, int equalsignIndex, DataObject caller, String callerProperty) {
    try {
        // trim off any whitespace for property names
        String propertyNameOfQryDataObject = frag.substring(openBracketIndex + 1, equalsignIndex + openBracketIndex).trim();
        List objects = caller.getList(caller.getInstanceProperty(callerProperty));
        String query = frag.substring(equalsignIndex + openBracketIndex + 1, closeBracketIndex);
        String value = null;
        int firstQuoteIndex = query.indexOf('\'');
        int lastQuoteIndex = query.lastIndexOf('\'');
        if ((firstQuoteIndex == -1) && (lastQuoteIndex == -1)) {
            // !! note: case: [number=1'23'] is assume not to happen !!
            firstQuoteIndex = query.indexOf('\"');
            lastQuoteIndex = query.lastIndexOf('\"');
        }
        if ((firstQuoteIndex != -1) && (lastQuoteIndex != -1) && (firstQuoteIndex < lastQuoteIndex)) {
            // quoted string existed
            value = query.substring(firstQuoteIndex + 1, lastQuoteIndex);
        } else {
            // if the value is not enclosed on quotes, trim off any whitespace
            value = query.trim();
        }
        Iterator iterObjects = objects.iterator();
        Object queryValue = value;
        Object actualValue = null;
        while (iterObjects.hasNext()) {
            DataObject cur = (DataObject) iterObjects.next();
            Property p = cur.getInstanceProperty(propertyNameOfQryDataObject);
            if (p != null) {
                try {
                    queryValue = XMLConversionManager.getDefaultXMLManager().convertObject(queryValue, p.getType().getInstanceClass());
                } catch (ConversionException e) {
                // do nothing, skip
                }
                if (!p.isMany()) {
                    actualValue = cur.get(p);
                    if (actualValue.equals(queryValue)) {
                        return cur;
                    }
                } else {
                    // case p is many type
                    List values = cur.getList(p);
                    Iterator iterValues = values.iterator();
                    while (iterValues.hasNext()) {
                        actualValue = iterValues.next();
                        if (actualValue.equals(queryValue)) {
                            return cur;
                        }
                    }
                }
            }
        }
        return null;
    } catch (IllegalArgumentException e) {
        return null;
    }
}
Also used : ConversionException(org.eclipse.persistence.exceptions.ConversionException) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) Iterator(java.util.Iterator) List(java.util.List) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) Property(commonj.sdo.Property)

Aggregations

ConversionException (org.eclipse.persistence.exceptions.ConversionException)45 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)9 ConversionManager (org.eclipse.persistence.internal.helper.ConversionManager)7 CacheId (org.eclipse.persistence.internal.identitymaps.CacheId)7 Time (java.sql.Time)6 XMLConversionException (org.eclipse.persistence.exceptions.XMLConversionException)6 QName (javax.xml.namespace.QName)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)4 MarshalException (jakarta.xml.bind.MarshalException)3 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 PrivilegedActionException (java.security.PrivilegedActionException)3 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)3 ValidationException (org.eclipse.persistence.exceptions.ValidationException)3 ManagedType (jakarta.persistence.metamodel.ManagedType)2 Iterator (java.util.Iterator)2 Vector (java.util.Vector)2