001: /*
002: * $Id: MuleActivationSpec.java 10789 2008-02-12 20:04:43Z dfeist $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.module.jca;
012:
013: import org.mule.api.endpoint.EndpointException;
014: import org.mule.api.endpoint.EndpointURI;
015: import org.mule.endpoint.MuleEndpointURI;
016: import org.mule.util.StringUtils;
017:
018: import java.io.Serializable;
019: import java.util.Properties;
020:
021: import javax.resource.ResourceException;
022: import javax.resource.spi.ActivationSpec;
023: import javax.resource.spi.InvalidPropertyException;
024: import javax.resource.spi.ResourceAdapter;
025:
026: /**
027: * <code>MuleActivationSpec</code> defines the contract between a Message Driven
028: * Bean (MDB) and the Mule Resource Adapter. This spec holds the configuration values
029: * used to register inbound communication with the Resource Adapter
030: */
031: public class MuleActivationSpec implements ActivationSpec, Serializable {
032: /**
033: * Serial version
034: */
035: private static final long serialVersionUID = 735353511874563914L;
036:
037: private Properties propertiesMap;
038: private String endpointName;
039: private String connectorName;
040: private int createConnector;
041: private MuleResourceAdapter resourceAdapter;
042: private String endpoint;
043: private EndpointURI endpointURI;
044: private String modelName;
045:
046: public Properties getPropertiesMap() {
047: return propertiesMap;
048: }
049:
050: public void setPropertiesMap(Properties propertiesMap) {
051: this .propertiesMap = propertiesMap;
052: }
053:
054: public void setPropertiesMap(String properties) {
055: String[] pairs = StringUtils.splitAndTrim(properties, ",");
056: Properties props = new Properties();
057:
058: for (int i = 0; i < pairs.length; i++) {
059: String pair = pairs[i];
060: int x = pair.indexOf('=');
061: if (x == -1) {
062: props.setProperty(pair, null);
063: } else {
064: props.setProperty(pair.substring(0, x), pair
065: .substring(x + 1));
066: }
067: }
068:
069: this .setPropertiesMap(props);
070: }
071:
072: public String getEndpointName() {
073: return endpointName;
074: }
075:
076: public void setEndpointName(String endpointName) {
077: this .endpointName = endpointName;
078: }
079:
080: public String getConnectorName() {
081: return connectorName;
082: }
083:
084: public void setConnectorName(String connectorName) {
085: this .connectorName = connectorName;
086: }
087:
088: public int getCreateConnector() {
089: return createConnector;
090: }
091:
092: public void setCreateConnector(int createConnector) {
093: this .createConnector = createConnector;
094: }
095:
096: public String getEndpoint() {
097: return endpoint;
098: }
099:
100: public void setEndpoint(String endpoint) {
101: this .endpoint = endpoint;
102:
103: }
104:
105: public void validate() throws InvalidPropertyException {
106: try {
107: this .endpointURI = new MuleEndpointURI(endpoint);
108: } catch (EndpointException e) {
109: throw new InvalidPropertyException(e);
110: }
111:
112: if (propertiesMap != null) {
113: propertiesMap.putAll(this .endpointURI.getParams());
114: } else {
115: propertiesMap = this .endpointURI.getParams();
116: }
117: if (endpoint == null) {
118: throw new InvalidPropertyException("endpoint is null");
119: }
120:
121: if (endpointURI == null) {
122: throw new InvalidPropertyException("endpointURI is null");
123: }
124: }
125:
126: public ResourceAdapter getResourceAdapter() {
127: return resourceAdapter;
128: }
129:
130: public void setResourceAdapter(ResourceAdapter resourceAdapter)
131: throws ResourceException {
132: // spec section 5.3.3
133: if (this .resourceAdapter != null) {
134: throw new ResourceException("ResourceAdapter already set");
135: }
136: if (!(resourceAdapter instanceof MuleResourceAdapter)) {
137: throw new ResourceException(
138: "ResourceAdapter is not of type: "
139: + MuleResourceAdapter.class.getName());
140: }
141: this .resourceAdapter = (MuleResourceAdapter) resourceAdapter;
142: }
143:
144: public String getModelName() {
145: return modelName;
146: }
147:
148: public void setModelName(String modelName) {
149: this.modelName = modelName;
150: }
151: }
|