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;
}
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());
}
}
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());
}
}
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());
}
}
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;
}
Aggregations