1 /* 2 * $Id: EndpointRefParser.java 19191 2010-08-25 21:05:23Z tcarlson $ 3 * -------------------------------------------------------------------------------------- 4 * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com 5 * 6 * The software in this package is published under the terms of the CPAL v1.0 7 * license, a copy of which has been included with this distribution in the 8 * LICENSE.txt file. 9 */ 10 package org.mule.config.spring.parsers.specific.endpoint; 11 12 import org.mule.config.spring.parsers.generic.ParentDefinitionParser; 13 import org.mule.config.spring.parsers.processors.CheckExclusiveAttributes; 14 import org.mule.util.StringUtils; 15 16 import org.w3c.dom.Element; 17 18 /** 19 * Configures a reference to an endpoint on a parent bean. This is typically used in configuration 20 * where a reference to the actual endpoint is not wanted (i.e. Reply-To endpoints should be set as a string 21 * on a message). 22 * 23 * Note that endpoint Reference elements should always have an 'address' and 'ref' attributes available. These 24 * are mutually exclusive. 25 * 26 * Any other attributes on the element processed by this parser will also be set on the parent object. 27 */ 28 public class EndpointRefParser extends ParentDefinitionParser 29 { 30 public EndpointRefParser(String propertyName) 31 { 32 addAlias("address", propertyName); 33 addAlias("ref", propertyName); 34 addAlias("reference", propertyName); 35 registerPreProcessor(new CheckExclusiveAttributes(new String[][]{new String[]{"ref"}, new String[]{"address"}})); 36 } 37 38 39 40 @Override 41 protected void preProcess(Element element) 42 { 43 //This causes the Bean framework to process the "ref" as a string rather than a ref to another object 44 if(StringUtils.isNotEmpty(element.getAttribute("ref"))) 45 { 46 element.setAttribute("reference", element.getAttribute("ref")); 47 element.removeAttribute("ref"); 48 } 49 super.preProcess(element); 50 51 } 52 }