Search in sources :

Example 21 with AegisContext

use of org.apache.cxf.aegis.AegisContext in project cxf by apache.

the class NoNamespaceAegisElementProvider method getAegisContext.

@Override
protected AegisContext getAegisContext(Class<?> plainClass, Type genericType) {
    AegisContext context = new AegisContext();
    context.setWriteXsiTypes(writeXsiType);
    context.setReadXsiTypes(readXsiType);
    TypeCreationOptions tco = new TypeCreationOptions();
    tco.setQualifyElements(false);
    Set<java.lang.reflect.Type> rootClasses = new HashSet<java.lang.reflect.Type>();
    rootClasses.add(genericType);
    context.setTypeCreationOptions(tco);
    context.setRootClasses(rootClasses);
    TypeMapping baseMapping = DefaultTypeMapping.createSoap11TypeMapping(true, false, false);
    DefaultTypeMapping mapping = new DefaultTypeMapping(Constants.URI_2001_SCHEMA_XSD, baseMapping);
    TypeCreator stockTypeCreator = createTypeCreator(tco);
    mapping.setTypeCreator(stockTypeCreator);
    context.setTypeMapping(mapping);
    context.initialize();
    return context;
}
Also used : Type(java.lang.reflect.Type) DefaultTypeMapping(org.apache.cxf.aegis.type.DefaultTypeMapping) AegisContext(org.apache.cxf.aegis.AegisContext) DefaultTypeMapping(org.apache.cxf.aegis.type.DefaultTypeMapping) TypeMapping(org.apache.cxf.aegis.type.TypeMapping) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) XMLTypeCreator(org.apache.cxf.aegis.type.XMLTypeCreator) TypeCreator(org.apache.cxf.aegis.type.TypeCreator) AbstractTypeCreator(org.apache.cxf.aegis.type.AbstractTypeCreator) Java5TypeCreator(org.apache.cxf.aegis.type.java5.Java5TypeCreator) HashSet(java.util.HashSet)

Example 22 with AegisContext

use of org.apache.cxf.aegis.AegisContext in project cxf by apache.

the class ReadZoo method go.

private void go() throws Exception {
    AegisContext context;
    context = new AegisContext();
    Set<Type> rootClasses = new HashSet<>();
    rootClasses.add(Zoo.class);
    context.setRootClasses(rootClasses);
    context.initialize();
    AegisReader<XMLStreamReader> reader = context.createXMLStreamReader();
    FileInputStream input = new FileInputStream(inputPathname);
    XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(input);
    Zoo zoo = (Zoo) reader.read(xmlReader);
    System.out.println("Name " + zoo.getName());
    System.out.println("Founder " + zoo.getFounder());
    for (Map.Entry<String, Animal> e : zoo.getAnimals().entrySet()) {
        System.out.println(e.getKey() + " -> " + e.getValue().getName());
    }
}
Also used : Type(java.lang.reflect.Type) XMLStreamReader(javax.xml.stream.XMLStreamReader) Animal(org.apache.cxf.demo.aegis.types.Animal) AegisContext(org.apache.cxf.aegis.AegisContext) Zoo(org.apache.cxf.demo.aegis.types.Zoo) Map(java.util.Map) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Example 23 with AegisContext

use of org.apache.cxf.aegis.AegisContext in project cxf by apache.

the class AegisDatabinding method initialize.

/**
 * {@inheritDoc} Set up the data binding for a service.
 */
public void initialize(Service s) {
    // We want to support some compatibility configuration properties.
    if (aegisContext == null) {
        aegisContext = new AegisContext();
        Object val = s.get("mtom-enabled");
        if ("true".equals(val) || Boolean.TRUE.equals(val) || mtomEnabled) {
            setMtomEnabled(true);
            aegisContext.setMtomEnabled(true);
        }
        if (mtomUseXmime) {
            aegisContext.setMtomUseXmime(true);
        }
        Map<Class<?>, String> implMap = new HashMap<>();
        // now for a really annoying case, the .implementation objects.
        for (String key : s.keySet()) {
            if (key.endsWith(".implementation")) {
                String className = key.substring(0, key.length() - ".implementation".length());
                Class<?> clazz = null;
                try {
                    clazz = ClassLoaderUtils.loadClass(className, getClass());
                } catch (ClassNotFoundException e) {
                    Message message = new Message("MAPPED_CLASS_NOT_FOUND", LOG, className, key);
                    LOG.warning(message.toString());
                    continue;
                }
                String implClassName = (String) s.get(key);
                implMap.put(clazz, implClassName);
            }
        }
        if (overrideTypes != null) {
            aegisContext.setRootClassNames(overrideTypes);
        }
        if (configuration != null) {
            aegisContext.setTypeCreationOptions(configuration);
        }
        if (!implMap.isEmpty()) {
            aegisContext.setBeanImplementationMap(implMap);
        }
    }
    aegisContext.setMappingNamespaceURI(s.getServiceInfos().get(0).getInterface().getName().getNamespaceURI());
    aegisContext.initialize();
    this.service = s;
    s.getInInterceptors().add(new StaxSchemaValidationInInterceptor());
    Set<AegisType> deps = new HashSet<>();
    for (ServiceInfo info : s.getServiceInfos()) {
        for (OperationInfo opInfo : info.getInterface().getOperations()) {
            if (opInfo.isUnwrappedCapable()) {
                initializeOperation(s, aegisContext.getTypeMapping(), opInfo.getUnwrappedOperation(), deps);
            } else {
                initializeOperation(s, aegisContext.getTypeMapping(), opInfo, deps);
            }
        }
    }
    Collection<AegisType> additional = aegisContext.getRootTypes();
    if (additional != null) {
        for (AegisType t : additional) {
            if (!deps.contains(t)) {
                deps.add(t);
            }
            addDependencies(deps, t);
        }
    }
    createSchemas(s, deps);
    for (ServiceInfo info : s.getServiceInfos()) {
        for (OperationInfo opInfo : info.getInterface().getOperations()) {
            if (opInfo.isUnwrappedCapable()) {
                initializeOperationTypes(info, opInfo.getUnwrappedOperation());
            } else {
                initializeOperationTypes(info, opInfo);
            }
        }
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) Message(org.apache.cxf.common.i18n.Message) HashMap(java.util.HashMap) AegisType(org.apache.cxf.aegis.type.AegisType) AegisContext(org.apache.cxf.aegis.AegisContext) StaxSchemaValidationInInterceptor(org.apache.cxf.staxutils.validation.StaxSchemaValidationInInterceptor) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) HashSet(java.util.HashSet)

Example 24 with AegisContext

use of org.apache.cxf.aegis.AegisContext in project cxf by apache.

the class XMLStreamReaderMappingTest method getContext.

protected Context getContext() {
    AegisContext globalContext = new AegisContext();
    globalContext.initialize();
    globalContext.setTypeMapping(mapping);
    return new Context(globalContext);
}
Also used : Context(org.apache.cxf.aegis.Context) AegisContext(org.apache.cxf.aegis.AegisContext) AegisContext(org.apache.cxf.aegis.AegisContext)

Example 25 with AegisContext

use of org.apache.cxf.aegis.AegisContext in project cxf by apache.

the class TestDateMapping method testWriteSqlDateAsDate.

@Test
public void testWriteSqlDateAsDate() throws Exception {
    context = new AegisContext();
    Set<java.lang.reflect.Type> rootClasses = new HashSet<java.lang.reflect.Type>();
    rootClasses.add(BeanWithDate.class);
    context.setRootClasses(rootClasses);
    context.initialize();
    BeanWithDate bean = new BeanWithDate();
    java.sql.Date date = new java.sql.Date(0);
    bean.setFig(date);
    AegisType sbType = context.getTypeMapping().getType(bean.getClass());
    AegisWriter<XMLStreamWriter> writer = context.createXMLStreamWriter();
    StringWriter stringWriter = new StringWriter();
    XMLStreamWriter xmlWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter);
    writer.write(bean, new QName("urn:test", "beanWithDate"), false, xmlWriter, sbType);
    xmlWriter.close();
// an absence of exception is success here.
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) AegisContext(org.apache.cxf.aegis.AegisContext) AegisType(org.apache.cxf.aegis.type.AegisType) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

AegisContext (org.apache.cxf.aegis.AegisContext)40 Test (org.junit.Test)20 QName (javax.xml.namespace.QName)15 AegisType (org.apache.cxf.aegis.type.AegisType)15 HashSet (java.util.HashSet)13 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)8 TypeMapping (org.apache.cxf.aegis.type.TypeMapping)8 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)6 Context (org.apache.cxf.aegis.Context)6 TypeCreationOptions (org.apache.cxf.aegis.type.TypeCreationOptions)6 XmlSchema (org.apache.ws.commons.schema.XmlSchema)5 Before (org.junit.Before)5 StringWriter (java.io.StringWriter)4 AegisDatabinding (org.apache.cxf.aegis.databinding.AegisDatabinding)4 XmlMappedAttributeBean (org.apache.cxf.aegis.services.XmlMappedAttributeBean)4 Type (java.lang.reflect.Type)3 ArrayList (java.util.ArrayList)3 SimpleBean (org.apache.cxf.aegis.services.SimpleBean)3 DefaultTypeMapping (org.apache.cxf.aegis.type.DefaultTypeMapping)3