01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
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.OMAttribute;
23: import org.apache.axiom.om.OMElement;
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.AbstractMediatorFactory;
29:
30: import javax.xml.namespace.QName;
31:
32: /**
33: * Creates an instance of a Spring mediator that refers to the given Spring
34: * configuration and bean. Optionally, one could specify an inlined Spring
35: * configuration as opposed to a globally defined Spring configuration
36: * <p/>
37: * <spring bean="exampleBean1" key="string""/>
38: */
39: public class SpringMediatorFactory extends AbstractMediatorFactory {
40:
41: private static final Log log = LogFactory
42: .getLog(SpringMediatorFactory.class);
43:
44: private static final QName TAG_NAME = new QName(
45: XMLConfigConstants.SYNAPSE_NAMESPACE + "/spring", "spring");
46:
47: /**
48: * Create a Spring mediator instance referring to the bean and configuration given
49: * by the OMElement declaration
50: *
51: * @param elem the OMElement that specifies the Spring mediator configuration
52: * @return the Spring mediator instance created
53: */
54: public Mediator createMediator(OMElement elem) {
55:
56: SpringMediator sm = new SpringMediator();
57: OMAttribute bean = elem.getAttribute(new QName(
58: XMLConfigConstants.NULL_NAMESPACE, "bean"));
59: OMAttribute key = elem.getAttribute(new QName(
60: XMLConfigConstants.NULL_NAMESPACE, "key"));
61:
62: if (bean == null) {
63: handleException("The 'bean' attribute is required for a Spring mediator definition");
64: } else if (key == null) {
65: handleException("A 'key' attribute is required for a Spring mediator definition");
66: } else {
67:
68: // after successfully creating the mediator
69: // set its common attributes such as tracing etc
70: processTraceState(sm, elem);
71: sm.setBeanName(bean.getAttributeValue());
72: sm.setConfigKey(key.getAttributeValue());
73: return sm;
74: }
75: return null;
76: }
77:
78: public QName getTagQName() {
79: return TAG_NAME;
80: }
81: }
|