Search in sources :

Example 1 with TypeInfo

use of org.eclipse.persistence.jaxb.compiler.TypeInfo in project eclipselink by eclipse-ee4j.

the class PropertyTypeTestCases method testPropertyTypes.

public void testPropertyTypes() throws Exception {
    JaxbClassLoader classLoader = new JaxbClassLoader(Thread.currentThread().getContextClassLoader());
    Generator generator = new Generator(new JavaModelInputImpl(new Class<?>[] { TestObject.class }, new JavaModelImpl(this.classLoader)));
    CoreProject proj = generator.generateProject();
    TypeInfo info = generator.getAnnotationsProcessor().getTypeInfos().get("org.eclipse.persistence.testing.jaxb.annotations.TestObject");
    Property booleanProp = info.getProperties().get("booleanTest");
    JavaClass type = booleanProp.getType();
    assertEquals("java.lang.Boolean", type.getRawName());
    Property booleanListProp = info.getProperties().get("booleanListTest");
    type = booleanListProp.getType();
    assertEquals("java.util.List", type.getRawName());
    Property byteArrayProp = info.getProperties().get("byteArrayTest");
    type = byteArrayProp.getType();
    assertEquals("java.lang.String", type.getRawName());
    Property byteArrayListProp = info.getProperties().get("byteArrayListTest");
    type = byteArrayListProp.getType();
    assertEquals("java.util.List", type.getRawName());
    assertEquals("java.lang.String", byteArrayListProp.getGenericType().getRawName());
}
Also used : JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) CoreProject(org.eclipse.persistence.core.sessions.CoreProject) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) TypeInfo(org.eclipse.persistence.jaxb.compiler.TypeInfo) Property(org.eclipse.persistence.jaxb.compiler.Property) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) Generator(org.eclipse.persistence.jaxb.compiler.Generator)

Example 2 with TypeInfo

use of org.eclipse.persistence.jaxb.compiler.TypeInfo 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()));
    }
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) HashMap(java.util.HashMap) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) ChildSchemaGenerator(org.eclipse.persistence.testing.moxy.unit.jaxb.compiler.builder.ChildSchemaGenerator) StringWriter(java.io.StringWriter) TransformerPropertyBuilder(org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder) List(java.util.List) Property(org.eclipse.persistence.jaxb.compiler.Property) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) XMLContext(org.eclipse.persistence.oxm.XMLContext) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) TypeInfo(org.eclipse.persistence.jaxb.compiler.TypeInfo) JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) Generator(org.eclipse.persistence.jaxb.compiler.Generator) ChildSchemaGenerator(org.eclipse.persistence.testing.moxy.unit.jaxb.compiler.builder.ChildSchemaGenerator) Test(org.junit.Test)

Example 3 with TypeInfo

use of org.eclipse.persistence.jaxb.compiler.TypeInfo in project eclipselink by eclipse-ee4j.

the class SchemaGeneratorTestCase method getTransformerPropertyBuilder.

@Test
public void getTransformerPropertyBuilder() {
    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);
    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);
    assertNotNull(transformerPropertyBuilder);
}
Also used : JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) ChildSchemaGenerator(org.eclipse.persistence.testing.moxy.unit.jaxb.compiler.builder.ChildSchemaGenerator) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) TransformerPropertyBuilder(org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder) TypeInfo(org.eclipse.persistence.jaxb.compiler.TypeInfo) Property(org.eclipse.persistence.jaxb.compiler.Property) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) Generator(org.eclipse.persistence.jaxb.compiler.Generator) ChildSchemaGenerator(org.eclipse.persistence.testing.moxy.unit.jaxb.compiler.builder.ChildSchemaGenerator) Test(org.junit.Test)

Example 4 with TypeInfo

use of org.eclipse.persistence.jaxb.compiler.TypeInfo in project eclipselink by eclipse-ee4j.

the class TransformerPropertyBuilderTestCase method testTransformerPropertyBuilder.

@Test
public void testTransformerPropertyBuilder() {
    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);
    // Indirect call of org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder.getPropertyName(...) and org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder.buildPropertyFromTransformer(...)
    // Indirect call of org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder.getTransformerJavaClass(...) with booth options writeTransformer.isSetTransformerClass() true,false
    List<Property> props = transformerPropertyBuilder.buildProperties();
    assertEquals(2, props.size());
    // Verification of result of org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder.getPropertyName(...)
    // Verify property names
    assertEquals("start-time", props.get(0).getPropertyName());
    assertEquals("end-time", props.get(1).getPropertyName());
    // Verification of result of org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder.getReturnTypeFromTransformer(...)
    // Verify property types
    assertEquals(String.class.getName(), props.get(0).getType().getName());
    assertEquals(String.class.getName(), props.get(1).getType().getName());
    assertEquals(NormalHoursAttributeTransformer.class.getName(), normalHoursProperty.getXmlTransformation().getXmlReadTransformer().getTransformerClass());
    assertEquals(StartTimeTransformer.class.getName(), normalHoursProperty.getXmlTransformation().getXmlWriteTransformer().get(0).getTransformerClass());
    assertEquals(String.class.getName(), normalHoursProperty.getGenericType().getName());
    // Indirect call of org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder.getTransformerJavaClass(...) with invalid TransformerClass name
    try {
        normalHoursProperty.getXmlTransformation().getXmlWriteTransformer().get(0).setTransformerClass("xxx.xxx.WrongClassName");
        transformerPropertyBuilder.buildProperties();
        fail("Expected JAXBException.");
    } catch (JAXBException expected) {
        assertEquals(50054, expected.getErrorCode());
    }
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) NormalHoursAttributeTransformer(org.eclipse.persistence.testing.jaxb.externalizedmetadata.mappings.xmltransformation.NormalHoursAttributeTransformer) HashMap(java.util.HashMap) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(org.eclipse.persistence.exceptions.JAXBException) StartTimeTransformer(org.eclipse.persistence.testing.jaxb.externalizedmetadata.mappings.xmltransformation.StartTimeTransformer) TypeInfo(org.eclipse.persistence.jaxb.compiler.TypeInfo) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) Helper(org.eclipse.persistence.jaxb.javamodel.Helper) TransformerPropertyBuilder(org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder) Property(org.eclipse.persistence.jaxb.compiler.Property) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) Generator(org.eclipse.persistence.jaxb.compiler.Generator) Test(org.junit.Test)

Aggregations

JaxbClassLoader (org.eclipse.persistence.internal.jaxb.JaxbClassLoader)4 Generator (org.eclipse.persistence.jaxb.compiler.Generator)4 Property (org.eclipse.persistence.jaxb.compiler.Property)4 TypeInfo (org.eclipse.persistence.jaxb.compiler.TypeInfo)4 JavaModelImpl (org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl)4 JavaModelInputImpl (org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl)4 TransformerPropertyBuilder (org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Source (javax.xml.transform.Source)2 StreamSource (javax.xml.transform.stream.StreamSource)2 XmlBindings (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings)2 ChildSchemaGenerator (org.eclipse.persistence.testing.moxy.unit.jaxb.compiler.builder.ChildSchemaGenerator)2 StringWriter (java.io.StringWriter)1 List (java.util.List)1 CoreProject (org.eclipse.persistence.core.sessions.CoreProject)1 JAXBException (org.eclipse.persistence.exceptions.JAXBException)1 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)1 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)1