camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Proctor (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CAMEL-2921) DataFormat's should allow url query like parameters
Date Fri, 09 Jul 2010 00:12:51 GMT

    [ https://issues.apache.org/activemq/browse/CAMEL-2921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=60524#action_60524
] 

Mark Proctor commented on CAMEL-2921:
-------------------------------------

This won't work for the moment, seems I need to get a better understanding of Dataformat and
DataFormatDefinition resolving.
If seems that DataFormatDefintions are only created for customed dataformats, such as in the
spring <dataformats> xml or by the user.

if you just do:
marshall( "xstream" )

That will not create a DataFormatDefinition, instead it creates DataFormat directly from the
factory finder; based on the discovery of :
META-INF/services/org/apache/camel/dataforamt/xstream

Imho it would be cleaner for it to always return a DataFormatDefinition,  whichh would better
support runtime augmentation by policy.

So when you do marshall( "xstream" ). Instead of creating the DataFormat directly, via the
factory finder, it should instead create the DataFormatDefintion for xtream and then store
that in the context's map of data format definitions; so that future resolving comes directly
from there (don't forget to clone the dataformatdefinition before using). This should also
add an over all level of consistency.

At the moment the factoryfinder points to the DataFormat class, instead that should be updated
to point to the DataFormatDefinition class; this will need to be updated for all data format
implementations.



> DataFormat's should allow url query like parameters
> ---------------------------------------------------
>
>                 Key: CAMEL-2921
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2921
>             Project: Apache Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Mark Proctor
>
> It would be nice if we could customise DataFormatDefinitions inline:
> marshal( "jaxb?contextPath=org.domain.package" )
> Here is an outline of some code I think that would achieve this, however to be safe (imho)
the resolver should only ever returned "cloned" copies of any registered DataFormatDefinition;
to save the originally source from being altered.
> I found this library (BSD license) that provides for reflection based cloning:
> http://commonj.googlecode.com/svn/trunk/src/org/jcommon/clone/
> Based on a blog  I read here:
> http://www.matthicks.com/2008/05/fastest-deep-cloning.html
> DataFormatDefinition
> {code}
>     public static DataFormat getDataFormat(RouteContext routeContext, DataFormatDefinition
type, String ref) {
>         if (type == null) {
>             ObjectHelper.notNull(ref, "ref or type");
>             
>             // try to let resolver see if it can resolve it, its not always possible
>             int pos = ref.indexOf( '?' );
>             if ( pos < 0 ) {                                
>                 type = routeContext.getCamelContext().resolveDataFormatDefinition( ref
);
>             } else {
>                 type = routeContext.getCamelContext().resolveDataFormatDefinition( ref.substring(0,
pos -1 ) );
>             }        
>             if (type != null &&  pos >= 0 ) {
>                 try {
>                     Map<String, Object> parameters = URISupport.parseQuery( ref.substring(
pos ) ); 
>                     try {
>                         IntrospectionSupport.setProperties(routeContext.getCamelContext().getTypeConverter(),
type, parameters);
>                     } catch (Exception e) {
>                         throw new RuntimeException( "Unable to set DataFormatDefinition
properties '" + ref + "'", e);
>                     }
>                 } catch (URISyntaxException e) {
>                     throw new RuntimeException( "Unable to parse parameters " + ref,
e);
>                 }
>                 
>                 return type.getDataFormat(routeContext);
>             }
>             DataFormat dataFormat = routeContext.getCamelContext().resolveDataFormat(ref);
>             if (dataFormat == null) {
>                 throw new IllegalArgumentException("Cannot find data format in registry
with ref: " + ref);
>             }
>             return dataFormat;
>         } else {
>             return type.getDataFormat(routeContext);
>         }
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message