You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ch...@apache.org on 2007/08/07 20:36:08 UTC
svn commit: r563607 [3/12] - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/ main/java/org/apache/camel/builder/
main/java/org/apache/camel/builder/xml/
main/java/org/apache/camel/component/bean/
main/java/org/apache/camel/componen...
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultNamespaceContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultNamespaceContext.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultNamespaceContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DefaultNamespaceContext.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,19 +16,20 @@
*/
package org.apache.camel.builder.xml;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.xpath.XPathFactory;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
/**
* An implementation of {@link NamespaceContext} which uses a simple Map where
* the keys are the prefixes and the values are the URIs
@@ -108,7 +108,8 @@
setNamespacesFromDom((Element) parentNode);
}
NamedNodeMap attributes = element.getAttributes();
- for (int i = 0, size = attributes.getLength(); i < size; i++) {
+ int size = attributes.getLength();
+ for (int i = 0; i < size; i++) {
Attr node = (Attr) attributes.item(i);
String name = node.getName();
if (name.startsWith("xmlns:")) {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DomResultHandler.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DomResultHandler.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DomResultHandler.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/DomResultHandler.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,10 +16,10 @@
*/
package org.apache.camel.builder.xml;
-import org.apache.camel.Message;
-
import javax.xml.transform.Result;
import javax.xml.transform.dom.DOMResult;
+
+import org.apache.camel.Message;
/**
* Uses DOM to handle results of the transformation
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/InvalidXPathExpression.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/InvalidXPathExpression.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/InvalidXPathExpression.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/InvalidXPathExpression.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,9 +16,9 @@
*/
package org.apache.camel.builder.xml;
-import org.apache.camel.RuntimeExpressionException;
-
import javax.xml.xpath.XPathException;
+
+import org.apache.camel.RuntimeExpressionException;
/**
* An exception thrown if am XPath expression could not be parsed or evaluated
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/MessageVariableResolver.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/MessageVariableResolver.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/MessageVariableResolver.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/MessageVariableResolver.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,26 +16,33 @@
*/
package org.apache.camel.builder.xml;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathVariableResolver;
+
import org.apache.camel.Exchange;
import org.apache.camel.Message;
-import static org.apache.camel.builder.xml.Namespaces.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import javax.xml.namespace.QName;
-import javax.xml.xpath.XPathVariableResolver;
-import java.util.HashMap;
-import java.util.Map;
+import static org.apache.camel.builder.xml.Namespaces.ENVIRONMENT_VARIABLES;
+import static org.apache.camel.builder.xml.Namespaces.EXCHANGE_PROPERTY;
+import static org.apache.camel.builder.xml.Namespaces.IN_NAMESPACE;
+import static org.apache.camel.builder.xml.Namespaces.OUT_NAMESPACE;
+import static org.apache.camel.builder.xml.Namespaces.SYSTEM_PROPERTIES_NAMESPACE;
/**
- * A variable resolver for XPath expressions which support properties on the messge, exchange as well
- * as making system properties and environment properties available.
- *
+ * A variable resolver for XPath expressions which support properties on the
+ * messge, exchange as well as making system properties and environment
+ * properties available.
+ *
* @version $Revision: 521692 $
*/
public class MessageVariableResolver implements XPathVariableResolver {
- private static final transient Log log = LogFactory.getLog(MessageVariableResolver.class);
+ private static final transient Log LOG = LogFactory.getLog(MessageVariableResolver.class);
private Exchange exchange;
private Map<String, Object> variables = new HashMap<String, Object>();
@@ -66,28 +72,24 @@
answer = exchange.getProperty(localPart);
}
}
- }
- else if (uri.equals(SYSTEM_PROPERTIES_NAMESPACE)) {
+ } else if (uri.equals(SYSTEM_PROPERTIES_NAMESPACE)) {
try {
answer = System.getProperty(localPart);
+ } catch (Exception e) {
+ LOG
+ .debug("Security exception evaluating system property: " + localPart + ". Reason: " + e,
+ e);
}
- catch (Exception e) {
- log.debug("Security exception evaluating system property: " + localPart + ". Reason: " + e, e);
- }
- }
- else if (uri.equals(ENVIRONMENT_VARIABLES)) {
+ } else if (uri.equals(ENVIRONMENT_VARIABLES)) {
answer = System.getenv().get(localPart);
- }
- else if (uri.equals(EXCHANGE_PROPERTY)) {
+ } else if (uri.equals(EXCHANGE_PROPERTY)) {
answer = exchange.getProperty(localPart);
- }
- else if (uri.equals(IN_NAMESPACE)) {
+ } else if (uri.equals(IN_NAMESPACE)) {
answer = in.getHeader(localPart);
if (answer == null && localPart.equals("body")) {
answer = in.getBody();
}
- }
- else if (uri.equals(OUT_NAMESPACE)) {
+ } else if (uri.equals(OUT_NAMESPACE)) {
Message out = exchange.getOut();
answer = out.getHeader(localPart);
if (answer == null && localPart.equals("body")) {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/NamespaceBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/NamespaceBuilder.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/NamespaceBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/NamespaceBuilder.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/Namespaces.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/Namespaces.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/Namespaces.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/Namespaces.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -29,9 +29,16 @@
public static final String SYSTEM_PROPERTIES_NAMESPACE = "http://camel.apache.org/xml/variables/system-properties";
public static final String ENVIRONMENT_VARIABLES = "http://camel.apache.org/xml/variables/environment-variables";
public static final String EXCHANGE_PROPERTY = "http://camel.apache.org/xml/variables/exchange-property";
+
+ /**
+ * Utility classes should not have a public constructor.
+ */
+ private Namespaces() {
+ }
/**
- * Returns true if the given namespaceURI is empty or if it matches the given expected namespace
+ * Returns true if the given namespaceURI is empty or if it matches the
+ * given expected namespace
*/
public static boolean isMatchingNamespaceOrEmptyNamespace(String namespaceURI, String expectedNamespace) {
return ObjectHelper.isNullOrBlank(namespaceURI) || namespaceURI.equals(expectedNamespace);
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/ResultHandler.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/ResultHandler.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/ResultHandler.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/ResultHandler.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,9 +16,9 @@
*/
package org.apache.camel.builder.xml;
-import org.apache.camel.Message;
-
import javax.xml.transform.Result;
+
+import org.apache.camel.Message;
/**
* A strategy for handling XSLT results
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/StreamResultHandler.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/StreamResultHandler.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/StreamResultHandler.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/StreamResultHandler.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,11 +16,12 @@
*/
package org.apache.camel.builder.xml;
-import org.apache.camel.Message;
+import java.io.ByteArrayOutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
-import java.io.ByteArrayOutputStream;
+
+import org.apache.camel.Message;
/**
* Processes the XSLT result as a byte[]
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/StringResultHandler.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/StringResultHandler.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/StringResultHandler.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/StringResultHandler.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,11 +16,12 @@
*/
package org.apache.camel.builder.xml;
-import org.apache.camel.Message;
+import java.io.StringWriter;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
-import java.io.StringWriter;
+
+import org.apache.camel.Message;
/**
* Processes the XSLT result as a String
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,16 +16,8 @@
*/
package org.apache.camel.builder.xml;
-import org.apache.camel.Exchange;
-import org.apache.camel.Expression;
-import org.apache.camel.Message;
-import org.apache.camel.Predicate;
-import org.apache.camel.RuntimeExpressionException;
-import static org.apache.camel.builder.xml.Namespaces.*;
-import static org.apache.camel.converter.ObjectConverter.toBoolean;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.InputSource;
+import java.io.StringReader;
+import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.xpath.XPath;
@@ -38,20 +29,35 @@
import javax.xml.xpath.XPathFunction;
import javax.xml.xpath.XPathFunctionException;
import javax.xml.xpath.XPathFunctionResolver;
-import java.io.StringReader;
-import java.util.List;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.xml.sax.InputSource;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.Message;
+import org.apache.camel.Predicate;
+import org.apache.camel.RuntimeExpressionException;
+
+import static org.apache.camel.builder.xml.Namespaces.DEFAULT_NAMESPACE;
+import static org.apache.camel.builder.xml.Namespaces.IN_NAMESPACE;
+import static org.apache.camel.builder.xml.Namespaces.OUT_NAMESPACE;
+import static org.apache.camel.builder.xml.Namespaces.isMatchingNamespaceOrEmptyNamespace;
+import static org.apache.camel.converter.ObjectConverter.toBoolean;
/**
* Creates an XPath expression builder
- *
+ *
* @version $Revision: 531854 $
*/
public class XPathBuilder<E extends Exchange> implements Expression<E>, Predicate<E> {
private final String text;
private XPathFactory xpathFactory;
private Class documentType = Document.class;
- private QName resultType = null;
- private String objectModelUri = null;
+ private QName resultType;
+ private String objectModelUri;
private DefaultNamespaceContext namespaceContext;
private XPathFunctionResolver functionResolver;
private XPathExpression expression;
@@ -62,15 +68,14 @@
private XPathFunction outBodyFunction;
private XPathFunction outHeaderFunction;
+ public XPathBuilder(String text) {
+ this.text = text;
+ }
public static XPathBuilder xpath(String text) {
return new XPathBuilder(text);
}
- public XPathBuilder(String text) {
- this.text = text;
- }
-
@Override
public String toString() {
return "XPath: " + text;
@@ -93,11 +98,11 @@
}
// Builder methods
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
/**
* Sets the expression result type to boolean
- *
+ *
* @return the current builder
*/
public XPathBuilder<E> booleanResult() {
@@ -107,7 +112,7 @@
/**
* Sets the expression result type to boolean
- *
+ *
* @return the current builder
*/
public XPathBuilder<E> nodeResult() {
@@ -117,7 +122,7 @@
/**
* Sets the expression result type to boolean
- *
+ *
* @return the current builder
*/
public XPathBuilder<E> nodeSetResult() {
@@ -127,7 +132,7 @@
/**
* Sets the expression result type to boolean
- *
+ *
* @return the current builder
*/
public XPathBuilder<E> numberResult() {
@@ -137,7 +142,7 @@
/**
* Sets the expression result type to boolean
- *
+ *
* @return the current builder
*/
public XPathBuilder<E> stringResult() {
@@ -147,7 +152,7 @@
/**
* Sets the object model URI to use
- *
+ *
* @return the current builder
*/
public XPathBuilder<E> objectModel(String uri) {
@@ -156,8 +161,9 @@
}
/**
- * Sets the {@link XPathFunctionResolver} instance to use on these XPath expressions
- *
+ * Sets the {@link XPathFunctionResolver} instance to use on these XPath
+ * expressions
+ *
* @return the current builder
*/
public XPathBuilder<E> functionResolver(XPathFunctionResolver functionResolver) {
@@ -166,10 +172,12 @@
}
/**
- * Registers the namespace prefix and URI with the builder so that the prefix can be used in XPath expressions
- *
- * @param prefix is the namespace prefix that can be used in the XPath expressions
- * @param uri is the namespace URI to which the prefix refers
+ * Registers the namespace prefix and URI with the builder so that the
+ * prefix can be used in XPath expressions
+ *
+ * @param prefix is the namespace prefix that can be used in the XPath
+ * expressions
+ * @param uri is the namespace URI to which the prefix refers
* @return the current builder
*/
public XPathBuilder<E> namespace(String prefix, String uri) {
@@ -178,16 +186,16 @@
}
/**
- * Registers a variable (in the global namespace) which can be referred to from XPath expressions
+ * Registers a variable (in the global namespace) which can be referred to
+ * from XPath expressions
*/
public XPathBuilder<E> variable(String name, Object value) {
variableResolver.addVariable(name, value);
return this;
}
-
// Properties
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
public XPathFactory getXPathFactory() throws XPathFactoryConfigurationException {
if (xpathFactory == null) {
if (objectModelUri != null) {
@@ -221,11 +229,11 @@
public DefaultNamespaceContext getNamespaceContext() {
if (namespaceContext == null) {
try {
- DefaultNamespaceContext defaultNamespaceContext = new DefaultNamespaceContext(getXPathFactory());
+ DefaultNamespaceContext defaultNamespaceContext = new DefaultNamespaceContext(
+ getXPathFactory());
populateDefaultNamespaces(defaultNamespaceContext);
namespaceContext = defaultNamespaceContext;
- }
- catch (XPathFactoryConfigurationException e) {
+ } catch (XPathFactoryConfigurationException e) {
throw new RuntimeExpressionException(e);
}
}
@@ -244,7 +252,8 @@
this.functionResolver = functionResolver;
}
- public XPathExpression getExpression() throws XPathFactoryConfigurationException, XPathExpressionException {
+ public XPathExpression getExpression() throws XPathFactoryConfigurationException,
+ XPathExpressionException {
if (expression == null) {
expression = createXPathExpression();
}
@@ -334,7 +343,7 @@
}
// Implementation methods
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
/**
* Evaluates the expression as the given result type
@@ -346,32 +355,28 @@
Object document = getDocument(exchange);
if (resultType != null) {
if (document instanceof InputSource) {
- InputSource inputSource = (InputSource) document;
+ InputSource inputSource = (InputSource)document;
return getExpression().evaluate(inputSource, resultType);
- }
- else {
+ } else {
return getExpression().evaluate(document, resultType);
}
- }
- else {
+ } else {
if (document instanceof InputSource) {
- InputSource inputSource = (InputSource) document;
+ InputSource inputSource = (InputSource)document;
return getExpression().evaluate(inputSource);
- }
- else {
+ } else {
return getExpression().evaluate(document);
}
}
- }
- catch (XPathExpressionException e) {
+ } catch (XPathExpressionException e) {
throw new InvalidXPathExpression(getText(), e);
- }
- catch (XPathFactoryConfigurationException e) {
+ } catch (XPathFactoryConfigurationException e) {
throw new InvalidXPathExpression(getText(), e);
}
}
- protected XPathExpression createXPathExpression() throws XPathExpressionException, XPathFactoryConfigurationException {
+ protected XPathExpression createXPathExpression() throws XPathExpressionException,
+ XPathFactoryConfigurationException {
XPath xPath = getXPathFactory().newXPath();
// lets now clear any factory references to avoid keeping them around
@@ -417,7 +422,7 @@
}
if (answer == null) {
if (isMatchingNamespaceOrEmptyNamespace(qName.getNamespaceURI(), IN_NAMESPACE)
- || isMatchingNamespaceOrEmptyNamespace(qName.getNamespaceURI(), DEFAULT_NAMESPACE)) {
+ || isMatchingNamespaceOrEmptyNamespace(qName.getNamespaceURI(), DEFAULT_NAMESPACE)) {
String localPart = qName.getLocalPart();
if (localPart.equals("body") && argumentCount == 0) {
return getBodyFunction();
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathLanguage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathLanguage.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathLanguage.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathLanguage.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,20 +16,6 @@
*/
package org.apache.camel.builder.xml;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExpectedBodyTypeException;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
-import org.apache.camel.RuntimeTransformException;
-import org.apache.camel.converter.jaxp.XmlConverter;
-import static org.apache.camel.util.ObjectHelper.notNull;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.stream.StreamSource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -39,10 +24,26 @@
import java.util.Map;
import java.util.Set;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ExpectedBodyTypeException;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.RuntimeTransformException;
+import org.apache.camel.converter.jaxp.XmlConverter;
+
+import static org.apache.camel.util.ObjectHelper.notNull;
+
/**
* Creates a <a href="http://activemq.apache.org/camel/processor.html">Processor</a>
* which performs an XSLT transformation of the IN message body
- *
+ *
* @version $Revision: 531854 $
*/
public class XsltBuilder implements Processor {
@@ -77,7 +78,7 @@
}
// Builder methods
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
/**
* Creates an XSLT processor using the given transformer instance
@@ -150,7 +151,7 @@
}
// Properties
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
public Map<String, Object> getParameters() {
return parameters;
@@ -200,12 +201,10 @@
if (source == null) {
if (isFailOnNullBody()) {
throw new ExpectedBodyTypeException(exchange, Source.class);
- }
- else {
+ } else {
try {
source = converter.toSource(converter.createDocument());
- }
- catch (ParserConfigurationException e) {
+ } catch (ParserConfigurationException e) {
throw new RuntimeTransformException(e);
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/AmbiguousMethodCallException.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/AmbiguousMethodCallException.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/AmbiguousMethodCallException.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/AmbiguousMethodCallException.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -16,10 +16,10 @@
*/
package org.apache.camel.component.bean;
+import java.util.List;
+
import org.apache.camel.CamelExchangeException;
import org.apache.camel.Exchange;
-
-import java.util.List;
/**
* An exception thrown if an attempted method invocation resulted in an ambiguous method
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanComponent.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,6 +16,8 @@
*/
package org.apache.camel.component.bean;
+import java.util.Map;
+
import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.impl.ProcessorEndpoint;
@@ -25,8 +26,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.util.Map;
-
/**
* An alternative to the <a href="http://activemq.apache.org/pojo.html">POJO Component</a>
* which implements the <a href="http://activemq.apache.org/bean.html">Bean Component</a>
@@ -35,7 +34,7 @@
* @version $Revision: 1.1 $
*/
public class BeanComponent extends DefaultComponent {
- private static final Log log = LogFactory.getLog(BeanComponent.class);
+ private static final Log LOG = LogFactory.getLog(BeanComponent.class);
private ParameterMappingStrategy parameterMappingStrategy;
public BeanComponent() {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanExchange.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanExchange.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanExchange.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -16,6 +16,16 @@
*/
package org.apache.camel.component.bean;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
import org.apache.camel.Body;
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
@@ -24,28 +34,19 @@
import org.apache.camel.Property;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.builder.ExpressionBuilder;
-import static org.apache.camel.util.ExchangeHelper.convertToType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+import static org.apache.camel.util.ExchangeHelper.convertToType;
/**
* Represents the metadata about a bean type created via a combination of
* introspection and annotations together with some useful sensible defaults
- *
+ *
* @version $Revision: $
*/
public class BeanInfo {
- private static final transient Log log = LogFactory.getLog(BeanInfo.class);
+ private static final transient Log LOG = LogFactory.getLog(BeanInfo.class);
private Class type;
private ParameterMappingStrategy strategy;
private Map<String, MethodInfo> operations = new ConcurrentHashMap<String, MethodInfo>();
@@ -68,7 +69,8 @@
return type;
}
- public MethodInvocation createInvocation(Method method, Object pojo, Exchange exchange) throws RuntimeCamelException {
+ public MethodInvocation createInvocation(Method method, Object pojo, Exchange exchange)
+ throws RuntimeCamelException {
MethodInfo methodInfo = introspect(type, method);
if (methodInfo != null) {
return methodInfo.createMethodInvocation(pojo, exchange);
@@ -76,7 +78,8 @@
return null;
}
- public MethodInvocation createInvocation(Object pojo, Exchange exchange) throws RuntimeCamelException, AmbiguousMethodCallException {
+ public MethodInvocation createInvocation(Object pojo, Exchange exchange) throws RuntimeCamelException,
+ AmbiguousMethodCallException {
MethodInfo methodInfo = null;
// TODO use some other mechanism?
@@ -120,23 +123,24 @@
for (int i = 0; i < parameterTypes.length; i++) {
Class parameterType = parameterTypes[i];
Annotation[] parameterAnnotations = parametersAnnotations[i];
- Expression expression = createParameterUnmarshalExpression(clazz, method,
- parameterType, parameterAnnotations);
+ Expression expression = createParameterUnmarshalExpression(clazz, method, parameterType,
+ parameterAnnotations);
if (expression == null) {
if (parameterTypes.length == 1 && bodyParameters.isEmpty()) {
// lets assume its the body
expression = ExpressionBuilder.bodyExpression(parameterType);
- }
- else {
- if (log.isDebugEnabled()) {
- log.debug("No expression available for method: "
- + method.toString() + " which already has a body so ignoring parameter: " + i + " so ignoring method");
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("No expression available for method: " + method.toString()
+ + " which already has a body so ignoring parameter: " + i
+ + " so ignoring method");
}
return null;
}
}
- ParameterInfo parameterInfo = new ParameterInfo(i, parameterType, parameterAnnotations, expression);
+ ParameterInfo parameterInfo = new ParameterInfo(i, parameterType, parameterAnnotations,
+ expression);
parameters.add(parameterInfo);
if (isPossibleBodyParameter(parameterAnnotations)) {
bodyParameters.add(parameterInfo);
@@ -147,16 +151,13 @@
String opName = method.getName();
/*
-
- TODO allow an annotation to expose the operation name to use
-
- if (method.getAnnotation(Operation.class) != null) {
- String name = method.getAnnotation(Operation.class).name();
- if (name != null && name.length() > 0) {
- opName = name;
- }
- }
- */
+ *
+ * TODO allow an annotation to expose the operation name to use
+ *
+ * if (method.getAnnotation(Operation.class) != null) { String name =
+ * method.getAnnotation(Operation.class).name(); if (name != null &&
+ * name.length() > 0) { opName = name; } }
+ */
MethodInfo methodInfo = new MethodInfo(clazz, method, parameters, bodyParameters);
operations.put(opName, methodInfo);
if (methodInfo.hasBodyParameter()) {
@@ -168,16 +169,16 @@
/**
* Lets try choose one of the available methods to invoke if we can match
* the message body to the body parameter
- *
- * @param pojo the bean to invoke a method on
+ *
+ * @param pojo the bean to invoke a method on
* @param exchange the message exchange
- * @return the method to invoke or null if no definitive method could be matched
+ * @return the method to invoke or null if no definitive method could be
+ * matched
*/
protected MethodInfo chooseMethod(Object pojo, Exchange exchange) throws AmbiguousMethodCallException {
if (operationsWithBody.size() == 1) {
return operationsWithBody.get(0);
- }
- else if (!operationsWithBody.isEmpty()) {
+ } else if (!operationsWithBody.isEmpty()) {
// lets see if we can find a method who's body param type matches
// the message body
Message in = exchange.getIn();
@@ -193,8 +194,7 @@
}
if (possibles.size() == 1) {
return possibles.get(0);
- }
- else if (possibles.isEmpty()) {
+ } else if (possibles.isEmpty()) {
// lets try converting
Object newBody = null;
MethodInfo matched = null;
@@ -202,9 +202,9 @@
Object value = convertToType(exchange, methodInfo.getBodyParameterType(), body);
if (value != null) {
if (newBody != null) {
- throw new AmbiguousMethodCallException(exchange, Arrays.asList(matched, methodInfo));
- }
- else {
+ throw new AmbiguousMethodCallException(exchange, Arrays.asList(matched,
+ methodInfo));
+ } else {
newBody = value;
matched = methodInfo;
}
@@ -214,8 +214,7 @@
in.setBody(newBody);
return matched;
}
- }
- else {
+ } else {
throw new AmbiguousMethodCallException(exchange, possibles);
}
}
@@ -224,18 +223,19 @@
return null;
}
-
/**
- * Creates an expression for the given parameter type if the parameter can be mapped
- * automatically or null if the parameter cannot be mapped due to unsufficient
- * annotations or not fitting with the default type conventions.
+ * Creates an expression for the given parameter type if the parameter can
+ * be mapped automatically or null if the parameter cannot be mapped due to
+ * unsufficient annotations or not fitting with the default type
+ * conventions.
*/
- protected Expression createParameterUnmarshalExpression(Class clazz, Method method, Class parameterType, Annotation[] parameterAnnotation) {
+ protected Expression createParameterUnmarshalExpression(Class clazz, Method method, Class parameterType,
+ Annotation[] parameterAnnotation) {
// TODO look for a parameter annotation that converts into an expression
for (Annotation annotation : parameterAnnotation) {
- Expression answer = createParameterUnmarshalExpressionForAnnotation(
- clazz, method, parameterType, annotation);
+ Expression answer = createParameterUnmarshalExpressionForAnnotation(clazz, method, parameterType,
+ annotation);
if (answer != null) {
return answer;
}
@@ -243,7 +243,6 @@
return strategy.getDefaultParameterTypeExpression(parameterType);
}
-
protected boolean isPossibleBodyParameter(Annotation[] annotations) {
if (annotations != null) {
for (Annotation annotation : annotations) {
@@ -255,26 +254,25 @@
return true;
}
- protected Expression createParameterUnmarshalExpressionForAnnotation(Class clazz, Method method, Class parameterType, Annotation annotation) {
+ protected Expression createParameterUnmarshalExpressionForAnnotation(Class clazz, Method method,
+ Class parameterType,
+ Annotation annotation) {
if (annotation instanceof Property) {
- Property propertyAnnotation = (Property) annotation;
+ Property propertyAnnotation = (Property)annotation;
return ExpressionBuilder.propertyExpression(propertyAnnotation.name());
- }
- else if (annotation instanceof Header) {
- Header headerAnnotation = (Header) annotation;
+ } else if (annotation instanceof Header) {
+ Header headerAnnotation = (Header)annotation;
return ExpressionBuilder.headerExpression(headerAnnotation.name());
- }
- else if (annotation instanceof Body) {
- Body content = (Body) annotation;
+ } else if (annotation instanceof Body) {
+ Body content = (Body)annotation;
return ExpressionBuilder.bodyExpression(parameterType);
// TODO allow annotations to be used to create expressions?
-/*
- } else if (annotation instanceof XPath) {
- XPath xpathAnnotation = (XPath) annotation;
- return new JAXPStringXPathExpression(xpathAnnotation.xpath());
- }
-*/
+ /*
+ * } else if (annotation instanceof XPath) { XPath xpathAnnotation =
+ * (XPath) annotation; return new
+ * JAXPStringXPathExpression(xpathAnnotation.xpath()); }
+ */
}
return null;
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInvocation.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInvocation.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInvocation.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInvocation.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -16,11 +16,11 @@
*/
package org.apache.camel.component.bean;
-import org.apache.camel.Exchange;
-
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import org.apache.camel.Exchange;
+
public class BeanInvocation {
private final Object proxy;
@@ -47,24 +47,20 @@
/**
* This causes us to invoke the endpoint Pojo using reflection.
- *
+ *
* @param pojo
*/
public void invoke(Object pojo, Exchange exchange) {
try {
Object response = getMethod().invoke(pojo, getArgs());
exchange.getOut().setBody(response);
- }
- catch (InvocationTargetException e) {
+ } catch (InvocationTargetException e) {
exchange.setException(e.getCause());
- }
- catch (RuntimeException e) {
+ } catch (RuntimeException e) {
throw e;
- }
- catch (Throwable e) {
+ } catch (Throwable e) {
throw new RuntimeException(e);
}
}
-
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -16,41 +16,34 @@
*/
package org.apache.camel.component.bean;
+import java.lang.reflect.Method;
+
+import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
-import org.apache.camel.CamelContext;
import org.apache.camel.spi.Registry;
import org.apache.camel.util.ObjectHelper;
-import static org.apache.camel.util.ObjectHelper.isNullOrBlank;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.lang.reflect.Method;
+import static org.apache.camel.util.ObjectHelper.isNullOrBlank;
/**
- * A {@link Processor} which converts the inbound exchange to a method invocation on a POJO
- *
+ * A {@link Processor} which converts the inbound exchange to a method
+ * invocation on a POJO
+ *
* @version $Revision: $
*/
public class BeanProcessor implements Processor {
public static final String METHOD_NAME = "org.apache.camel.MethodName";
- private static final Log log = LogFactory.getLog(BeanProcessor.class);
+ private static final Log LOG = LogFactory.getLog(BeanProcessor.class);
private final Object pojo;
private final BeanInfo beanInfo;
private Method method;
private String methodName;
- public static ParameterMappingStrategy createParameterMappingStrategy(CamelContext camelContext) {
- Registry registry = camelContext.getRegistry();
- ParameterMappingStrategy answer = registry.lookup(ParameterMappingStrategy.class.getName(), ParameterMappingStrategy.class);
- if (answer == null) {
- answer = new DefaultParameterMappingStrategy();
- }
- return answer;
- }
-
public BeanProcessor(Object pojo, BeanInfo beanInfo) {
this.pojo = pojo;
this.beanInfo = beanInfo;
@@ -64,6 +57,15 @@
this(pojo, createParameterMappingStrategy(camelContext));
}
+ public static ParameterMappingStrategy createParameterMappingStrategy(CamelContext camelContext) {
+ Registry registry = camelContext.getRegistry();
+ ParameterMappingStrategy answer = registry.lookup(ParameterMappingStrategy.class.getName(),
+ ParameterMappingStrategy.class);
+ if (answer == null) {
+ answer = new DefaultParameterMappingStrategy();
+ }
+ return answer;
+ }
@Override
public String toString() {
String description = method != null ? " " + method : "";
@@ -71,8 +73,8 @@
}
public void process(Exchange exchange) throws Exception {
- if (log.isDebugEnabled()) {
- log.debug(">>>> invoking method for: " + exchange);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(">>>> invoking method for: " + exchange);
}
Message in = exchange.getIn();
BeanInvocation beanInvoke = in.getBody(BeanInvocation.class);
@@ -84,8 +86,7 @@
MethodInvocation invocation;
if (method != null) {
invocation = beanInfo.createInvocation(method, pojo, exchange);
- }
- else {
+ } else {
// lets pass in the method name to use if its specified
if (ObjectHelper.isNotNullAndNonEmpty(methodName)) {
if (isNullOrBlank(in.getHeader(METHOD_NAME, String.class))) {
@@ -102,17 +103,15 @@
if (value != null) {
exchange.getIn().setBody(value);
}
- }
- catch (Exception e) {
+ } catch (Exception e) {
throw e;
- }
- catch (Throwable throwable) {
+ } catch (Throwable throwable) {
throw new Exception(throwable);
}
}
// Properties
- //-----------------------------------------------------------------------
+ // -----------------------------------------------------------------------
public Method getMethod() {
return method;
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -16,12 +16,12 @@
*/
package org.apache.camel.component.bean;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Producer;
-
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Producer;
/**
* An {@link java.lang.reflect.InvocationHandler} which invokes a
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -16,13 +16,13 @@
*/
package org.apache.camel.component.bean;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.apache.camel.Message;
import org.apache.camel.builder.ExpressionBuilder;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
/**
* Represents the strategy used to figure out how to map a message exchange to a POJO method invocation
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -16,15 +16,15 @@
*/
package org.apache.camel.component.bean;
-import org.apache.camel.Exchange;
-import org.apache.camel.Expression;
-import org.apache.camel.util.ObjectHelper;
-
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.util.ObjectHelper;
/**
* @version $Revision: $
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInvocation.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInvocation.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInvocation.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInvocation.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/NoBeanAvailableException.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/NoBeanAvailableException.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/NoBeanAvailableException.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/NoBeanAvailableException.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterInfo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterInfo.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterInfo.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterInfo.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -16,9 +16,9 @@
*/
package org.apache.camel.component.bean;
-import org.apache.camel.Expression;
-
import java.lang.annotation.Annotation;
+
+import org.apache.camel.Expression;
/**
* @version $Revision: $
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterMappingStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterMappingStrategy.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterMappingStrategy.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ParameterMappingStrategy.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ProxyHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ProxyHelper.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ProxyHelper.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/ProxyHelper.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -16,31 +16,38 @@
*/
package org.apache.camel.component.bean;
+import java.lang.reflect.Proxy;
+
import org.apache.camel.Endpoint;
import org.apache.camel.Producer;
-import java.lang.reflect.Proxy;
-
/**
* A helper class for creating proxies which delegate to Camel
- *
+ *
* @version $Revision: 519973 $
*/
public class ProxyHelper {
/**
+ * Utility classes should not have a public constructor.
+ */
+ private ProxyHelper() {
+ }
+
+ /**
* Creates a Proxy which sends PojoExchange to the endpoint.
- *
+ *
* @throws Exception
*/
- public static Object createProxy(final Endpoint endpoint, ClassLoader cl, Class interfaces[]) throws Exception {
+ public static Object createProxy(final Endpoint endpoint, ClassLoader cl, Class interfaces[])
+ throws Exception {
final Producer producer = endpoint.createProducer();
return Proxy.newProxyInstance(cl, interfaces, new CamelInvocationHandler(endpoint, producer));
}
/**
* Creates a Proxy which sends PojoExchange to the endpoint.
- *
+ *
* @throws Exception
*/
public static Object createProxy(Endpoint endpoint, Class interfaces[]) throws Exception {
@@ -52,23 +59,23 @@
/**
* Creates a Proxy which sends PojoExchange to the endpoint.
- *
+ *
* @throws Exception
*/
@SuppressWarnings("unchecked")
- public static <T> T createProxy(Endpoint endpoint, ClassLoader cl, Class<T> interfaceClass) throws Exception {
- return (T) createProxy(endpoint, cl, new Class[]{interfaceClass});
+ public static <T> T createProxy(Endpoint endpoint, ClassLoader cl, Class<T> interfaceClass)
+ throws Exception {
+ return (T)createProxy(endpoint, cl, new Class[] {interfaceClass});
}
/**
* Creates a Proxy which sends PojoExchange to the endpoint.
- *
+ *
* @throws Exception
*/
@SuppressWarnings("unchecked")
public static <T> T createProxy(Endpoint endpoint, Class<T> interfaceClass) throws Exception {
- return (T) createProxy(endpoint, new Class[]{interfaceClass});
+ return (T)createProxy(endpoint, new Class[] {interfaceClass});
}
-
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectComponent.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectComponent.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectComponent.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -29,39 +29,39 @@
import org.apache.camel.util.URISupport;
/**
- * Represents the component that manages {@link DirectEndpoint}. It holds the
+ * Represents the component that manages {@link DirectEndpoint}. It holds the
* list of named direct endpoints.
- *
+ *
* @org.apache.xbean.XBean
* @version $Revision: 519973 $
*/
public class DirectComponent<E extends Exchange> implements Component<E> {
- private CamelContext context;
+ private CamelContext context;
- public CamelContext getCamelContext() {
- return context;
- }
+ public CamelContext getCamelContext() {
+ return context;
+ }
- public ScheduledExecutorService getExecutorService() {
- return null;
- }
+ public ScheduledExecutorService getExecutorService() {
+ return null;
+ }
- public Endpoint<E> createEndpoint(String uri) throws Exception {
+ public Endpoint<E> createEndpoint(String uri) throws Exception {
- ObjectHelper.notNull(getCamelContext(), "camelContext");
+ ObjectHelper.notNull(getCamelContext(), "camelContext");
URI u = new URI(uri);
Map parameters = URISupport.parseParamters(u);
- Endpoint<E> endpoint = new DirectEndpoint<E>(uri,this);
+ Endpoint<E> endpoint = new DirectEndpoint<E>(uri, this);
if (parameters != null) {
IntrospectionSupport.setProperties(endpoint, parameters);
}
return endpoint;
- }
+ }
- public void setCamelContext(CamelContext context) {
- this.context = context;
- }
+ public void setCamelContext(CamelContext context) {
+ this.context = context;
+ }
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -26,24 +26,22 @@
import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.impl.DefaultProducer;
-import org.apache.camel.util.ProducerCache;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
- * Represents a direct endpoint that synchronously invokes the consumers of the endpoint when a producer
- * sends a message to it.
- *
+ * Represents a direct endpoint that synchronously invokes the consumers of the
+ * endpoint when a producer sends a message to it.
+ *
* @org.apache.xbean.XBean
* @version $Revision: 519973 $
*/
public class DirectEndpoint<E extends Exchange> extends DefaultEndpoint<E> {
- private static final Log log = LogFactory.getLog(DirectEndpoint.class);
+ private static final Log LOG = LogFactory.getLog(DirectEndpoint.class);
+
+ boolean allowMultipleConsumers = true;
+ private final CopyOnWriteArrayList<DefaultConsumer<E>> consumers = new CopyOnWriteArrayList<DefaultConsumer<E>>();
- private final CopyOnWriteArrayList<DefaultConsumer<E>> consumers = new CopyOnWriteArrayList<DefaultConsumer<E>>();
-
- boolean allowMultipleConsumers=true;
-
public DirectEndpoint(String uri, DirectComponent<E> component) {
super(uri, component);
}
@@ -51,56 +49,57 @@
public Producer createProducer() throws Exception {
return new DefaultProducer(this) {
public void process(Exchange exchange) throws Exception {
- DirectEndpoint.this.process(exchange);
+ DirectEndpoint.this.process(exchange);
}
- };
+ };
}
protected void process(Exchange exchange) throws Exception {
- if (consumers.isEmpty()) {
- log.warn("No consumers available on " + this + " for " + exchange);
- }
- else {
- for (DefaultConsumer<E> consumer : consumers) {
- consumer.getProcessor().process(exchange);
- }
- }
- }
-
- public Consumer<E> createConsumer(Processor processor) throws Exception {
- return new DefaultConsumer<E>(this, processor) {
- @Override
- public void start() throws Exception {
- if( !allowMultipleConsumers && !consumers.isEmpty() )
- throw new IllegalStateException("Endpoint "+getEndpointUri()+" only allows 1 active consumer but you attempted to start a 2nd consumer.");
-
- consumers.add(this);
- super.start();
- }
-
- @Override
- public void stop() throws Exception {
- super.stop();
- consumers.remove(this);
- }
- };
+ if (consumers.isEmpty()) {
+ LOG.warn("No consumers available on " + this + " for " + exchange);
+ } else {
+ for (DefaultConsumer<E> consumer : consumers) {
+ consumer.getProcessor().process(exchange);
+ }
+ }
+ }
+
+ public Consumer<E> createConsumer(Processor processor) throws Exception {
+ return new DefaultConsumer<E>(this, processor) {
+ @Override
+ public void start() throws Exception {
+ if (!allowMultipleConsumers && !consumers.isEmpty()) {
+ throw new IllegalStateException("Endpoint " + getEndpointUri() + " only allows 1 active consumer but you attempted to start a 2nd consumer.");
+ }
+
+ consumers.add(this);
+ super.start();
+ }
+
+ @Override
+ public void stop() throws Exception {
+ super.stop();
+ consumers.remove(this);
+ }
+ };
}
public E createExchange() {
- // How can we create a specific Exchange if we are generic??
- // perhaps it would be better if we did not implement this.
- return (E) new DefaultExchange(getContext());
+ // How can we create a specific Exchange if we are generic??
+ // perhaps it would be better if we did not implement this.
+ return (E)new DefaultExchange(getContext());
+ }
+
+ public boolean isAllowMultipleConsumers() {
+ return allowMultipleConsumers;
}
- public boolean isAllowMultipleConsumers() {
- return allowMultipleConsumers;
- }
- public void setAllowMultipleConsumers(boolean allowMutlipleConsumers) {
- this.allowMultipleConsumers = allowMutlipleConsumers;
- }
-
- public boolean isSingleton() {
- return true;
- }
+ public void setAllowMultipleConsumers(boolean allowMutlipleConsumers) {
+ this.allowMultipleConsumers = allowMutlipleConsumers;
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,24 +16,24 @@
*/
package org.apache.camel.component.file;
+import java.io.File;
+import java.util.Map;
+
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.util.IntrospectionSupport;
-import java.io.File;
-import java.util.Map;
-import java.net.URI;
-
/**
- * The <a href="http://activemq.apache.org/camel/file.html">File Component</a> for working with file systems
- *
+ * The <a href="http://activemq.apache.org/camel/file.html">File Component</a>
+ * for working with file systems
+ *
* @version $Revision: 523772 $
*/
public class FileComponent extends DefaultComponent<FileExchange> {
public static final String HEADER_FILE_NAME = "org.apache.camel.file.name";
- public FileComponent() {
+ public FileComponent() {
}
public FileComponent(CamelContext context) {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,23 +16,23 @@
*/
package org.apache.camel.component.file;
+import java.io.File;
+
import org.apache.camel.Processor;
import org.apache.camel.component.file.strategy.FileStrategy;
import org.apache.camel.impl.ScheduledPollConsumer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.io.File;
-
/**
* @version $Revision: 523016 $
*/
public class FileConsumer extends ScheduledPollConsumer<FileExchange> {
- private static final transient Log log = LogFactory.getLog(FileConsumer.class);
+ private static final transient Log LOG = LogFactory.getLog(FileConsumer.class);
private final FileEndpoint endpoint;
private boolean recursive = true;
private String regexPattern = "";
- private long lastPollTime = 0l;
+ private long lastPollTime;
public FileConsumer(final FileEndpoint endpoint, Processor processor) {
super(endpoint, processor);
@@ -48,18 +47,16 @@
protected void pollFileOrDirectory(File fileOrDirectory, boolean processDir) {
if (!fileOrDirectory.isDirectory()) {
pollFile(fileOrDirectory); // process the file
- }
- else if (processDir) {
+ } else if (processDir) {
if (isValidFile(fileOrDirectory)) {
- log.debug("Polling directory " + fileOrDirectory);
+ LOG.debug("Polling directory " + fileOrDirectory);
File[] files = fileOrDirectory.listFiles();
for (int i = 0; i < files.length; i++) {
pollFileOrDirectory(files[i], isRecursive()); // self-recursion
}
}
- }
- else {
- log.debug("Skipping directory " + fileOrDirectory);
+ } else {
+ LOG.debug("Skipping directory " + fileOrDirectory);
}
}
@@ -70,20 +67,18 @@
FileExchange exchange = endpoint.createExchange(file);
try {
- if (log.isDebugEnabled()) {
- log.debug("About to process file: " + file + " using exchange: " + exchange);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("About to process file: " + file + " using exchange: " + exchange);
}
if (strategy.begin(endpoint, exchange, file)) {
getProcessor().process(exchange);
strategy.commit(endpoint, exchange, file);
- }
- else {
- if (log.isDebugEnabled()) {
- log.debug(endpoint + " cannot process file: " + file);
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(endpoint + " cannot process file: " + file);
}
}
- }
- catch (Throwable e) {
+ } catch (Throwable e) {
handleException(e);
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,6 +16,8 @@
*/
package org.apache.camel.component.file;
+import java.io.File;
+
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
@@ -28,23 +29,22 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.io.File;
-
/**
- * A <a href="http://activemq.apache.org/camel/file.html">File Endpoint</a> for working with file systems
- *
+ * A <a href="http://activemq.apache.org/camel/file.html">File Endpoint</a> for
+ * working with file systems
+ *
* @version $Revision: 523016 $
*/
public class FileEndpoint extends ScheduledPollEndpoint<FileExchange> {
- private static final transient Log log = LogFactory.getLog(FileEndpoint.class);
+ private static final transient Log LOG = LogFactory.getLog(FileEndpoint.class);
private File file;
private FileStrategy fileStrategy;
private boolean autoCreate = true;
private boolean lock = true;
- private boolean delete = false;
- private boolean noop = false;
- private String moveNamePrefix = null;
- private String moveNamePostfix = null;
+ private boolean delete;
+ private boolean noop;
+ private String moveNamePrefix;
+ private String moveNamePostfix;
private String[] excludedNamePrefixes = {"."};
protected FileEndpoint(File file, String endpointUri, FileComponent component) {
@@ -119,15 +119,15 @@
public FileStrategy getFileStrategy() {
if (fileStrategy == null) {
fileStrategy = createFileStrategy();
- log.debug("" + this + " using strategy: " + fileStrategy);
+ LOG.debug("" + this + " using strategy: " + fileStrategy);
}
return fileStrategy;
}
/**
- * Sets the strategy to be used when the file has been processed
- * such as deleting or renaming it etc.
- *
+ * Sets the strategy to be used when the file has been processed such as
+ * deleting or renaming it etc.
+ *
* @param fileStrategy the new stategy to use
*/
public void setFileStrategy(FileStrategy fileStrategy) {
@@ -155,9 +155,9 @@
}
/**
- * Sets the name postfix appended to moved files. For example
- * to rename all the files from * to *.done set this value to ".done"
- *
+ * Sets the name postfix appended to moved files. For example to rename all
+ * the files from * to *.done set this value to ".done"
+ *
* @param moveNamePostfix
* @see RenameFileStrategy#setNamePostfix(String)
*/
@@ -170,10 +170,10 @@
}
/**
- * Sets the name prefix appended to moved files. For example
- * to move processed files into a hidden directory called ".camel"
- * set this value to ".camel/"
- *
+ * Sets the name prefix appended to moved files. For example to move
+ * processed files into a hidden directory called ".camel" set this value to
+ * ".camel/"
+ *
* @see RenameFileStrategy#setNamePrefix(String)
*/
public void setMoveNamePrefix(String moveNamePrefix) {
@@ -185,8 +185,8 @@
}
/**
- * Sets the excluded file name prefixes, such as "." for hidden files
- * which are excluded by default
+ * Sets the excluded file name prefixes, such as "." for hidden files which
+ * are excluded by default
*/
public void setExcludedNamePrefixes(String[] excludedNamePrefixes) {
this.excludedNamePrefixes = excludedNamePrefixes;
@@ -197,9 +197,9 @@
}
/**
- * If set to true then the default {@link FileStrategy} will be to use
- * the {@link NoOpFileStrategy} to not move or copy processed files
- *
+ * If set to true then the default {@link FileStrategy} will be to use the
+ * {@link NoOpFileStrategy} to not move or copy processed files
+ *
* @param noop
*/
public void setNoop(boolean noop) {
@@ -212,17 +212,15 @@
protected FileStrategy createFileStrategy() {
if (isNoop()) {
return new NoOpFileStrategy();
- }
- else if (moveNamePostfix != null || moveNamePrefix != null) {
+ } else if (moveNamePostfix != null || moveNamePrefix != null) {
if (isDelete()) {
- throw new IllegalArgumentException("You cannot set the deleteFiles property and a moveFilenamePostfix or moveFilenamePrefix");
+ throw new IllegalArgumentException(
+ "You cannot set the deleteFiles property and a moveFilenamePostfix or moveFilenamePrefix");
}
return new RenameFileStrategy(isLock(), moveNamePrefix, moveNamePostfix);
- }
- else if (isDelete()) {
+ } else if (isDelete()) {
return new DeleteFileStrategy(isLock());
- }
- else {
+ } else {
return new RenameFileStrategy(isLock());
}
}