Done.

Thanks for the reminding.

Willem

Claus Ibsen wrote:
> Willem
> 
> Can you add SNIPPET tags in:
>    public @interface MyXPath
> 
> And add it to the xpath wiki page, then end users can better read and
> understand how to create their own xpath annotation with their
> namespaces.
> 
> 
> 
> On Tue, May 12, 2009 at 6:58 AM,  <[email protected]> wrote:
>> Author: ningjiang
>> Date: Tue May 12 04:58:13 2009
>> New Revision: 773781
>>
>> URL: http://svn.apache.org/viewvc?rev=773781&view=rev
>> Log:
>> CAMEL-1602 support to get the namespces from a customerized XPath
>>
>> Added:
>>    
>> camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/MyXPath.java
>>    (with props)
>> Modified:
>>    
>> camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java
>>    
>> camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterPojoTest.java
>>    
>> camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/TestBean.java
>>
>> Modified: 
>> camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java
>> URL: 
>> http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java?rev=773781&r1=773780&r2=773781&view=diff
>> ==============================================================================
>> --- 
>> camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java
>>  (original)
>> +++ 
>> camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/XPathAnnotationExpressionFactory.java
>>  Tue May 12 04:58:13 2009
>> @@ -17,6 +17,7 @@
>>  package org.apache.camel.component.bean;
>>
>>  import java.lang.annotation.Annotation;
>> +import java.lang.reflect.Method;
>>
>>  import org.apache.camel.CamelContext;
>>  import org.apache.camel.Expression;
>> @@ -24,6 +25,7 @@
>>  import org.apache.camel.language.LanguageAnnotation;
>>  import org.apache.camel.language.NamespacePrefix;
>>  import org.apache.camel.language.XPath;
>> +import org.apache.camel.util.ObjectHelper;
>>
>>  /**
>>  * Factory for the XPath expression annotations.
>> @@ -36,15 +38,23 @@
>>     public Expression createExpression(CamelContext camelContext, Annotation 
>> annotation, LanguageAnnotation languageAnnotation, Class 
>> expressionReturnType) {
>>         String xpath = getExpressionFromAnnotation(annotation);
>>         XPathBuilder builder = XPathBuilder.xpath(xpath);
>> -        if (annotation instanceof XPath) {
>> -            XPath xpathAnnotation = (XPath) annotation;
>> -            NamespacePrefix[] namespaces = xpathAnnotation.namespaces();
>> -            if (namespaces != null) {
>> -                for (NamespacePrefix namespacePrefix : namespaces) {
>> -                    builder = builder.namespace(namespacePrefix.prefix(), 
>> namespacePrefix.uri());
>> -                }
>> +        NamespacePrefix[] namespaces = 
>> getExpressionNameSpacePrefix(annotation);
>> +        if (namespaces != null) {
>> +            for (NamespacePrefix namespacePrefix : namespaces) {
>> +                builder = builder.namespace(namespacePrefix.prefix(), 
>> namespacePrefix.uri());
>>             }
>> +
>>         }
>>         return builder;
>>     }
>> +
>> +    protected NamespacePrefix[] getExpressionNameSpacePrefix(Annotation 
>> annotation) {
>> +        try {
>> +            Method method = annotation.getClass().getMethod("namespaces");
>> +            Object value = ObjectHelper.invokeMethod(method, annotation);
>> +            return (NamespacePrefix[])value;
>> +        } catch (NoSuchMethodException e) {
>> +            throw new IllegalArgumentException("Cannot determine the 
>> annotation: " + annotation + " as it does not have an namespaces() method");
>> +        }
>> +    }
>>  }
>>
>> Modified: 
>> camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterPojoTest.java
>> URL: 
>> http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterPojoTest.java?rev=773781&r1=773780&r2=773781&view=diff
>> ==============================================================================
>> --- 
>> camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterPojoTest.java
>>  (original)
>> +++ 
>> camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterPojoTest.java
>>  Tue May 12 04:58:13 2009
>> @@ -121,6 +121,7 @@
>>             // to access the message header and body at same time,
>>             // then create the message that we want, splitter will
>>             // take care rest of them.
>> +            // *NOTE* this feature requires Camel version >= 1.6.1
>>             List<Message> answer = new ArrayList<Message>();
>>             String[] parts = header.split(",");
>>             for (String part : parts) {
>>
>> Added: 
>> camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/MyXPath.java
>> URL: 
>> http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/MyXPath.java?rev=773781&view=auto
>> ==============================================================================
>> --- 
>> camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/MyXPath.java
>>  (added)
>> +++ 
>> camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/MyXPath.java
>>  Tue May 12 04:58:13 2009
>> @@ -0,0 +1,37 @@
>> +/**
>> + * Licensed to the Apache Software Foundation (ASF) under one or more
>> + * contributor license agreements.  See the NOTICE file distributed with
>> + * this work for additional information regarding copyright ownership.
>> + * The ASF licenses this file to You under the Apache License, Version 2.0
>> + * (the "License"); you may not use this file except in compliance with
>> + * the License.  You may obtain a copy of the License at
>> + *
>> + *      http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing, software
>> + * distributed under the License is distributed on an "AS IS" BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>> + * See the License for the specific language governing permissions and
>> + * limitations under the License.
>> + */
>> +package org.apache.camel.component.xslt;
>> +
>> +import java.lang.annotation.ElementType;
>> +import java.lang.annotation.Retention;
>> +import java.lang.annotation.RetentionPolicy;
>> +import java.lang.annotation.Target;
>> +
>> +import org.apache.camel.component.bean.XPathAnnotationExpressionFactory;
>> +import org.apache.camel.language.LanguageAnnotation;
>> +import org.apache.camel.language.NamespacePrefix;
>> +
>> +...@retention(RetentionPolicy.RUNTIME)
>> +...@target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
>> +...@languageannotation(language = "xpath", factory = 
>> XPathAnnotationExpressionFactory.class)
>> +public @interface MyXPath {
>> +    String value();
>> +
>> +    NamespacePrefix[] namespaces() default {
>> +    @NamespacePrefix(prefix = "n1", uri = "http://example.org/ns1";),
>> +    @NamespacePrefix(prefix = "n2", uri = "http://example.org/ns2";)};
>> +}
>>
>> Propchange: 
>> camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/MyXPath.java
>> ------------------------------------------------------------------------------
>>    svn:eol-style = native
>>
>> Propchange: 
>> camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/MyXPath.java
>> ------------------------------------------------------------------------------
>>    svn:keywords = Rev Date
>>
>> Modified: 
>> camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/TestBean.java
>> URL: 
>> http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/TestBean.java?rev=773781&r1=773780&r2=773781&view=diff
>> ==============================================================================
>> --- 
>> camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/TestBean.java
>>  (original)
>> +++ 
>> camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/TestBean.java
>>  Tue May 12 04:58:13 2009
>> @@ -16,7 +16,6 @@
>>  */
>>  package org.apache.camel.component.xslt;
>>
>> -import org.apache.camel.language.XPath;
>>
>>  /**
>>  * @version $Revision$
>> @@ -24,7 +23,7 @@
>>  public class TestBean {
>>     private String subject;
>>
>> -    public void onMethod(@XPath("/*/@subject")String subject) {
>> +    public void onMethod(@MyXPath("/*/@subject")String subject) {
>>         this.subject = subject;
>>     }
>>
>>
>>
>>
> 
> 
> 

Reply via email to