You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2007/08/09 22:33:52 UTC
svn commit: r564374 [2/7] - in
/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix:
./ client/ components/util/ components/util/xstream/
components/varscheduler/ expression/ jbi/ jbi/container/ jbi/deployment/
jbi/event...
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/PojoSupport.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/PojoSupport.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/PojoSupport.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/PojoSupport.java Thu Aug 9 13:33:26 2007
@@ -16,20 +16,29 @@
*/
package org.apache.servicemix.components.util;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.servicemix.jbi.FaultException;
-import org.apache.servicemix.jbi.NotInitialisedYetException;
-import org.apache.servicemix.jbi.management.BaseLifeCycle;
-
import javax.jbi.JBIException;
import javax.jbi.component.ComponentContext;
import javax.jbi.component.ComponentLifeCycle;
-import javax.jbi.messaging.*;
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOptionalOut;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
import javax.jbi.servicedesc.ServiceEndpoint;
import javax.management.ObjectName;
import javax.xml.namespace.QName;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.FaultException;
+import org.apache.servicemix.jbi.NotInitialisedYetException;
+import org.apache.servicemix.jbi.management.BaseLifeCycle;
+
/**
* A useful base class for a POJO based JBI component which contains most of the basic plumbing
*
@@ -37,6 +46,8 @@
*/
public abstract class PojoSupport extends BaseLifeCycle implements ComponentLifeCycle {
+ protected Log logger = LogFactory.getLog(getClass());
+
private ComponentContext context;
private ObjectName extensionMBeanName;
private QName service;
@@ -46,8 +57,6 @@
private ServiceEndpoint serviceEndpoint;
private DeliveryChannel channel;
- protected Log logger = LogFactory.getLog(getClass());
-
protected PojoSupport() {
}
@@ -60,7 +69,7 @@
* Get the description
* @return the description
*/
- public String getDescription(){
+ public String getDescription() {
return description;
}
@@ -235,7 +244,7 @@
* @throws MessagingException
*/
public void fail(MessageExchange exchange, Exception error) throws MessagingException {
- if (exchange instanceof InOnly || error instanceof FaultException == false) {
+ if (exchange instanceof InOnly || !(error instanceof FaultException)) {
exchange.setError(error);
} else {
FaultException faultException = (FaultException) error;
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/PollingComponentSupport.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/PollingComponentSupport.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/PollingComponentSupport.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/PollingComponentSupport.java Thu Aug 9 13:33:26 2007
@@ -31,13 +31,15 @@
import org.apache.servicemix.jbi.framework.ComponentContextImpl;
/**
- * An implementation inheritence class for a component which polls some resource at periodic intervals to decide if
- * there is an event to process.
+ * An implementation inheritence class for a component which polls some resource
+ * at periodic intervals to decide if there is an event to process.
*
* @version $Revision$
*/
public abstract class PollingComponentSupport extends ComponentSupport implements Work {
- private static final Log log = LogFactory.getLog(PollingComponentSupport.class);
+
+ private static final Log LOG = LogFactory.getLog(PollingComponentSupport.class);
+
private Executor executor;
private Scheduler scheduler;
private Date firstTime;
@@ -54,16 +56,15 @@
* @throws JBIException
*/
public abstract void poll() throws Exception;
-
+
public void release() {
}
public void run() {
try {
poll();
- }
- catch (Exception e) {
- log.error("Caught exception while polling: " + e, e);
+ } catch (Exception e) {
+ LOG.error("Caught exception while polling: " + e, e);
}
}
@@ -104,7 +105,7 @@
public void setScheduler(Scheduler scheduler) {
this.scheduler = scheduler;
}
-
+
public synchronized void start() throws JBIException {
if (!started) {
started = true;
@@ -112,7 +113,7 @@
schedulerTask.cancel();
}
schedulerTask = new PollSchedulerTask();
- this.scheduler.schedule(schedulerTask,scheduleIterator);
+ this.scheduler.schedule(schedulerTask, scheduleIterator);
}
super.start();
}
@@ -144,43 +145,44 @@
scheduler = new Scheduler(true);
}
if (scheduleIterator == null) {
- scheduleIterator = new PollScheduleIterator();
+ scheduleIterator = new PollScheduleIterator();
}
if (executor == null) {
ComponentContextImpl context = (ComponentContextImpl) getContext();
- ExecutorFactory factory = context.getContainer().getExecutorFactory();
- executor = factory.createExecutor("component." + context.getComponentName());
+ ExecutorFactory factory = context.getContainer()
+ .getExecutorFactory();
+ executor = factory.createExecutor("component."
+ + context.getComponentName());
}
super.init();
-
+
}
-
+
private class PollSchedulerTask extends SchedulerTask {
- public void run() {
- try {
- // lets run the work inside the JCA worker pools to ensure
- // the threads are setup correctly when we actually do stuff
- getExecutor().execute(PollingComponentSupport.this);
- }
- catch (Throwable e) {
- log.error("Failed to schedule work: " + e, e);
- }
- }
+ public void run() {
+ try {
+ // lets run the work inside the JCA worker pools to ensure
+ // the threads are setup correctly when we actually do stuff
+ getExecutor().execute(PollingComponentSupport.this);
+ } catch (Throwable e) {
+ LOG.error("Failed to schedule work: " + e, e);
+ }
+ }
}
-
+
private class PollScheduleIterator implements ScheduleIterator {
- public Date nextExecution() {
- long nextTime = System.currentTimeMillis();
- if (scheduleExecutedFlag) {
- nextTime += period;
- } else {
- if (firstTime != null) {
- nextTime = firstTime.getTime();
- }
- nextTime += delay;
- scheduleExecutedFlag = true;
- }
- return (started) ? new Date(nextTime) : null;
+ public Date nextExecution() {
+ long nextTime = System.currentTimeMillis();
+ if (scheduleExecutedFlag) {
+ nextTime += period;
+ } else {
+ if (firstTime != null) {
+ nextTime = firstTime.getTime();
+ }
+ nextTime += delay;
+ scheduleExecutedFlag = true;
+ }
+ return started ? new Date(nextTime) : null;
}
}
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/SimpleFlatFileMarshaler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/SimpleFlatFileMarshaler.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/SimpleFlatFileMarshaler.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/SimpleFlatFileMarshaler.java Thu Aug 9 13:33:26 2007
@@ -28,7 +28,6 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang.StringUtils;
-import org.apache.servicemix.components.util.DefaultFileMarshaler;
import org.apache.servicemix.jbi.jaxp.StringSource;
/**
@@ -40,22 +39,26 @@
*/
public class SimpleFlatFileMarshaler extends DefaultFileMarshaler {
- private static final String XML_OPEN = "<";
+ public static final String XMLDECLARATION_LINE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
- private static final String XML_OPEN_END = "</";
+ public static final ContentConverter NO_CONVERSION = new NoConversion();
- private static final String XML_CLOSE = ">";
+ public static final ContentConverter TEXT_STRIPPER = new TextStripConverter();
- private static final String XML_CLOSE_NEWLINE = ">\n";
+ public static final int LINEFORMAT_FIXLENGTH = 0;
+ public static final int LINEFORMAT_CSV = 1;
+ public static final int LINEFORMAT_VARIABLE = 2;
+ public static final int LINEFORMAT_DEFAULT = LINEFORMAT_FIXLENGTH;
+ private static final String XML_OPEN = "<";
+ private static final String XML_OPEN_END = "</";
+ private static final String XML_CLOSE = ">";
+ private static final String XML_CLOSE_NEWLINE = ">\n";
private static final String XML_CLOSE_ATTR_NEWLINE = "\">\n";
-
private static final String XML_CLOSE_ATTR = "\">";
private boolean xmlDeclaration = true;
- public static final String XMLDECLARATION_LINE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
-
/**
* Encoding for the input file. Can be null for default encoding
*/
@@ -78,14 +81,6 @@
*/
private String columnElementname = "Column";
- public static final int LINEFORMAT_FIXLENGTH = 0;
-
- public static final int LINEFORMAT_CSV = 1;
-
- public static final int LINEFORMAT_VARIABLE = 2;
-
- public static final int LINEFORMAT_DEFAULT = LINEFORMAT_FIXLENGTH;
-
private int lineFormat = LINEFORMAT_DEFAULT;
/**
@@ -103,367 +98,367 @@
private boolean insertLineNumbers = true;
- private boolean insertColNumbers = false;
+ private boolean insertColNumbers;
private boolean skipKnownEmptyCols = true;
private boolean alwaysStripColContents = true;
- private boolean insertRawData = false;
+ private boolean insertRawData;
- private boolean insertColContentInAttribut = false;
+ private boolean insertColContentInAttribut;
- private int headerlinesCount = 0;
-
- public static final ContentConverter noConversion = new NoConversion();
-
- public static final ContentConverter textStripper = new TextStripConverter();
+ private int headerlinesCount;
public void readMessage(MessageExchange exchange,
- NormalizedMessage message, InputStream in, String path)
- throws IOException, JBIException {
- message.setContent(new StringSource(this.convertLinesToString(message,
- in, path)));
- message.setProperty(FILE_NAME_PROPERTY, new File(path).getName());
- message.setProperty(FILE_PATH_PROPERTY, path);
+ NormalizedMessage message,
+ InputStream in,
+ String path) throws IOException, JBIException {
+ message.setContent(new StringSource(this.convertLinesToString(message, in, path)));
+ message.setProperty(FILE_NAME_PROPERTY, new File(path).getName());
+ message.setProperty(FILE_PATH_PROPERTY, path);
}
// Implementation methods
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
protected InputStream convertLinesToStream(NormalizedMessage message,
- InputStream in, String path) throws IOException {
- return IOUtils.toInputStream(this.convertLinesToString(message, in,
- path), "UTF-8");
+ InputStream in, String path) throws IOException {
+ return IOUtils.toInputStream(this.convertLinesToString(message, in,
+ path), "UTF-8");
}
protected InputStream convertLines(NormalizedMessage message,
- InputStream in, String path) throws IOException {
- return this.convertLinesToStream(message, in, path);
+ InputStream in, String path) throws IOException {
+ return this.convertLinesToStream(message, in, path);
}
protected String convertLinesToString(NormalizedMessage message,
- InputStream in, String path) throws IOException {
- LineIterator lines = IOUtils.lineIterator(in, this.encoding);
-
- StringBuffer aBuffer = new StringBuffer(1024);
+ InputStream in, String path) throws IOException {
+ LineIterator lines = IOUtils.lineIterator(in, this.encoding);
- if (this.xmlDeclaration)
- aBuffer.append(XMLDECLARATION_LINE);
+ StringBuffer aBuffer = new StringBuffer(1024);
- aBuffer.append(XML_OPEN + this.docElementname);
-
- if (this.docElementNamespace != null) {
- aBuffer.append("xmlns=\"");
- aBuffer.append(this.docElementNamespace);
- aBuffer.append("\"");
- }
-
- aBuffer.append(" name=\"");
- aBuffer.append(new File(path).getName());
- aBuffer.append("\"");
-
- aBuffer.append(" location=\"");
- aBuffer.append(path);
- aBuffer.append(XML_CLOSE_ATTR_NEWLINE);
-
- this.processHeaderLines(aBuffer, lines);
-
- int lineNumber = 1;
- while (lines.hasNext()) {
- String lineText = lines.nextLine();
- aBuffer.append(XML_OPEN + this.lineElementname);
-
- if (this.insertLineNumbers || this.insertRawData) {
- if (this.insertLineNumbers) {
- aBuffer.append(" number=\"");
- aBuffer.append(lineNumber);
- if (!this.insertRawData)
- aBuffer.append(XML_CLOSE_ATTR);
- else
- aBuffer.append("\"");
- }
- if (this.insertRawData) {
- aBuffer.append(" raw=\"");
- aBuffer.append(lineText);
- aBuffer.append(XML_CLOSE_ATTR);
- }
- } else
- aBuffer.append(XML_CLOSE);
-
- if ((this.columnLengths != null)
- || (this.lineFormat != LINEFORMAT_FIXLENGTH)) {
- this.extractColumns(aBuffer, lineText, lines);
- } else
- aBuffer.append(lineText);
- aBuffer.append(XML_OPEN_END + this.lineElementname
- + XML_CLOSE_NEWLINE);
+ if (this.xmlDeclaration) {
+ aBuffer.append(XMLDECLARATION_LINE);
+ }
+
+ aBuffer.append(XML_OPEN + this.docElementname);
+
+ if (this.docElementNamespace != null) {
+ aBuffer.append("xmlns=\"");
+ aBuffer.append(this.docElementNamespace);
+ aBuffer.append("\"");
+ }
+
+ aBuffer.append(" name=\"");
+ aBuffer.append(new File(path).getName());
+ aBuffer.append("\"");
+
+ aBuffer.append(" location=\"");
+ aBuffer.append(path);
+ aBuffer.append(XML_CLOSE_ATTR_NEWLINE);
+
+ this.processHeaderLines(aBuffer, lines);
+
+ int lineNumber = 1;
+ while (lines.hasNext()) {
+ String lineText = lines.nextLine();
+ aBuffer.append(XML_OPEN + this.lineElementname);
+
+ if (this.insertLineNumbers || this.insertRawData) {
+ if (this.insertLineNumbers) {
+ aBuffer.append(" number=\"");
+ aBuffer.append(lineNumber);
+ if (!this.insertRawData) {
+ aBuffer.append(XML_CLOSE_ATTR);
+ } else {
+ aBuffer.append("\"");
+ }
+ }
+ if (this.insertRawData) {
+ aBuffer.append(" raw=\"");
+ aBuffer.append(lineText);
+ aBuffer.append(XML_CLOSE_ATTR);
+ }
+ } else {
+ aBuffer.append(XML_CLOSE);
+ }
+
+ if ((this.columnLengths != null)
+ || (this.lineFormat != LINEFORMAT_FIXLENGTH)) {
+ this.extractColumns(aBuffer, lineText, lines);
+ } else {
+ aBuffer.append(lineText);
+ }
+ aBuffer.append(XML_OPEN_END + this.lineElementname
+ + XML_CLOSE_NEWLINE);
- lineNumber++;
- }
+ lineNumber++;
+ }
- aBuffer.append(XML_OPEN_END + this.docElementname + XML_CLOSE_NEWLINE);
+ aBuffer.append(XML_OPEN_END + this.docElementname + XML_CLOSE_NEWLINE);
- return aBuffer.toString();
+ return aBuffer.toString();
}
protected void processHeaderLines(StringBuffer buffer, LineIterator lines) {
- if ((this.headerlinesCount > 0) && (lines.hasNext())) {
- int counter = 0;
- do {
- String headerline = lines.nextLine();
- this.convertHeaderline(buffer, headerline);
-
- counter++;
- } while ((counter < this.headerlinesCount) && (lines.hasNext()));
- }
+ if ((this.headerlinesCount > 0) && (lines.hasNext())) {
+ int counter = 0;
+ do {
+ String headerline = lines.nextLine();
+ this.convertHeaderline(buffer, headerline);
+
+ counter++;
+ } while ((counter < this.headerlinesCount) && (lines.hasNext()));
+ }
}
protected void convertHeaderline(StringBuffer buffer, String headerline) {
}
protected void extractColumns(StringBuffer buffer, String lineText,
- LineIterator lines) {
- String[] rawcolContents = this.extractColumnContents(lineText, lines);
+ LineIterator lines) {
+ String[] rawcolContents = this.extractColumnContents(lineText, lines);
- if ((rawcolContents != null) && (rawcolContents.length > 0)) {
- for (int i = 0; i < rawcolContents.length; i++) {
- String colText = rawcolContents[i];
-
- String colName = this.findColumnname(i);
- String colContents = this.convertColumnContents(i, colText);
-
- if (colContents == null) {
- // Simple skip
- // Or maybe insert NULL Element
- } else {
- if (!((colContents.length() == 0)
- && (this.skipKnownEmptyCols) && (!this.columnElementname
- .equals(colName)))) {
- if (this.insertColContentInAttribut) {
- buffer.append(XML_OPEN + colName);
-
- if (this.insertColNumbers) {
- buffer.append(" number=\"");
- buffer.append(i + 1);
- buffer.append("\"");
- }
- buffer.append(" value=\"");
- buffer.append(colContents);
- buffer.append("\"/>");
- } else {
- if (!this.insertColNumbers)
- buffer.append(XML_OPEN + colName + XML_CLOSE);
- else {
- buffer.append(XML_OPEN + colName);
- buffer.append(" number=\"");
- buffer.append(i + 1);
- buffer.append("\"/>");
- }
- buffer.append(colContents);
- buffer.append(XML_OPEN_END + colName + XML_CLOSE);
- }
- }
- }
- }
- }
+ if ((rawcolContents != null) && (rawcolContents.length > 0)) {
+ for (int i = 0; i < rawcolContents.length; i++) {
+ String colText = rawcolContents[i];
+
+ String colName = this.findColumnname(i);
+ String colContents = this.convertColumnContents(i, colText);
+
+ if (colContents == null) {
+ // Simple skip
+ // Or maybe insert NULL Element
+ } else {
+ if (!((colContents.length() == 0)
+ && (this.skipKnownEmptyCols) && (!this.columnElementname
+ .equals(colName)))) {
+ if (this.insertColContentInAttribut) {
+ buffer.append(XML_OPEN + colName);
+
+ if (this.insertColNumbers) {
+ buffer.append(" number=\"");
+ buffer.append(i + 1);
+ buffer.append("\"");
+ }
+ buffer.append(" value=\"");
+ buffer.append(colContents);
+ buffer.append("\"/>");
+ } else {
+ if (!this.insertColNumbers) {
+ buffer.append(XML_OPEN + colName + XML_CLOSE);
+ } else {
+ buffer.append(XML_OPEN + colName);
+ buffer.append(" number=\"");
+ buffer.append(i + 1);
+ buffer.append("\"/>");
+ }
+ buffer.append(colContents);
+ buffer.append(XML_OPEN_END + colName + XML_CLOSE);
+ }
+ }
+ }
+ }
+ }
}
protected String[] extractColumnContents(String lineText, LineIterator lines) {
- String[] result = null;
+ String[] result = null;
- if ((lineText != null) && (lineText.length() > 0)) {
- if (this.lineFormat == LINEFORMAT_FIXLENGTH) {
- if ((this.columnLengths != null)
- && (this.columnLengths.length > 0)) {
- result = new String[this.columnLengths.length];
- int curIndex = 0;
-
- for (int i = 0; i < this.columnLengths.length; i++) {
- try {
- result[i] = lineText.substring(curIndex, curIndex
- + this.columnLengths[i]);
-
- curIndex += this.columnLengths[i];
-
- } catch (StringIndexOutOfBoundsException e) {
- break;
- }
- }
- }
- } else if (this.lineFormat == LINEFORMAT_CSV) {
- result = StringUtils.splitPreserveAllTokens(lineText,
- this.columnSeparator);
- } else if (this.lineFormat == LINEFORMAT_VARIABLE) {
- if (this.columnExtractor == null)
- throw new IllegalStateException(
- "No Column Extractor defined");
-
- result = this.columnExtractor.extractColumns(lineText);
- } else
- throw new IllegalStateException("Unknown line format '"
- + this.lineFormat + "'");
- }
+ if ((lineText != null) && (lineText.length() > 0)) {
+ if (this.lineFormat == LINEFORMAT_FIXLENGTH) {
+ if ((this.columnLengths != null)
+ && (this.columnLengths.length > 0)) {
+ result = new String[this.columnLengths.length];
+ int curIndex = 0;
+
+ for (int i = 0; i < this.columnLengths.length; i++) {
+ try {
+ result[i] = lineText.substring(curIndex, curIndex
+ + this.columnLengths[i]);
+
+ curIndex += this.columnLengths[i];
+
+ } catch (StringIndexOutOfBoundsException e) {
+ break;
+ }
+ }
+ }
+ } else if (this.lineFormat == LINEFORMAT_CSV) {
+ result = StringUtils.splitPreserveAllTokens(lineText,
+ this.columnSeparator);
+ } else if (this.lineFormat == LINEFORMAT_VARIABLE) {
+ if (this.columnExtractor == null) {
+ throw new IllegalStateException("No Column Extractor defined");
+ }
+ result = this.columnExtractor.extractColumns(lineText);
+ } else {
+ throw new IllegalStateException("Unknown line format '" + this.lineFormat + "'");
+ }
+ }
- return result;
+ return result;
}
protected String findColumnname(int index) {
- String result = this.columnElementname;
+ String result = this.columnElementname;
- if ((this.columnNames != null) && (this.columnNames.length > index)
- && (this.columnNames[index] != null)) {
- return this.columnNames[index];
- }
+ if ((this.columnNames != null) && (this.columnNames.length > index)
+ && (this.columnNames[index] != null)) {
+ return this.columnNames[index];
+ }
- return result;
+ return result;
}
protected String convertColumnContents(int index, String contents) {
- if ((this.columnConverters != null)
- && (this.columnConverters.size() > index)
- && (this.columnConverters.get(index) != null)) {
- ContentConverter converter = (ContentConverter) this.columnConverters
- .get(index);
- return converter.convertToXml(contents);
- } else {
- if (this.alwaysStripColContents)
- return textStripper.convertToXml(contents);
- else
- return noConversion.convertToXml(contents);
- }
+ if ((this.columnConverters != null)
+ && (this.columnConverters.size() > index)
+ && (this.columnConverters.get(index) != null)) {
+ ContentConverter converter = (ContentConverter) this.columnConverters.get(index);
+ return converter.convertToXml(contents);
+ } else {
+ if (this.alwaysStripColContents) {
+ return TEXT_STRIPPER.convertToXml(contents);
+ } else {
+ return NO_CONVERSION.convertToXml(contents);
+ }
+ }
}
// Properties
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
public final String getEncoding() {
- return encoding;
+ return encoding;
}
public final void setEncoding(String encoding) {
- this.encoding = encoding;
+ this.encoding = encoding;
}
public final String getColumnElementname() {
- return columnElementname;
+ return columnElementname;
}
public final void setColumnElementname(String columnElementname) {
- this.columnElementname = columnElementname;
+ this.columnElementname = columnElementname;
}
public final String getDocElementname() {
- return docElementname;
+ return docElementname;
}
public final void setDocElementname(String docElementname) {
- this.docElementname = docElementname;
+ this.docElementname = docElementname;
}
public final String getLineElementname() {
- return lineElementname;
+ return lineElementname;
}
public final void setLineElementname(String lineElementname) {
- this.lineElementname = lineElementname;
+ this.lineElementname = lineElementname;
}
public final void setColumnLengths(String[] columnLengths) {
- this.columnLengths = new int[columnLengths.length];
- for (int i = 0; i < columnLengths.length; i++)
- this.columnLengths[i] = Integer.parseInt(columnLengths[i]);
+ this.columnLengths = new int[columnLengths.length];
+ for (int i = 0; i < columnLengths.length; i++) {
+ this.columnLengths[i] = Integer.parseInt(columnLengths[i]);
+ }
}
public final boolean isXmlDeclaration() {
- return xmlDeclaration;
+ return xmlDeclaration;
}
public final void setXmlDeclaration(boolean xmlDeclaration) {
- this.xmlDeclaration = xmlDeclaration;
+ this.xmlDeclaration = xmlDeclaration;
}
public final void setInsertLineNumbers(boolean insertLineNumbers) {
- this.insertLineNumbers = insertLineNumbers;
+ this.insertLineNumbers = insertLineNumbers;
}
public final void setColumnConverters(List columnConverters) {
- this.columnConverters = columnConverters;
+ this.columnConverters = columnConverters;
}
public final void setColumnNames(String[] columnNames) {
- this.columnNames = columnNames;
+ this.columnNames = columnNames;
}
public final boolean isSkipKnownEmptyCols() {
- return skipKnownEmptyCols;
+ return skipKnownEmptyCols;
}
public final void setSkipKnownEmptyCols(boolean skipKnownEmptyCols) {
- this.skipKnownEmptyCols = skipKnownEmptyCols;
+ this.skipKnownEmptyCols = skipKnownEmptyCols;
}
public final void setInsertRawData(boolean insertRawData) {
- this.insertRawData = insertRawData;
+ this.insertRawData = insertRawData;
}
public final boolean isAlwaysStripColContents() {
- return alwaysStripColContents;
+ return alwaysStripColContents;
}
public final void setAlwaysStripColContents(boolean alwaysStripColContents) {
- this.alwaysStripColContents = alwaysStripColContents;
+ this.alwaysStripColContents = alwaysStripColContents;
}
public final int getLineFormat() {
- return lineFormat;
+ return lineFormat;
}
public final void setLineFormat(int lineFormat) {
- this.lineFormat = lineFormat;
+ this.lineFormat = lineFormat;
}
public final String getColumnSeparator() {
- return columnSeparator;
+ return columnSeparator;
}
public final void setColumnSeparator(String columnSeparator) {
- this.columnSeparator = columnSeparator;
+ this.columnSeparator = columnSeparator;
}
public final String getDocElementNamespace() {
- return docElementNamespace;
+ return docElementNamespace;
}
public final void setDocElementNamespace(String docElementNamespace) {
- this.docElementNamespace = docElementNamespace;
+ this.docElementNamespace = docElementNamespace;
}
public final int getHeaderlinesCount() {
- return headerlinesCount;
+ return headerlinesCount;
}
public final void setHeaderlinesCount(int headerlinesCount) {
- this.headerlinesCount = headerlinesCount;
+ this.headerlinesCount = headerlinesCount;
}
public final boolean isInsertColContentInAttribut() {
- return insertColContentInAttribut;
+ return insertColContentInAttribut;
}
public final void setInsertColContentInAttribut(
- boolean insertColContentInAttribut) {
- this.insertColContentInAttribut = insertColContentInAttribut;
+ boolean insertColContentInAttribut) {
+ this.insertColContentInAttribut = insertColContentInAttribut;
}
public final boolean isInsertColNumbers() {
- return insertColNumbers;
+ return insertColNumbers;
}
public final void setInsertColNumbers(boolean insertColNumbers) {
- this.insertColNumbers = insertColNumbers;
+ this.insertColNumbers = insertColNumbers;
}
public final void setColumnExtractor(ColumnExtractor columnExtractor) {
- this.columnExtractor = columnExtractor;
+ this.columnExtractor = columnExtractor;
}
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/SpringBootstrap.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/SpringBootstrap.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/SpringBootstrap.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/SpringBootstrap.java Thu Aug 9 13:33:26 2007
@@ -16,6 +16,16 @@
*/
package org.apache.servicemix.components.util;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.Bootstrap;
+import javax.jbi.component.InstallationContext;
+import javax.management.ObjectName;
+
+import org.w3c.dom.DocumentFragment;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.jbi.NotInitialisedYetException;
@@ -23,29 +33,24 @@
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
-import org.w3c.dom.DocumentFragment;
-
-import javax.jbi.JBIException;
-import javax.jbi.component.Bootstrap;
-import javax.jbi.component.InstallationContext;
-import javax.management.ObjectName;
-
-import java.util.Iterator;
-import java.util.Map;
/**
* A Spring implementation of the {@link Bootstrap}
- *
+ *
* @version $Revision$
*/
public class SpringBootstrap implements Bootstrap, ApplicationContextAware {
+
+ private static final Log LOG = LogFactory.getLog(SpringBootstrap.class);
+
private InstallationContext installContext;
+
private ObjectName extensionMBeanName;
+
private ApplicationContext applicationContext;
- private static Log log = LogFactory.getLog(SpringBootstrap.class);
-
- public void init(InstallationContext installContext) throws JBIException {
- this.installContext = installContext;
+
+ public void init(InstallationContext ctx) throws JBIException {
+ this.installContext = ctx;
}
public void cleanUp() throws JBIException {
@@ -61,15 +66,15 @@
}
DocumentFragment fragment = installContext.getInstallationDescriptorExtension();
if (fragment != null) {
- log.debug("Installation Descriptor Extension Found");
+ LOG.debug("Installation Descriptor Extension Found");
} else {
- log.debug("Installation Descriptor Extension Not Found !");
+ LOG.debug("Installation Descriptor Extension Not Found !");
}
// lets load this from Spring...
Map map = applicationContext.getBeansOfType(ActivationSpec.class, false, false);
- for (Iterator iter = map.values().iterator(); iter.hasNext(); ) {
+ for (Iterator iter = map.values().iterator(); iter.hasNext();) {
ActivationSpec spec = (ActivationSpec) iter.next();
- log.debug("Registering "+spec.getComponentName());
+ LOG.debug("Registering " + spec.getComponentName());
}
}
@@ -80,7 +85,7 @@
return installContext;
}
- public void setApplicationContext(ApplicationContext appCtx) throws BeansException {
- this.applicationContext = appCtx;
- }
+ public void setApplicationContext(ApplicationContext appCtx) throws BeansException {
+ this.applicationContext = appCtx;
+ }
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TextStripConverter.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TextStripConverter.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TextStripConverter.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TextStripConverter.java Thu Aug 9 13:33:26 2007
@@ -19,8 +19,9 @@
import org.apache.commons.lang.StringUtils;
/**
- * Column converter for SimpleFlatFileMarshaler that strips off leading
- * and trailing whitespaces from flat file columns
+ * Column converter for SimpleFlatFileMarshaler that strips off leading and
+ * trailing whitespaces from flat file columns
+ *
* @author Mayrbaeurl
* @since 3.2
* @see StringUtils#strip(String)
@@ -28,12 +29,12 @@
public class TextStripConverter implements ContentConverter {
// Implementation methods
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
public String convertToXml(String contents) {
- return StringUtils.strip(contents);
+ return StringUtils.strip(contents);
}
public String convertToFlatFileContent(String contents) {
- return contents;
+ return contents;
}
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TraceComponent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TraceComponent.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TraceComponent.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TraceComponent.java Thu Aug 9 13:33:26 2007
@@ -16,16 +16,16 @@
*/
package org.apache.servicemix.components.util;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.servicemix.MessageExchangeListener;
-import org.apache.servicemix.jbi.jaxp.SourceTransformer;
-
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import javax.xml.transform.TransformerException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+
/**
* A simple tracing component which can be placed inside a pipeline
* to trace the message exchange though the component.
@@ -59,13 +59,11 @@
NormalizedMessage message = exchange.getMessage("in");
if (message == null) {
log.warn("Received null message from exchange: " + exchange);
- }
- else {
+ } else {
log.info("Exchange: " + exchange + " received IN message: " + message);
try {
log.info("Body is: " + sourceTransformer.toString(message.getContent()));
- }
- catch (TransformerException e) {
+ } catch (TransformerException e) {
log.error("Failed to turn message body into text: " + e, e);
}
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TransformComponent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TransformComponent.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TransformComponent.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TransformComponent.java Thu Aug 9 13:33:26 2007
@@ -16,11 +16,11 @@
*/
package org.apache.servicemix.components.util;
-import org.springframework.beans.factory.InitializingBean;
-
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
+
+import org.springframework.beans.factory.InitializingBean;
/**
* A Java based transformation component using a plugable {@link MessageTransformer} instance
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TransformComponentSupport.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TransformComponentSupport.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TransformComponentSupport.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/TransformComponentSupport.java Thu Aug 9 13:33:26 2007
@@ -76,8 +76,7 @@
} else {
getDeliveryChannel().send(exchange);
}
- }
- else {
+ } else {
outExchange.setMessage(out, "in");
if (txSync) {
getDeliveryChannel().sendSync(outExchange);
@@ -91,8 +90,7 @@
exchange.setStatus(ExchangeStatus.DONE);
getDeliveryChannel().send(exchange);
}
- }
- catch (Exception e) {
+ } catch (Exception e) {
try {
fail(exchange, e);
} catch (Exception e2) {
@@ -143,7 +141,8 @@
/**
* If enabled the properties and attachments are copied to the destination message
*/
- protected void copyPropertiesAndAttachments(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+ protected void copyPropertiesAndAttachments(MessageExchange exchange, NormalizedMessage in,
+ NormalizedMessage out) throws MessagingException {
if (isCopyProperties()) {
CopyTransformer.copyProperties(in, out);
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/VariableFixedLengthColumnExtractor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/VariableFixedLengthColumnExtractor.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/VariableFixedLengthColumnExtractor.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/VariableFixedLengthColumnExtractor.java Thu Aug 9 13:33:26 2007
@@ -22,14 +22,15 @@
import org.apache.commons.lang.StringUtils;
/**
- * Column extractor for SimpleFlatFileMarshaler that can extract columns
- * from fixed-length flat files that have a variable count of columns based on
- * a discriminator column value
+ * Column extractor for SimpleFlatFileMarshaler that can extract columns from
+ * fixed-length flat files that have a variable count of columns based on a
+ * discriminator column value
+ *
* @author Mayrbaeurl
* @since 3.2
*/
public class VariableFixedLengthColumnExtractor implements ColumnExtractor {
-
+
/**
* Index of the discriminator column in the fixed length flat file
*/
@@ -51,107 +52,93 @@
private int[] fixedColumnLengths;
/**
- * Column lengths for discriminator values. Key is discriminator value.
+ * Column lengths for discriminator values. Key is discriminator value.
* Value is int[] for column lengths
*/
private Map variableColumnLengths;
// Implementation methods
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
public String[] extractColumns(String lineText) {
- String[] result = new String[maximumColumnCount];
-
- int curIndex = 0;
-
- for (int i = 0; i <= lastFixedContentIndex; i++) {
- try {
- result[i] = lineText.substring(curIndex, curIndex
- + this.fixedColumnLengths[i]);
-
- curIndex += this.fixedColumnLengths[i];
-
- } catch (StringIndexOutOfBoundsException e) {
- return result;
- }
- }
-
- if (result.length > this.discriminatorIndex) {
- String discriminatorValue = result[this.discriminatorIndex];
- if (StringUtils.isNotBlank(discriminatorValue)
- && (this.variableColumnLengths != null)
- && (this.variableColumnLengths
- .containsKey(discriminatorValue))) {
- int[] variableLengths = (int[]) this.variableColumnLengths
- .get(discriminatorValue);
-
- int variableIndex = 0;
- for (int i = lastFixedContentIndex + 1; i < maximumColumnCount; i++, variableIndex++) {
- try {
- if (variableLengths[variableIndex] != -1) {
- result[i] = lineText.substring(curIndex, curIndex
- + variableLengths[variableIndex]);
-
- curIndex += variableLengths[variableIndex];
- }
- } catch (StringIndexOutOfBoundsException e) {
- break;
- }
- }
- }
- } else
- throw new IllegalStateException(
- "Discriminator Column could not be read");
-
- return result;
+ String[] result = new String[maximumColumnCount];
+ int curIndex = 0;
+ for (int i = 0; i <= lastFixedContentIndex; i++) {
+ try {
+ result[i] = lineText.substring(curIndex, curIndex + this.fixedColumnLengths[i]);
+ curIndex += this.fixedColumnLengths[i];
+ } catch (StringIndexOutOfBoundsException e) {
+ return result;
+ }
+ }
+ if (result.length > this.discriminatorIndex) {
+ String discriminatorValue = result[this.discriminatorIndex];
+ if (StringUtils.isNotBlank(discriminatorValue) && (this.variableColumnLengths != null)
+ && (this.variableColumnLengths.containsKey(discriminatorValue))) {
+ int[] variableLengths = (int[]) this.variableColumnLengths.get(discriminatorValue);
+
+ int variableIndex = 0;
+ for (int i = lastFixedContentIndex + 1; i < maximumColumnCount; i++, variableIndex++) {
+ try {
+ if (variableLengths[variableIndex] != -1) {
+ result[i] = lineText.substring(curIndex, curIndex + variableLengths[variableIndex]);
+
+ curIndex += variableLengths[variableIndex];
+ }
+ } catch (StringIndexOutOfBoundsException e) {
+ break;
+ }
+ }
+ }
+ } else {
+ throw new IllegalStateException("Discriminator Column could not be read");
+ }
+ return result;
}
// Properties
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
public final void setFixedColumnLengths(int[] fixedColumnLengths) {
- this.fixedColumnLengths = fixedColumnLengths;
+ this.fixedColumnLengths = fixedColumnLengths;
}
- public final void setStringFixedColumnLengths(String[] fixedColumnLengths) {
- this.fixedColumnLengths = new int[fixedColumnLengths.length];
-
- for (int i = 0; i < fixedColumnLengths.length; i++)
- this.fixedColumnLengths[i] = Integer
- .parseInt(fixedColumnLengths[i]);
+ public final void setStringFixedColumnLengths(String[] lengths) {
+ this.fixedColumnLengths = new int[lengths.length];
+ for (int i = 0; i < lengths.length; i++) {
+ this.fixedColumnLengths[i] = Integer.parseInt(lengths[i]);
+ }
}
public final void setMaximumColumnCount(int maximumColumnCount) {
- this.maximumColumnCount = maximumColumnCount;
+ this.maximumColumnCount = maximumColumnCount;
}
public final void setDiscriminatorIndex(int discriminatorIndex) {
- this.discriminatorIndex = discriminatorIndex;
+ this.discriminatorIndex = discriminatorIndex;
}
public final void setLastFixedContentIndex(int lastFixedContentIndex) {
- this.lastFixedContentIndex = lastFixedContentIndex;
+ this.lastFixedContentIndex = lastFixedContentIndex;
}
public final void setVariableColumnLengths(Map variableColumnLengths) {
- this.variableColumnLengths = variableColumnLengths;
+ this.variableColumnLengths = variableColumnLengths;
}
- public final void setStringEncodedVariableColumnLengths(
- String variableColumnLengths) {
- this.variableColumnLengths = null;
-
- String[] entries = StringUtils.split(variableColumnLengths, ";");
- if ((entries != null) && (entries.length > 0)) {
- this.variableColumnLengths = new LinkedHashMap();
- for (int i = 0; i < entries.length; i++) {
- String[] colLengths = StringUtils.splitPreserveAllTokens(
- entries[i], ",");
- if ((colLengths != null) && (colLengths.length > 1)) {
- int[] lengths = new int[colLengths.length - 1];
- for (int j = 1; j < colLengths.length; j++)
- lengths[j - 1] = Integer.parseInt(colLengths[j]);
- this.variableColumnLengths.put(colLengths[0], lengths);
- }
- }
- }
+ public final void setStringEncodedVariableColumnLengths(String columnLengths) {
+ this.variableColumnLengths = null;
+ String[] entries = StringUtils.split(columnLengths, ";");
+ if ((entries != null) && (entries.length > 0)) {
+ this.variableColumnLengths = new LinkedHashMap();
+ for (int i = 0; i < entries.length; i++) {
+ String[] colLengths = StringUtils.splitPreserveAllTokens(entries[i], ",");
+ if ((colLengths != null) && (colLengths.length > 1)) {
+ int[] lengths = new int[colLengths.length - 1];
+ for (int j = 1; j < colLengths.length; j++) {
+ lengths[j - 1] = Integer.parseInt(colLengths[j]);
+ }
+ this.variableColumnLengths.put(colLengths[0], lengths);
+ }
+ }
+ }
}
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/xstream/XStreamMarshaler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/xstream/XStreamMarshaler.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/xstream/XStreamMarshaler.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/xstream/XStreamMarshaler.java Thu Aug 9 13:33:26 2007
@@ -26,16 +26,16 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
-import org.apache.servicemix.jbi.jaxp.SourceTransformer;
-import org.apache.servicemix.jbi.jaxp.StringSource;
-import org.apache.servicemix.jbi.messaging.DefaultMarshaler;
-import org.apache.servicemix.jbi.messaging.PojoMarshaler;
import org.w3c.dom.Document;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomReader;
import com.thoughtworks.xstream.io.xml.DomWriter;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.messaging.DefaultMarshaler;
+
/**
* A {@link PojoMarshaler} for <a href="http://xStream.codehaus.org/">XStream</a> which
* streams the object to an a W3C DOM Document so that other components can access
@@ -45,8 +45,10 @@
*/
public class XStreamMarshaler extends DefaultMarshaler {
private XStream xStream;
+
private SourceTransformer transformer = new SourceTransformer();
- private boolean useDOM = false;
+
+ private boolean useDOM;
public void marshal(MessageExchange exchange, NormalizedMessage message, Object body) throws MessagingException {
if (useDOM) {
@@ -54,12 +56,10 @@
Document document = transformer.createDocument();
getXStream().marshal(body, new DomWriter(document));
message.setContent(new DOMSource(document));
- }
- catch (ParserConfigurationException e) {
+ } catch (ParserConfigurationException e) {
throw new MessagingException("Failed to marshal: " + body + " to DOM document: " + e, e);
}
- }
- else {
+ } else {
String xml = getXStream().toXML(body);
message.setContent(new StringSource(xml));
}
@@ -76,13 +76,11 @@
if (content instanceof DOMSource) {
DOMSource domSource = (DOMSource) content;
document = (Document) domSource.getNode();
- }
- else {
+ } else {
DOMResult result = new DOMResult();
try {
transformer.toResult(content, result);
- }
- catch (TransformerException e) {
+ } catch (TransformerException e) {
throw new MessagingException("Failed to transform content: " + content + " to DOMResult: " + e, e);
}
document = (Document) result.getNode();
@@ -136,9 +134,9 @@
protected XStream createXStream() {
XStream answer = new XStream();
try {
- answer.alias("invoke", Class.forName("org.logicblaze.lingo.LingoInvocation"));
+ answer.alias("invoke", Class.forName("org.logicblaze.lingo.LingoInvocation"));
} catch (ClassNotFoundException e) {
- // Ignore
+ // Ignore
}
return answer;
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/xstream/XStreamSource.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/xstream/XStreamSource.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/xstream/XStreamSource.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/util/xstream/XStreamSource.java Thu Aug 9 13:33:26 2007
@@ -51,8 +51,8 @@
setSource(object);
}
- public void setSource(Object object) {
- super.setSource(object);
- this.object = object;
+ public void setSource(Object source) {
+ super.setSource(source);
+ this.object = source;
}
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/ScheduleIterator.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/ScheduleIterator.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/ScheduleIterator.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/ScheduleIterator.java Thu Aug 9 13:33:26 2007
@@ -19,16 +19,17 @@
import java.util.Date;
/**
- * Iterator for scheduling.
+ * Iterator for scheduling.
+ *
* @author george
- *
+ *
*/
public interface ScheduleIterator {
- /**
- * Next execution date of associated task.
- * Implementations should return null to cancel running task.
- *
- * @return next date of Execution
- */
- Date nextExecution();
+ /**
+ * Next execution date of associated task. Implementations should return
+ * null to cancel running task.
+ *
+ * @return next date of Execution
+ */
+ Date nextExecution();
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/Scheduler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/Scheduler.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/Scheduler.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/Scheduler.java Thu Aug 9 13:33:26 2007
@@ -25,90 +25,94 @@
* <p>
* This class is thread-safe
* <p>
- *
+ *
* @author George Gastaldi (gastaldi)
*/
public class Scheduler {
- private Timer timer;
+ private Timer timer;
- /**
- * Creates a new Scheduler.
- */
- public Scheduler() {
- this.timer = new Timer();
- }
-
- /**
- * Creates a new Daemon Scheduler
- * @param daemon Thread must be executed as "daemon".
- */
- public Scheduler(boolean daemon) {
- this.timer = new Timer(daemon);
- }
-
- /**
- * Cancels the scheduler task
- */
- public void cancel() {
- timer.cancel();
- }
-
- /**
- * Schedules a task
- *
- * @param task scheduled tasl
- * @param iterator iterator for schedulingque descreve o agendamento
- * @throws IllegalStateException if task scheduled or canceled
- */
- public void schedule(SchedulerTask task, ScheduleIterator iterator) {
- Date time = iterator.nextExecution();
- if (time == null) {
- task.cancel();
- } else {
- synchronized (task.lock) {
- if (task.state != SchedulerTask.VIRGIN) {
- throw new IllegalStateException(
- "Task already scheduled or cancelled");
- }
- task.state = SchedulerTask.SCHEDULED;
- task.timerTask = new SchedulerTimerTask(task, iterator);
- timer.schedule(task.timerTask, time);
- }
- }
- }
-
- private void reschedule(SchedulerTask task, ScheduleIterator iterator) {
- Date time = iterator.nextExecution();
- if (time == null) {
- task.cancel();
- } else {
- synchronized (task.lock) {
- if (task.state != SchedulerTask.CANCELLED) {
- task.timerTask = new SchedulerTimerTask(task, iterator);
- timer.schedule(task.timerTask, time);
- }
- }
- }
- }
-
- /**
- * Internal TimerTask instance
- */
- class SchedulerTimerTask extends TimerTask {
- private SchedulerTask task;
- private ScheduleIterator iterator;
-
- public SchedulerTimerTask(SchedulerTask task,ScheduleIterator iterator){
- this.task = task;
- this.iterator = iterator;
- }
-
- public void run() {
- task.run();
- reschedule(task, iterator);
- }
- }
+ /**
+ * Creates a new Scheduler.
+ */
+ public Scheduler() {
+ this.timer = new Timer();
+ }
+
+ /**
+ * Creates a new Daemon Scheduler
+ *
+ * @param daemon
+ * Thread must be executed as "daemon".
+ */
+ public Scheduler(boolean daemon) {
+ this.timer = new Timer(daemon);
+ }
+
+ /**
+ * Cancels the scheduler task
+ */
+ public void cancel() {
+ timer.cancel();
+ }
+
+ /**
+ * Schedules a task
+ *
+ * @param task
+ * scheduled tasl
+ * @param iterator
+ * iterator for schedulingque descreve o agendamento
+ * @throws IllegalStateException
+ * if task scheduled or canceled
+ */
+ public void schedule(SchedulerTask task, ScheduleIterator iterator) {
+ Date time = iterator.nextExecution();
+ if (time == null) {
+ task.cancel();
+ } else {
+ synchronized (task.lock) {
+ if (task.state != SchedulerTask.VIRGIN) {
+ throw new IllegalStateException("Task already scheduled or cancelled");
+ }
+ task.state = SchedulerTask.SCHEDULED;
+ task.timerTask = new SchedulerTimerTask(task, iterator);
+ timer.schedule(task.timerTask, time);
+ }
+ }
+ }
+
+ private void reschedule(SchedulerTask task, ScheduleIterator iterator) {
+ Date time = iterator.nextExecution();
+ if (time == null) {
+ task.cancel();
+ } else {
+ synchronized (task.lock) {
+ if (task.state != SchedulerTask.CANCELLED) {
+ task.timerTask = new SchedulerTimerTask(task, iterator);
+ timer.schedule(task.timerTask, time);
+ }
+ }
+ }
+ }
+
+ /**
+ * Internal TimerTask instance
+ */
+ class SchedulerTimerTask extends TimerTask {
+ private SchedulerTask task;
+
+ private ScheduleIterator iterator;
+
+ public SchedulerTimerTask(SchedulerTask task, ScheduleIterator iterator) {
+ this.task = task;
+ this.iterator = iterator;
+ }
+
+ public void run() {
+ task.run();
+ reschedule(task, iterator);
+ }
+ }
}
-
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/SchedulerTask.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/SchedulerTask.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/SchedulerTask.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/SchedulerTask.java Thu Aug 9 13:33:26 2007
@@ -16,48 +16,52 @@
*/
package org.apache.servicemix.components.varscheduler;
-import java.util.*;
+import java.util.TimerTask;
/**
* A task run by a {@link Scheduler}.
*
- * @author George Gastaldi (gastaldi)
+ * @author George Gastaldi (gastaldi)
*/
public abstract class SchedulerTask implements Runnable {
- static final int VIRGIN = 0;
- static final int SCHEDULED = 1;
- static final int CANCELLED = 2;
-
- final Object lock = new Object();
- int state = VIRGIN;
- TimerTask timerTask;
-
- protected SchedulerTask() {
- }
-
- public abstract void run();
-
- /**
- * Cancels task.
- * @return true if task already scheduled
- */
- public boolean cancel() {
- synchronized (lock) {
- if (timerTask != null) {
- timerTask.cancel();
- }
- boolean result = (state == SCHEDULED);
- state = CANCELLED;
- return result;
- }
- }
-
- public long scheduledExecutionTime() {
- synchronized (lock) {
- return timerTask == null ? 0 : timerTask.scheduledExecutionTime();
- }
- }
+ static final int VIRGIN = 0;
-}
+ static final int SCHEDULED = 1;
+
+ static final int CANCELLED = 2;
+
+ final Object lock = new Object();
+ int state = VIRGIN;
+
+ TimerTask timerTask;
+
+ protected SchedulerTask() {
+ }
+
+ public abstract void run();
+
+ /**
+ * Cancels task.
+ *
+ * @return true if task already scheduled
+ */
+ public boolean cancel() {
+ synchronized (lock) {
+ if (timerTask != null) {
+ timerTask.cancel();
+ }
+ boolean result = state == SCHEDULED;
+ state = CANCELLED;
+ return result;
+ }
+ }
+
+ public long scheduledExecutionTime() {
+ synchronized (lock) {
+ return timerTask == null ? 0 : timerTask.scheduledExecutionTime();
+ }
+ }
+
+}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/Expression.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/Expression.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/Expression.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/Expression.java Thu Aug 9 13:33:26 2007
@@ -34,5 +34,5 @@
* @param message the message, typically an inbound message
* @return the value of the expression
*/
- public Object evaluate(MessageExchange exchange, NormalizedMessage message) throws MessagingException ;
+ Object evaluate(MessageExchange exchange, NormalizedMessage message) throws MessagingException;
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/ExpressionHelper.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/ExpressionHelper.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/ExpressionHelper.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/ExpressionHelper.java Thu Aug 9 13:33:26 2007
@@ -25,7 +25,10 @@
*
* @version $Revision$
*/
-public class ExpressionHelper {
+public final class ExpressionHelper {
+
+ private ExpressionHelper() {
+ }
/**
* Evaluates the given expression as a string value.
@@ -37,7 +40,8 @@
* @return the value of the expression as a string if it is not null or the defaultValue
* @throws MessagingException if the expression failed to be evaluated
*/
- public static String asString(Expression expression, MessageExchange exchange, NormalizedMessage message, String defaultValue) throws MessagingException {
+ public static String asString(Expression expression, MessageExchange exchange,
+ NormalizedMessage message, String defaultValue) throws MessagingException {
if (expression != null) {
Object answer = expression.evaluate(exchange, message);
if (answer != null) {
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPBooleanXPathExpression.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPBooleanXPathExpression.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPBooleanXPathExpression.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPBooleanXPathExpression.java Thu Aug 9 13:33:26 2007
@@ -21,9 +21,9 @@
/**
* Evaluates an XPath expression and coerces the result into a String.
- *
+ *
* @org.apache.xbean.XBean element="xpathBoolean"
- *
+ *
* @version $Revision: 359151 $
*/
public class JAXPBooleanXPathExpression extends JAXPXPathExpression {
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPNodeSetXPathExpression.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPNodeSetXPathExpression.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPNodeSetXPathExpression.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPNodeSetXPathExpression.java Thu Aug 9 13:33:26 2007
@@ -21,7 +21,7 @@
/**
* Evaluates an XPath expression and coerces the result into a String.
- *
+ *
* @version $Revision: 359151 $
*/
public class JAXPNodeSetXPathExpression extends JAXPXPathExpression {
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPStringXPathExpression.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPStringXPathExpression.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPStringXPathExpression.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPStringXPathExpression.java Thu Aug 9 13:33:26 2007
@@ -21,9 +21,9 @@
/**
* Evaluates an XPath expression and coerces the result into a String.
- *
+ *
* @org.apache.xbean.XBean element="xpathString"
- *
+ *
* @version $Revision$
*/
public class JAXPStringXPathExpression extends JAXPXPathExpression {
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPXPathExpression.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPXPathExpression.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPXPathExpression.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JAXPXPathExpression.java Thu Aug 9 13:33:26 2007
@@ -16,11 +16,7 @@
*/
package org.apache.servicemix.expression;
-import org.apache.servicemix.jbi.jaxp.SourceTransformer;
-import org.apache.servicemix.jbi.jaxp.StringSource;
-import org.apache.servicemix.jbi.util.MessageUtil;
-import org.springframework.beans.factory.InitializingBean;
-import org.xml.sax.SAXException;
+import java.io.IOException;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
@@ -34,30 +30,42 @@
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFunctionResolver;
-import java.io.IOException;
+import org.xml.sax.SAXException;
+
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.util.MessageUtil;
+import org.springframework.beans.factory.InitializingBean;
/**
* Evalutes an XPath expression on the given message using JAXP
- *
+ *
* @org.apache.xbean.XBean element="xpath"
- *
+ *
* @version $Revision$
*/
public class JAXPXPathExpression implements Expression, InitializingBean {
+
private String xpath;
+
private boolean useMessageContent = true;
+
private SourceTransformer transformer = new SourceTransformer();
+
private MessageVariableResolver variableResolver = new MessageVariableResolver();
+
private XPathExpression xPathExpression;
+
private XPathFunctionResolver functionResolver;
+
private NamespaceContext namespaceContext;
+
private XPathFactory factory;
public JAXPXPathExpression() {
}
/**
- * A helper constructor to make a fully created expression.
+ * A helper constructor to make a fully created expression.
*/
public JAXPXPathExpression(String xpath) {
this.xpath = xpath;
@@ -100,45 +108,43 @@
variableResolver.setMessage(message);
return evaluateXPath(object);
}
- }
- catch (TransformerException e) {
+ } catch (TransformerException e) {
throw new MessagingException(e);
- }
- catch (XPathExpressionException e) {
+ } catch (XPathExpressionException e) {
throw new MessagingException(e);
- }
- catch (ParserConfigurationException e) {
+ } catch (ParserConfigurationException e) {
throw new MessagingException(e);
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new MessagingException(e);
- }
- catch (SAXException e) {
+ } catch (SAXException e) {
throw new MessagingException(e);
}
}
// Properties
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
public String getXPath() {
return xpath;
}
- public void setXPath(String xpath) {
- this.xpath = xpath;
+ public void setXPath(String xp) {
+ this.xpath = xp;
}
-
+
public boolean isUseMessageContent() {
return useMessageContent;
}
-
+
/**
- * Specifies whether or not the XPath expression uses the message content.
+ * Specifies whether or not the XPath expression uses the message content.
*
- * By default, this property is <code>true</code>, but you can set it to <code>false</code> to avoid that the message content
- * is converted to {@link StringSource}
+ * By default, this property is <code>true</code>, but you can set it to
+ * <code>false</code> to avoid that the message content is converted to
+ * {@link StringSource}
*
- * @param useMessageContent specify <code>false</code> if this expression does not access the message content
+ * @param useMessageContent
+ * specify <code>false</code> if this expression does not
+ * access the message content
*/
public void setUseMessageContent(boolean useMessageContent) {
this.useMessageContent = useMessageContent;
@@ -185,7 +191,7 @@
}
// Implementation methods
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
protected Object evaluateXPath(Object object) throws XPathExpressionException {
return xPathExpression.evaluate(object);
}
@@ -194,8 +200,10 @@
return xPathExpression;
}
- protected Object getXMLNode(MessageExchange exchange, NormalizedMessage message) throws TransformerException, MessagingException, ParserConfigurationException, IOException, SAXException {
- //ensure re-readability of the content if the expression also needs to access the content
+ protected Object getXMLNode(MessageExchange exchange, NormalizedMessage message) throws TransformerException, MessagingException,
+ ParserConfigurationException, IOException, SAXException {
+ // ensure re-readability of the content if the expression also needs to
+ // access the content
if (useMessageContent) {
MessageUtil.enableContentRereadability(message);
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JaxenVariableContext.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JaxenVariableContext.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JaxenVariableContext.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JaxenVariableContext.java Thu Aug 9 13:33:26 2007
@@ -16,14 +16,14 @@
*/
package org.apache.servicemix.expression;
-import org.jaxen.UnresolvableException;
-import org.jaxen.VariableContext;
+import java.util.HashMap;
+import java.util.Map;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.NormalizedMessage;
-import java.util.HashMap;
-import java.util.Map;
+import org.jaxen.UnresolvableException;
+import org.jaxen.VariableContext;
/**
* A variable resolver for XPath expressions which support properties on the messge, exchange as well
@@ -33,12 +33,17 @@
*/
public class JaxenVariableContext implements VariableContext {
public static final String MESSAGE_NAMESPACE = "http://servicemix.org/xml/variables/message";
+
public static final String EXCHANGE_NAMESPACE = "http://servicemix.org/xml/variables/exchange";
+
public static final String SYSTEM_PROPERTIES_NAMESPACE = "http://servicemix.org/xml/variables/system-properties";
+
public static final String ENVIRONMENT_VARIABLES_NAMESPACE = "http://servicemix.org/xml/variables/environment-variables";
private MessageExchange exchange;
+
private NormalizedMessage message;
+
private Map variables;
public MessageExchange getExchange() {
@@ -78,17 +83,13 @@
if (answer == null) {
answer = exchange.getProperty(localPart);
}
- }
- else if (uri.equals(MESSAGE_NAMESPACE)) {
+ } else if (uri.equals(MESSAGE_NAMESPACE)) {
answer = message.getProperty(localPart);
- }
- else if (uri.equals(EXCHANGE_NAMESPACE)) {
+ } else if (uri.equals(EXCHANGE_NAMESPACE)) {
answer = message.getProperty(localPart);
- }
- else if (uri.equals(SYSTEM_PROPERTIES_NAMESPACE)) {
+ } else if (uri.equals(SYSTEM_PROPERTIES_NAMESPACE)) {
answer = System.getProperty(localPart);
- }
- else if (uri.equals(ENVIRONMENT_VARIABLES_NAMESPACE)) {
+ } else if (uri.equals(ENVIRONMENT_VARIABLES_NAMESPACE)) {
answer = System.getProperty(System.getProperty(localPart));
}
return answer;
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JaxenXPathExpression.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JaxenXPathExpression.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JaxenXPathExpression.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/JaxenXPathExpression.java Thu Aug 9 13:33:26 2007
@@ -16,10 +16,21 @@
*/
package org.apache.servicemix.expression;
+import java.io.IOException;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import org.w3c.dom.Node;
+
+import org.xml.sax.SAXException;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
-import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.util.MessageUtil;
import org.jaxen.FunctionContext;
import org.jaxen.JaxenException;
@@ -27,40 +38,38 @@
import org.jaxen.XPath;
import org.jaxen.dom.DOMXPath;
import org.springframework.beans.factory.InitializingBean;
-import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
-
-import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.MessagingException;
-import javax.jbi.messaging.NormalizedMessage;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerException;
-
-import java.io.IOException;
-
/**
- * Evalutes an XPath expression on the given message using <a href="http://jaxen.org/"/>Jaxen</a>
- *
+ * Evalutes an XPath expression on the given message using <a
+ * href="http://jaxen.org/"/>Jaxen</a>
+ *
* @version $Revision$
*/
public class JaxenXPathExpression implements Expression, InitializingBean {
- private static final transient Log log = LogFactory.getLog(JaxenXPathExpression.class);
+ private static final transient Log LOG = LogFactory.getLog(JaxenXPathExpression.class);
+
private String xpath;
+
private boolean useMessageContent = true;
+
private SourceTransformer transformer = new SourceTransformer();
+
private JaxenVariableContext variableContext = new JaxenVariableContext();
+
private XPath xpathObject;
+
private NamespaceContext namespaceContext;
+
private FunctionContext functionContext;
public JaxenXPathExpression() {
}
/**
- * A helper constructor to make a fully created expression. This constructor will
- * call the {@link #afterPropertiesSet()} method to ensure this POJO is properly constructed.
+ * A helper constructor to make a fully created expression. This constructor
+ * will call the {@link #afterPropertiesSet()} method to ensure this POJO is
+ * properly constructed.
*/
public JaxenXPathExpression(String xpath) throws Exception {
this.xpath = xpath;
@@ -94,20 +103,15 @@
variableContext.setMessage(message);
return evaluateXPath(object);
}
- }
- catch (TransformerException e) {
+ } catch (TransformerException e) {
throw new MessagingException(e);
- }
- catch (JaxenException e) {
+ } catch (JaxenException e) {
throw new MessagingException(e);
- }
- catch (ParserConfigurationException e) {
+ } catch (ParserConfigurationException e) {
throw new MessagingException(e);
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new MessagingException(e);
- }
- catch (SAXException e) {
+ } catch (SAXException e) {
throw new MessagingException(e);
}
}
@@ -123,26 +127,21 @@
variableContext.setMessage(message);
return evaluateXPathAsBoolean(object);
}
- }
- catch (TransformerException e) {
+ } catch (TransformerException e) {
throw new MessagingException(e);
- }
- catch (JaxenException e) {
+ } catch (JaxenException e) {
throw new MessagingException(e);
- }
- catch (ParserConfigurationException e) {
+ } catch (ParserConfigurationException e) {
throw new MessagingException(e);
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new MessagingException(e);
- }
- catch (SAXException e) {
+ } catch (SAXException e) {
throw new MessagingException(e);
}
}
// Properties
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
public XPath getXpathObject() {
return xpathObject;
}
@@ -164,12 +163,15 @@
}
/**
- * Specifies whether or not the XPath expression uses the message content.
+ * Specifies whether or not the XPath expression uses the message content.
*
- * By default, this property is <code>true</code>, but you can set it to <code>false</code> to avoid that the message content
- * is converted to {@link StringSource}
+ * By default, this property is <code>true</code>, but you can set it to
+ * <code>false</code> to avoid that the message content is converted to
+ * {@link StringSource}
*
- * @param useMessageContent specify <code>false</code> if this expression does not access the message content
+ * @param useMessageContent
+ * specify <code>false</code> if this expression does not
+ * access the message content
*/
public void setUseMessageContent(boolean useMessageContent) {
this.useMessageContent = useMessageContent;
@@ -208,9 +210,9 @@
}
// Implementation methods
- //-------------------------------------------------------------------------
- protected XPath createXPath(String xpath) throws JaxenException {
- return new DOMXPath(xpath);
+ // -------------------------------------------------------------------------
+ protected XPath createXPath(String xp) throws JaxenException {
+ return new DOMXPath(xp);
}
protected Object evaluateXPath(Object object) throws JaxenException {
@@ -221,21 +223,22 @@
return xpathObject.booleanValueOf(object);
}
-
- protected Object getXMLNode(MessageExchange exchange, NormalizedMessage message) throws TransformerException, MessagingException, ParserConfigurationException, IOException, SAXException {
+ protected Object getXMLNode(MessageExchange exchange, NormalizedMessage message) throws TransformerException, MessagingException,
+ ParserConfigurationException, IOException, SAXException {
Node node = null;
- //ensure re-readability of the content if the expression also needs to access the content
+ // ensure re-readability of the content if the expression also needs to
+ // access the content
if (useMessageContent) {
MessageUtil.enableContentRereadability(message);
}
if (message != null) {
node = transformer.toDOMNode(message);
- }
- else {
- log.warn("Null message for exchange: " + exchange);
+ } else {
+ LOG.warn("Null message for exchange: " + exchange);
}
if (node == null) {
- // lets make an empty document to avoid Jaxen throwing a NullPointerException
+ // lets make an empty document to avoid Jaxen throwing a
+ // NullPointerException
node = transformer.createDocument();
}
return node;
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/MessageVariableResolver.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/MessageVariableResolver.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/MessageVariableResolver.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/MessageVariableResolver.java Thu Aug 9 13:33:26 2007
@@ -62,11 +62,9 @@
if (answer == null) {
answer = exchange.getProperty(localPart);
}
- }
- else if (uri.equals(SYSTEM_PROPERTIES_NAMESPACE)) {
+ } else if (uri.equals(SYSTEM_PROPERTIES_NAMESPACE)) {
answer = System.getProperty(localPart);
- }
- else if (uri.equals(ENVIRONMENT_VARIABLES)) {
+ } else if (uri.equals(ENVIRONMENT_VARIABLES)) {
answer = System.getProperty(System.getProperty(localPart));
}
return answer;
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/XMLBeansStringXPathExpression.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/XMLBeansStringXPathExpression.java?view=diff&rev=564374&r1=564373&r2=564374
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/XMLBeansStringXPathExpression.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/expression/XMLBeansStringXPathExpression.java Thu Aug 9 13:33:26 2007
@@ -35,11 +35,9 @@
XmlObject[] xmlObjects = object.selectPath(xpath);
if (xmlObjects == null || xmlObjects.length == 0) {
return "";
- }
- else if (xmlObjects.length == 1) {
+ } else if (xmlObjects.length == 1) {
return asString(xmlObjects[0]);
- }
- else {
+ } else {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < xmlObjects.length; i++) {
XmlObject xmlObject = xmlObjects[i];