001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: FileProviderProcessor.java 11752 2008-01-30 22:23:29Z mpreston $
023: */
024: package com.bostechcorp.cbesb.runtime.component.file.processors;
025:
026: import java.io.File;
027: import java.util.Iterator;
028:
029: import javax.jbi.JBIException;
030: import javax.jbi.messaging.MessageExchange;
031: import javax.jbi.messaging.NormalizedMessage;
032: import javax.xml.namespace.QName;
033:
034: import com.bostechcorp.cbesb.common.runtime.CbesbException;
035: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.CbProviderProcessor;
036: import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.NormalizedMessageHandler;
037: import com.bostechcorp.cbesb.runtime.component.file.FileEndpoint;
038:
039: /**
040: * The provider processor classes for File component. It mainly handles the processing
041: * of provider endpoint in File component.
042: *
043: * @author elu
044: *
045: */
046: public class FileProviderProcessor extends CbProviderProcessor {
047: private FileEndpoint endpoint;
048: boolean mIsRunning = true;
049: protected FileWriterUtil fileWriterUtil;
050:
051: public FileProviderProcessor(FileEndpoint endpoint) {
052: super (endpoint);
053: this .endpoint = endpoint;
054: File rootPath = new File(endpoint.getServiceUnit()
055: .getRootPath());
056: fileWriterUtil = new FileWriterUtil();
057: fileWriterUtil.setCounterFile(new File(rootPath, endpoint
058: .getEndpoint()
059: + ".cnt"));
060: fileWriterUtil.setStageDir(endpoint.getStageDir());
061: fileWriterUtil.setDefaultDestDir(endpoint.getDestDir());
062: fileWriterUtil.setDefaultFilePattern(endpoint.getFilePattern());
063: fileWriterUtil.setDefaultWriteStyle(endpoint.getWriteStyle());
064: fileWriterUtil.setDefaultCharset(endpoint.getCharset());
065:
066: }
067:
068: /**
069: *
070: */
071: public void processInMessage(QName service, QName operation,
072: NormalizedMessage in, MessageExchange exchange)
073: throws JBIException, CbesbException {
074:
075: fileWriterUtil.writeMessageToFile(in, exchange);
076:
077: }
078:
079: /**
080: *
081: */
082: public boolean processInOutMessage(QName service, QName operation,
083: NormalizedMessage in, NormalizedMessage out,
084: boolean optionalOut, MessageExchange exchange)
085: throws JBIException, CbesbException {
086:
087: fileWriterUtil.writeMessageToFile(in, exchange);
088: copyMessageContent(in, out);
089:
090: return true;
091: }
092:
093: protected void copyMessageContent(NormalizedMessage src,
094: NormalizedMessage target) throws JBIException,
095: CbesbException {
096: //Copy message content and attachments
097: NormalizedMessageHandler nmhSrc = new NormalizedMessageHandler(
098: src);
099: NormalizedMessageHandler nmhDest = nmhSrc.copy(target,
100: getProviderSvcDescHandlerInstance());
101: nmhDest.generateMessageContent();
102:
103: //Copy message properties
104: for (Iterator iter = src.getPropertyNames().iterator(); iter
105: .hasNext();) {
106: String propName = (String) iter.next();
107: Object prop = src.getProperty(propName);
108: target.setProperty(propName, prop);
109: }
110: }
111: }
|