001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.servicemix.common;
018:
019: import org.apache.commons.logging.Log;
020: import org.w3c.dom.Document;
021:
022: import javax.jbi.management.DeploymentException;
023: import javax.jbi.messaging.MessageExchange;
024: import javax.jbi.messaging.MessageExchange.Role;
025: import javax.wsdl.Definition;
026: import javax.xml.namespace.QName;
027:
028: public abstract class Endpoint {
029:
030: protected QName service;
031: protected String endpoint;
032: protected QName interfaceName;
033: protected Document description;
034: protected Definition definition;
035: protected ServiceUnit serviceUnit;
036: protected Log logger;
037: private String key;
038:
039: public Endpoint() {
040: }
041:
042: public Endpoint(ServiceUnit serviceUnit, QName service,
043: String endpoint) {
044: this .serviceUnit = serviceUnit;
045: this .logger = serviceUnit.getComponent().getLogger();
046: this .service = service;
047: this .endpoint = endpoint;
048: }
049:
050: /**
051: * @return Returns the endpoint.
052: */
053: public String getEndpoint() {
054: return endpoint;
055: }
056:
057: /**
058: * @param endpoint The endpoint to set.
059: */
060: public void setEndpoint(String endpoint) {
061: this .endpoint = endpoint;
062: this .key = null;
063: }
064:
065: /**
066: * @return Returns the service.
067: */
068: public QName getService() {
069: return service;
070: }
071:
072: /**
073: * @param service The service to set.
074: */
075: public void setService(QName service) {
076: this .service = service;
077: this .key = null;
078: }
079:
080: /**
081: * @return Returns the role.
082: */
083: public abstract Role getRole();
084:
085: /**
086: * @return Returns the description.
087: */
088: public Document getDescription() {
089: return description;
090: }
091:
092: /**
093: * @param description The description to set.
094: */
095: public void setDescription(Document description) {
096: this .description = description;
097: }
098:
099: /**
100: * @return Returns the interfaceName.
101: */
102: public QName getInterfaceName() {
103: return interfaceName;
104: }
105:
106: /**
107: * @param interfaceName The interfaceName to set.
108: */
109: public void setInterfaceName(QName interfaceName) {
110: this .interfaceName = interfaceName;
111: }
112:
113: /**
114: * @return Returns the serviceUnit.
115: */
116: public ServiceUnit getServiceUnit() {
117: return serviceUnit;
118: }
119:
120: /**
121: * @param serviceUnit The serviceUnit to set.
122: */
123: public void setServiceUnit(ServiceUnit serviceUnit) {
124: this .serviceUnit = serviceUnit;
125: this .logger = serviceUnit.component.getLogger();
126: }
127:
128: public boolean isExchangeOkay(MessageExchange exchange) {
129: // TODO: We could check the MEP here
130: return true;
131: }
132:
133: public abstract void activate() throws Exception;
134:
135: public abstract void deactivate() throws Exception;
136:
137: public abstract ExchangeProcessor getProcessor();
138:
139: public String toString() {
140: return "Endpoint[service: "
141: + service
142: + ", "
143: + "endpoint: "
144: + endpoint
145: + ", "
146: + "role: "
147: + (getRole() == Role.PROVIDER ? "provider" : "consumer")
148: + "]";
149: }
150:
151: /**
152: * Validate the endpoint at either deployment time for statically defined endpoints or at runtime for dynamic endpoints
153: *
154: * @throws DeploymentException
155: */
156: public void validate() throws DeploymentException {
157: }
158:
159: public Definition getDefinition() {
160: return definition;
161: }
162:
163: public void setDefinition(Definition definition) {
164: this .definition = definition;
165: }
166:
167: String getKey() {
168: if (key == null) {
169: if (service == null) {
170: throw new IllegalArgumentException("Endpoint: " + this
171: + " has no service name defined");
172: }
173: if (endpoint == null) {
174: throw new IllegalArgumentException("Endpoint: " + this
175: + " has no endpoint name defined");
176: }
177: key = EndpointSupport.getKey(service, endpoint);
178: }
179: return key;
180: }
181:
182: }
|