001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.synapse.config.xml;
021:
022: import org.apache.axiom.om.OMElement;
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.apache.synapse.Mediator;
026: import org.apache.synapse.mediators.base.SequenceMediator;
027:
028: /**
029: * <pre>
030: * <sequence name="string" [onError="string"]>
031: * mediator+
032: * </sequence>
033: * </pre>
034: * <p/>
035: * OR
036: * <p/>
037: * <pre>
038: * <sequence key="name"/>
039: * </pre>
040: */
041: public class SequenceMediatorSerializer extends
042: AbstractListMediatorSerializer {
043:
044: public OMElement serializeAnonymousSequence(OMElement parent,
045: SequenceMediator mediator) {
046: OMElement sequence = fac.createOMElement("sequence", synNS);
047: int isEnableStatistics = mediator.getStatisticsState();
048: String statisticsValue = null;
049: if (isEnableStatistics == org.apache.synapse.SynapseConstants.STATISTICS_ON) {
050: statisticsValue = XMLConfigConstants.STATISTICS_ENABLE;
051: } else if (isEnableStatistics == org.apache.synapse.SynapseConstants.STATISTICS_OFF) {
052: statisticsValue = XMLConfigConstants.STATISTICS_DISABLE;
053: }
054: if (statisticsValue != null) {
055: sequence.addAttribute(fac.createOMAttribute(
056: XMLConfigConstants.STATISTICS_ATTRIB_NAME, nullNS,
057: statisticsValue));
058: }
059: if (mediator.getErrorHandler() != null) {
060: sequence.addAttribute(fac.createOMAttribute("onError",
061: nullNS, mediator.getErrorHandler()));
062: }
063: saveTracingState(sequence, mediator);
064: serializeChildren(sequence, mediator.getList());
065: if (parent != null) {
066: parent.addChild(sequence);
067: }
068: return sequence;
069: }
070:
071: public OMElement serializeMediator(OMElement parent, Mediator m) {
072:
073: if (!(m instanceof SequenceMediator)) {
074: handleException("Unsupported mediator passed in for serialization : "
075: + m.getType());
076: }
077:
078: SequenceMediator mediator = (SequenceMediator) m;
079: OMElement sequence = fac.createOMElement("sequence", synNS);
080:
081: // is this a dynamic sequence we loaded from a registry? if so we have no work to here
082: // except make sure that we refer back to the registry key used when we loaded ourself
083: if (mediator.isDynamic()) {
084: sequence.addAttribute(fac.createOMAttribute("name", nullNS,
085: mediator.getName()));
086: sequence.addAttribute(fac.createOMAttribute("key", nullNS,
087: mediator.getRegistryKey()));
088:
089: } else {
090:
091: int isEnableStatistics = mediator.getStatisticsState();
092: String statisticsValue = null;
093: if (isEnableStatistics == org.apache.synapse.SynapseConstants.STATISTICS_ON) {
094: statisticsValue = XMLConfigConstants.STATISTICS_ENABLE;
095: } else if (isEnableStatistics == org.apache.synapse.SynapseConstants.STATISTICS_OFF) {
096: statisticsValue = XMLConfigConstants.STATISTICS_DISABLE;
097: }
098: if (statisticsValue != null) {
099: sequence.addAttribute(fac.createOMAttribute(
100: XMLConfigConstants.STATISTICS_ATTRIB_NAME,
101: nullNS, statisticsValue));
102: }
103:
104: if (mediator.getKey() != null) {
105: sequence.addAttribute(fac.createOMAttribute("key",
106: nullNS, mediator.getKey()));
107: } else if (mediator.getName() != null) {
108: sequence.addAttribute(fac.createOMAttribute("name",
109: nullNS, mediator.getName()));
110:
111: if (mediator.getErrorHandler() != null) {
112: sequence.addAttribute(fac.createOMAttribute(
113: "onError", nullNS, mediator
114: .getErrorHandler()));
115: }
116: saveTracingState(sequence, mediator);
117: serializeChildren(sequence, mediator.getList());
118: }
119: }
120:
121: if (parent != null) {
122: parent.addChild(sequence);
123: }
124: return sequence;
125: }
126:
127: public String getMediatorClassName() {
128: return SequenceMediator.class.getName();
129: }
130: }
|