use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class SessionEventTestCases method setupContext.
protected JAXBContext setupContext(Class<?>[] classesToBeBound, SessionEventListener sel) throws Exception {
jakarta.xml.bind.JAXBContext jaxbContext = null;
XMLContext xmlContext = null;
JaxbClassLoader loader = new JaxbClassLoader(Thread.currentThread().getContextClassLoader());
try {
Generator generator = new Generator(new JavaModelInputImpl(classesToBeBound, new JavaModelImpl(loader)));
CoreProject proj = generator.generateProject();
ConversionManager conversionManager = null;
conversionManager = new ConversionManager();
conversionManager.setLoader(loader);
proj.convertClassNamesToClasses(conversionManager.getLoader());
for (Iterator<ClassDescriptor> descriptorIt = proj.getOrderedDescriptors().iterator(); descriptorIt.hasNext(); ) {
ClassDescriptor descriptor = descriptorIt.next();
if (descriptor.getJavaClass() == null) {
descriptor.setJavaClass(conversionManager.convertClassNameToClass(descriptor.getJavaClassName()));
}
}
xmlContext = new XMLContext((Project) proj, loader, sel);
jaxbContext = new org.eclipse.persistence.jaxb.JAXBContext(xmlContext, generator, classesToBeBound);
} catch (Exception ex) {
throw ex;
}
return jaxbContext;
}
use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class JAXBContextTransformationMappingTestCases method testInvalidTransformerClass.
/**
* Test exception handling: in this case an invalid transformer class
* has been set. An exception should be thrown.
*
* Negative test.
*/
public void testInvalidTransformerClass() {
InputStream inputStream = ClassLoader.getSystemResourceAsStream(METADATA_FILE_BAD_CLASS);
HashMap<String, Source> metadataSourceMap = new HashMap<>();
metadataSourceMap.put("org.eclipse.persistence.testing.jaxb.externalizedmetadata.mappings.xmltransformation", new StreamSource(inputStream));
Map<String, Object> properties = new HashMap<>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataSourceMap);
int exceptionCount = 0;
// test exception from MappingsGenerator
try {
JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class<?>[] { Employee.class }, properties, Thread.currentThread().getContextClassLoader());
} catch (JAXBException e) {
exceptionCount++;
}
assertTrue("The expected exception was never thrown.", exceptionCount > 0);
exceptionCount--;
// test exception from SchemaGenerator
try {
Map<String, XmlBindings> bindings = JAXBContextFactory.getXmlBindingsFromProperties(properties, Thread.currentThread().getContextClassLoader());
JavaModelInputImpl jModelInput = new JavaModelInputImpl(new Class<?>[] { Employee.class }, new JavaModelImpl(new JaxbClassLoader(Thread.currentThread().getContextClassLoader(), new Class<?>[] { Employee.class })));
Generator generator = new Generator(jModelInput, bindings, Thread.currentThread().getContextClassLoader(), "", false);
generator.generateSchema();
} catch (Exception e) {
exceptionCount++;
}
assertTrue("The expected exception was never thrown.", exceptionCount > 0);
}
use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class SchemaGenEmployeeTestCases method xtestAbstractSuperclassVaildDoc.
/**
* In this test the xsi:type of the root element set to subclass, which is valid.
*/
public void xtestAbstractSuperclassVaildDoc() throws Exception {
boolean exception = false;
String msg = null;
String src = "org/eclipse/persistence/testing/jaxb/schemagen/employee/valid_inheritance.xml";
File newXsd = new File(tmpdir, "schema1.xsd");
if (newXsd.exists() && newXsd.isFile() && newXsd.delete()) {
System.err.println("removed existing: " + newXsd.getAbsolutePath());
}
try {
Class<?>[] jClasses = new Class<?>[] { MyAbstractTestType.class, MyTestSubType.class };
Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
gen.generateSchemaFiles(tmpdir, null);
SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema theSchema = sFact.newSchema(newXsd);
Validator validator = theSchema.newValidator();
StreamSource ss = new StreamSource(new File(src));
validator.validate(ss);
} catch (Exception ex) {
exception = true;
msg = ex.toString();
}
assertFalse("Schema validation failed unexpectedly: " + msg, exception);
}
use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class SchemaGeneratorTestCase method javaxXmlRpcStringHolderTest.
@Test
public void javaxXmlRpcStringHolderTest() {
// Prepare Helper
JavaModelInputImpl jModelInput = new JavaModelInputImpl(DOMAIN_CLASSES, new JavaModelImpl(new JaxbClassLoader(Thread.currentThread().getContextClassLoader(), DOMAIN_CLASSES)));
Helper helper = new Helper(jModelInput.getJavaModel());
assertFalse(helper.isBuiltInJavaType(new JavaClass() {
@Override
public String getRawName() {
return "javax.xml.rpc.StringHolder";
}
@Override
public JavaClassInstanceOf instanceOf() {
return null;
}
@Override
public boolean isSynthetic() {
return false;
}
@Override
public Collection<JavaClass> getActualTypeArguments() {
return null;
}
@Override
public JavaClass getComponentType() {
return null;
}
@Override
public String getQualifiedName() {
return null;
}
@Override
public boolean hasActualTypeArguments() {
return false;
}
@Override
public Collection<JavaClass> getDeclaredClasses() {
return null;
}
@Override
public JavaField getDeclaredField(String arg0) {
return null;
}
@Override
public Collection<JavaField> getDeclaredFields() {
return null;
}
@Override
public JavaMethod getDeclaredMethod(String arg0, JavaClass[] arg1) {
return null;
}
@Override
public Collection<JavaMethod> getDeclaredMethods() {
return null;
}
@Override
public JavaMethod getMethod(String arg0, JavaClass[] arg1) {
return null;
}
@Override
public Collection<JavaMethod> getMethods() {
return null;
}
@Override
public JavaConstructor getConstructor(JavaClass[] parameterTypes) {
return null;
}
@Override
public Collection<JavaConstructor> getConstructors() {
return null;
}
@Override
public JavaConstructor getDeclaredConstructor(JavaClass[] parameterTypes) {
return null;
}
@Override
public Collection<JavaConstructor> getDeclaredConstructors() {
return null;
}
@Override
public int getModifiers() {
return 0;
}
@Override
public String getName() {
return null;
}
@Override
public JavaPackage getPackage() {
return null;
}
@Override
public String getPackageName() {
return null;
}
@Override
public JavaClass getSuperclass() {
return null;
}
@Override
public Type[] getGenericInterfaces() {
return null;
}
@Override
public Type getGenericSuperclass() {
return null;
}
@Override
public boolean isAbstract() {
return false;
}
@Override
public boolean isAnnotation() {
return false;
}
@Override
public boolean isArray() {
return false;
}
@Override
public boolean isAssignableFrom(JavaClass arg0) {
return false;
}
@Override
public boolean isEnum() {
return false;
}
@Override
public boolean isFinal() {
return false;
}
@Override
public boolean isInterface() {
return false;
}
@Override
public boolean isMemberClass() {
return false;
}
@Override
public boolean isPrimitive() {
return false;
}
@Override
public boolean isPrivate() {
return false;
}
@Override
public boolean isProtected() {
return false;
}
@Override
public boolean isPublic() {
return false;
}
@Override
public boolean isStatic() {
return false;
}
@Override
public JavaAnnotation getAnnotation(JavaClass arg0) {
return null;
}
@Override
public Collection getAnnotations() {
return null;
}
@Override
public JavaAnnotation getDeclaredAnnotation(JavaClass arg0) {
return null;
}
@Override
public Collection getDeclaredAnnotations() {
return null;
}
}));
}
use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl in project eclipselink by eclipse-ee4j.
the class SchemaGeneratorTestCase method addTransformerToSchema.
@Test
public void addTransformerToSchema() {
InputStream inputStream = ClassLoader.getSystemResourceAsStream(BINDINGS_DOC);
HashMap<String, Source> metadataSourceMap = new HashMap<>();
metadataSourceMap.put("org.eclipse.persistence.testing.jaxb.externalizedmetadata.mappings.xmltransformation", new StreamSource(inputStream));
Map<String, Object> properties = new HashMap<>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataSourceMap);
Map<String, XmlBindings> bindings = JAXBContextFactory.getXmlBindingsFromProperties(properties, Thread.currentThread().getContextClassLoader());
JavaModelInputImpl jModelInput = new JavaModelInputImpl(DOMAIN_CLASSES, new JavaModelImpl(new JaxbClassLoader(Thread.currentThread().getContextClassLoader(), DOMAIN_CLASSES)));
Helper helper = new Helper(jModelInput.getJavaModel());
Generator generator = new Generator(jModelInput, bindings, Thread.currentThread().getContextClassLoader(), "", false);
TypeInfo typeInfo = generator.getAnnotationsProcessor().getTypeInfos().get(EMPLOYEE_CLASS_NAME);
Property normalHoursProperty = typeInfo.getProperties().get(XML_TRANSFORMATION_PROPERTY_NAME);
ChildSchemaGenerator childSchemaGenerator = new ChildSchemaGenerator(helper);
TransformerPropertyBuilder transformerPropertyBuilder = childSchemaGenerator.getTransformerPropertyBuilder(normalHoursProperty, typeInfo);
java.util.List<Property> props = transformerPropertyBuilder.buildProperties();
// Indirect call of org.eclipse.persistence.jaxb.compiler.SchemaGenerator.addTransformerToSchema(.....) method.
List<Schema> schemas = (List) generator.generateSchema();
XMLContext context = new XMLContext(new SchemaModelProject());
XMLMarshaller marshaller = context.createMarshaller();
final StringWriter stringWriter = new StringWriter();
marshaller.marshal(schemas.get(0), stringWriter);
String outputSchema = stringWriter.toString();
// Verify that XML-Transformation property is added to XML schema
for (Property property : props) {
assertTrue(outputSchema.contains(property.getPropertyName()));
}
}
Aggregations