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 20 package org.apache.synapse.mediators.spring; 21 22 import org.apache.axiom.om.OMElement; 23 import org.apache.axiom.om.OMNamespace; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.synapse.Mediator; 27 import org.apache.synapse.config.xml.XMLConfigConstants; 28 import org.apache.synapse.config.xml.MediatorSerializer; 29 import org.apache.synapse.config.xml.AbstractMediatorSerializer; 30 31 /** 32 * <spring bean="exampleBean1" (config="spring1" | src="spring.xml)"/> 33 */ 34 public class SpringMediatorSerializer extends AbstractMediatorSerializer 35 implements MediatorSerializer { 36 37 private static final OMNamespace sprNS = fac.createOMNamespace(XMLConfigConstants.SYNAPSE_NAMESPACE+"/spring", "spring"); 38 39 private static final Log log = LogFactory.getLog(SpringMediatorSerializer.class); 40 41 public OMElement serializeMediator(OMElement parent, Mediator m) { 42 43 if (!(m instanceof SpringMediator)) { 44 handleException("Unsupported mediator passed in for serialization : " + m.getType()); 45 } 46 47 SpringMediator mediator = (SpringMediator) m; 48 OMElement spring = fac.createOMElement("spring", sprNS); 49 50 if (mediator.getBeanName() != null) { 51 spring.addAttribute(fac.createOMAttribute( 52 "bean", nullNS, mediator.getBeanName())); 53 } else { 54 handleException("Invalid mediator. Bean name required."); 55 } 56 saveTracingState(spring,mediator); 57 58 if (mediator.getConfigKey() != null) { 59 spring.addAttribute(fac.createOMAttribute( 60 "key", nullNS, mediator.getConfigKey())); 61 } 62 63 // TODO add support for src attribute - or replace with a reg key! 64 65 if (parent != null) { 66 parent.addChild(spring); 67 } 68 return spring; 69 } 70 71 public String getMediatorClassName() { 72 return SpringMediator.class.getName(); 73 } 74 }