Search in sources :

Example 1 with DescriptorException

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

the class MapValueAttributeAccessor method getAttributeValueFromObject.

@Override
public Object getAttributeValueFromObject(Object object) throws DescriptorException {
    Object value = nestedAccessor.getAttributeValueFromObject(object);
    if (null == value) {
        return null;
    }
    Object results = containerPolicy.containerInstance(((Map) value).size());
    Set<Entry> entrySet = ((Map) value).entrySet();
    if (null == entrySet) {
        return results;
    }
    for (Entry entry : entrySet) {
        MapEntry nextEntry;
        try {
            nextEntry = (MapEntry) generatedEntryClass.getConstructor().newInstance();
        } catch (Exception e) {
            return null;
        }
        nextEntry.setKey(entry.getKey());
        nextEntry.setValue(entry.getValue());
        containerPolicy.addInto(nextEntry, results, null);
    }
    return results;
}
Also used : Entry(java.util.Map.Entry) Map(java.util.Map) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException)

Example 2 with DescriptorException

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

the class FactoryTestCases method testNoDefaultConstructorFactoryError.

/**
 * Concrete factory class with no default constructor, non-static factory method (ERROR).
 */
public void testNoDefaultConstructorFactoryError() throws Exception {
    Class<?>[] classes = new Class<?>[] { Employee.class };
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream bindings = classLoader.getResourceAsStream(NODEFAULTCONSTRUCTOR_ERROR);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, bindings);
    Exception caughtException = null;
    try {
        jaxbContext = JAXBContextFactory.createContext(classes, properties);
    } catch (Exception e) {
        caughtException = e;
    }
    assertNotNull(caughtException);
    // "The instance creation method [{0}], with no parameters, does not exist, or is not accessible."
    try {
        JAXBException jaxbException = (JAXBException) caughtException;
        IntegrityException integrityException = (IntegrityException) jaxbException.getLinkedException();
        DescriptorException descriptorException = (DescriptorException) integrityException.getIntegrityChecker().getCaughtExceptions().firstElement();
        assertEquals("Incorrect error code:", DescriptorException.NO_SUCH_METHOD_WHILE_INITIALIZING_INSTANTIATION_POLICY, descriptorException.getErrorCode());
    } catch (Exception e) {
        fail("The expected Exception structure was not thrown, instead caught: " + caughtException.getLocalizedMessage());
    }
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) JAXBException(jakarta.xml.bind.JAXBException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) JAXBException(jakarta.xml.bind.JAXBException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException)

Example 3 with DescriptorException

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

the class FactoryTestCases method testAbstractFactoryError.

/**
 * Abstract factory class, non-static factory method (ERROR).
 */
public void testAbstractFactoryError() throws Exception {
    Class<?>[] classes = new Class<?>[] { Employee.class };
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream bindings = classLoader.getResourceAsStream(ABSTRACTFACTORY_ERROR);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, bindings);
    Exception caughtException = null;
    try {
        jaxbContext = JAXBContextFactory.createContext(classes, properties);
    } catch (Exception e) {
        caughtException = e;
    }
    assertNotNull(caughtException);
    // "The factory class does not define a public default constructor, or the constructor raised an exception."
    try {
        JAXBException jaxbException = (JAXBException) caughtException;
        IntegrityException integrityException = (IntegrityException) jaxbException.getLinkedException();
        DescriptorException descriptorException = (DescriptorException) integrityException.getIntegrityChecker().getCaughtExceptions().firstElement();
        assertEquals("Incorrect error code:", DescriptorException.INSTANTIATION_WHILE_CONSTRUCTOR_INSTANTIATION_OF_FACTORY, descriptorException.getErrorCode());
    } catch (Exception e) {
        fail("The expected Exception structure was not thrown, instead caught: " + caughtException.getLocalizedMessage());
    }
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) JAXBException(jakarta.xml.bind.JAXBException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) JAXBException(jakarta.xml.bind.JAXBException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException)

Example 4 with DescriptorException

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

the class FactoryTestCases method testDomainClassFactoryMethodError.

/**
 * No factory class specified, no default constructor on domain class, non-static factory method on domain class (ERROR).
 */
public void testDomainClassFactoryMethodError() throws Exception {
    Class<?>[] classes = new Class<?>[] { EmployeeWithNonStaticFactoryMethod.class };
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream bindings = classLoader.getResourceAsStream(DOMAINCLASSFACTORYMETHOD_ERROR);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, bindings);
    Exception caughtException = null;
    try {
        jaxbContext = JAXBContextFactory.createContext(classes, properties);
        InputStream xml = classLoader.getResourceAsStream(EMPLOYEE_XML);
        EmployeeWithNonStaticFactoryMethod e = (EmployeeWithNonStaticFactoryMethod) jaxbContext.createUnmarshaller().unmarshal(xml);
    } catch (Exception e) {
        caughtException = e;
    }
    assertNotNull(caughtException);
    // "Problem in creating new instance using creation method [x].  The creation method is not accessible."
    try {
        JAXBException jaxbException = (JAXBException) caughtException;
        DescriptorException descriptorException = (DescriptorException) jaxbException.getLinkedException();
        assertEquals("Incorrect error code:", DescriptorException.NULL_POINTER_WHILE_METHOD_INSTANTIATION, descriptorException.getErrorCode());
    } catch (Exception ex) {
        fail("The expected Exception structure was not thrown, instead caught: " + caughtException.getLocalizedMessage());
    }
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) JAXBException(jakarta.xml.bind.JAXBException) JAXBException(jakarta.xml.bind.JAXBException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException)

Example 5 with DescriptorException

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

the class UUIDTester method descriptorWithAccessors.

public static RelationalDescriptor descriptorWithAccessors() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    /* First define the class, table and descriptor properties. */
    descriptor.setJavaClass(UUIDTester.class);
    descriptor.setTableName("UUIDS");
    descriptor.setPrimaryKeyFieldName("NAME");
    /* Next define the attribute mappings. */
    try {
        descriptor.addDirectMapping("testName", "getTestName", "setTestName", "NAME");
        descriptor.addDirectMapping("uuidValue", "getUuidValue", "setUuidValue", "UUIDV");
    } catch (DescriptorException exception) {
    }
    return descriptor;
}
Also used : RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException)

Aggregations

DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)21 IntegrityException (org.eclipse.persistence.exceptions.IntegrityException)7 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)6 InputStream (java.io.InputStream)4 ValidationException (org.eclipse.persistence.exceptions.ValidationException)4 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)4 JAXBException (jakarta.xml.bind.JAXBException)3 HashMap (java.util.HashMap)3 Vector (java.util.Vector)3 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)3 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)3 XMLTransformationMapping (org.eclipse.persistence.oxm.mappings.XMLTransformationMapping)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)2 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)2 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)2 ForeignReferenceMapping (org.eclipse.persistence.mappings.ForeignReferenceMapping)2 XMLContext (org.eclipse.persistence.oxm.XMLContext)2