Home » synapse-1.2-src » org.apache.synapse.mediators.bsf » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
   10    *   http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing,
   13    *  software distributed under the License is distributed on an
   14    *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    *  KIND, either express or implied.  See the License for the
   16    *  specific language governing permissions and limitations
   17    *  under the License.
   18    */
   19   package org.apache.synapse.mediators.bsf;
   20   
   21   import java.util.Iterator;
   22   import java.util.Map;
   23   
   24   import javax.xml.stream.XMLStreamConstants;
   25   
   26   import org.apache.axiom.om.OMElement;
   27   import org.apache.axiom.om.impl.llom.OMTextImpl;
   28   import org.apache.commons.logging.Log;
   29   import org.apache.commons.logging.LogFactory;
   30   import org.apache.synapse.Mediator;
   31   import org.apache.synapse.config.xml.AbstractMediatorSerializer;
   32   
   33   /**
   34    * Serializer for a script mediator
   35    * @see org.apache.synapse.mediators.bsf.ScriptMediatorFactory
   36    */
   37   public class ScriptMediatorSerializer extends AbstractMediatorSerializer {
   38   
   39       private static final Log log = LogFactory.getLog(ScriptMediatorSerializer.class);
   40   
   41       public OMElement serializeMediator(OMElement parent, Mediator m) {
   42           if (!(m instanceof ScriptMediator) ) {
   43               handleException("Unsupported mediator passed in for serialization : " + m.getType());
   44           }
   45   
   46           ScriptMediator scriptMediator = (ScriptMediator) m;
   47           OMElement script = fac.createOMElement("script", synNS);
   48   
   49           String language = scriptMediator.getLanguage();
   50           String key = scriptMediator.getKey();
   51           String function = scriptMediator.getFunction();
   52   
   53           if (key != null) {
   54               script.addAttribute(fac.createOMAttribute("language", nullNS, language));
   55               script.addAttribute(fac.createOMAttribute("key", nullNS, key));
   56               if (!function.equals("mediate")) {
   57                   script.addAttribute(fac.createOMAttribute("function", nullNS, function));
   58               }
   59           } else {
   60               script.addAttribute(fac.createOMAttribute("language", nullNS, language));
   61               OMTextImpl textData = (OMTextImpl) fac.createOMText(scriptMediator.getScriptSrc().trim());
   62               textData.setType(XMLStreamConstants.CDATA);
   63               script.addChild(textData);
   64           }
   65           
   66           Map includeMap = scriptMediator.getIncludeMap();
   67           Iterator iterIncludeMap = includeMap.keySet().iterator();
   68           while(iterIncludeMap.hasNext()) {
   69             String includeKey = (String) iterIncludeMap.next();
   70             OMElement includeKeyElement = fac.createOMElement("include", synNS);
   71             includeKeyElement.addAttribute(fac.createOMAttribute("key", nullNS, includeKey));
   72             script.addChild(includeKeyElement);
   73           }
   74   
   75           saveTracingState(script, scriptMediator);
   76           if (parent != null) {
   77               parent.addChild(script);
   78           }
   79           return script;
   80       }
   81   
   82       public String getMediatorClassName() {
   83           return ScriptMediator.class.getName();
   84       }
   85   }

Home » synapse-1.2-src » org.apache.synapse.mediators.bsf » [javadoc | source]