protected void mapElementToJaxbProperty()

in components/camel-cxf/camel-cxf-blueprint/src/main/java/org/apache/camel/component/cxf/blueprint/configuration/AbstractBPBeanDefinitionParser.java [354:396]


    protected void mapElementToJaxbProperty(ParserContext ctx,
                                            MutableBeanMetadata bean,
                                            Element data,
                                            String propertyName,
                                            Class<?> c) {
        try {
            Unmarshaller u = null;
            try {
                final StringWriter writer = new StringWriter();
                StaxUtils.writeTo(data, writer);

                MutableBeanMetadata factory = ctx.createMetadata(MutableBeanMetadata.class);
                factory.setClassName(c.getName());
                factory.setFactoryComponent(createPassThrough(ctx, new JAXBBeanFactory(getContext(c), c)));
                factory.setFactoryMethod("createJAXBBean");
                factory.addArgument(createValue(ctx, writer.toString()), String.class.getName(), 0);
                bean.addProperty(propertyName, factory);

            } catch (Exception ex) {
                u = getContext(c).createUnmarshaller();
                u.setEventHandler(null);
                Object obj;
                if (c != null) {
                    obj = u.unmarshal(data, c);
                } else {
                    obj = u.unmarshal(data);
                }
                if (obj instanceof JAXBElement<?>) {
                    JAXBElement<?> el = (JAXBElement<?>)obj;
                    obj = el.getValue();
                }
                if (obj != null) {
                    MutablePassThroughMetadata value = ctx.createMetadata(MutablePassThroughMetadata.class);
                    value.setObject(obj);
                    bean.addProperty(propertyName, value);
                }
            } finally {
                JAXBUtils.closeUnmarshaller(u);
            }
        } catch (JAXBException e) {
            throw new RuntimeException("Could not parse configuration.", e);
        }
    }