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: * $Id: ParserEndpoint.java 1214 2006-09-24 04:32:11Z elu $
022: */
023:
024: package com.bostechcorp.cbesb.runtime.component.transformer;
025:
026: import java.util.ArrayList;
027: import java.util.List;
028:
029: import javax.jbi.messaging.MessageExchange;
030:
031: import com.bostechcorp.cbesb.common.runtime.CbesbException;
032: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
033: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.IComponentProcessor;
034: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.LifeCycleEndpoint;
035: import com.bostechcorp.cbesb.runtime.component.transformer.processors.TransformerProviderProcessor;
036: import com.bostechcorp.cbesb.runtime.transformer.engine.TransformerRuntime;
037: import com.bostechcorp.cbesb.runtime.transformer.engine.TransformerRuntimeFactory;
038:
039: public class TransformerEndpoint extends LifeCycleEndpoint {
040:
041: private String trnFile;
042: // private TransformerRuntime runtime;
043: private TransformerRuntimeFactory runtimeFactory = new TransformerRuntimeFactory();
044:
045: /**
046: * @return the trnFile
047: */
048: public String getTrnFile() {
049: return trnFile;
050: }
051:
052: /**
053: * @param trnFile the trnFile to set
054: */
055: public void setTrnFile(String trnFile) {
056: this .trnFile = trnFile;
057: }
058:
059: public TransformerRuntime getRuntime() throws CbesbException {
060: String className = EsbPathHelper.getTrnClassName(trnFile);
061: String saName = EsbPathHelper.getProjectName(trnFile);
062: return runtimeFactory.newTransformerRuntime(saName, className);
063: }
064:
065: public TransformerRuntime getRuntime(String saName, String className)
066: throws CbesbException {
067: return runtimeFactory.newTransformerRuntime(saName, className);
068: }
069:
070: public void processAsConsumer(MessageExchange exchange)
071: throws Exception {
072:
073: Exception e = new Exception(
074: "Transformer component doesn't support Consumer role ");
075: exchange.setError(e);
076: channel.send(exchange);
077: throw e;
078:
079: }
080:
081: protected IComponentProcessor createProviderProcessor() {
082: return new TransformerProviderProcessor(this );
083: }
084:
085: protected IComponentProcessor createConsumerProcessor() {
086: return null;
087: }
088:
089: /**********************************************************************************
090: * These attributes and methods customize the LifeCycleEndpoint for this component
091: ***********************************************************************************/
092:
093: /*
094: * The display parameters are general information for the admin console to display.
095: */
096: public String[] getDisplayParameterTitles() {
097: return new String[] { TransformerPropertiesEnumeration.TRN_FILE
098: .name() };
099:
100: }
101:
102: /*
103: * The values returned here correspond to the titles above.
104: */
105: public String[] getDisplayParameters() {
106: return new String[] { TransformerPropertiesEnumeration.TRN_FILE
107: .getValue(this ) };
108: }
109:
110: /*
111: * This returns a list of properties that can be read.
112: */
113: public String[] getGetableProperties() {
114: TransformerPropertiesEnumeration[] fps = TransformerPropertiesEnumeration
115: .values();
116: List<String> result = new ArrayList<String>();
117: for (int i = 0; i < fps.length; i++) {
118: result.add(fps[i].name());
119: }
120: String[] sr = new String[result.size()];
121: return result.toArray(sr);
122: }
123:
124: /*
125: * This gets one property from the list above.
126: */
127: public String getProperty(int index) {
128: return TransformerPropertiesEnumeration.values()[index]
129: .getValue(this );
130: }
131:
132: /*
133: * This gets one property from the list above.
134: */
135: public String getProperty(String property) {
136: return TransformerPropertiesEnumeration.valueOf(property)
137: .getValue(this );
138: }
139:
140: /*
141: * This returns a list of properties that can be set.
142: */
143: public String[] getSetableProperties() {
144: TransformerPropertiesEnumeration[] fps = TransformerPropertiesEnumeration
145: .values();
146: List<String> result = new ArrayList<String>();
147: for (int i = 0; i < fps.length; i++) {
148: if (fps[i].isSetable())
149: result.add(fps[i].name());
150: }
151: String[] sr = new String[result.size()];
152: return result.toArray(sr);
153: }
154:
155: /*
156: * This sets one property from the list above.
157: */
158: public void setProperty(int index, String value) {
159: TransformerPropertiesEnumeration.values()[index].setValue(this ,
160: value);
161: }
162:
163: /*
164: * This sets one property from the list above.
165: */
166: public void setProperty(String property, String value) {
167: TransformerPropertiesEnumeration.valueOf(property).setValue(
168: this , value);
169: }
170:
171: /**************************************************
172: * Done with LifeCycleEndpoint methods
173: ***************************************************/
174:
175: }
|