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.wsn;
018
019 import org.w3._2005._08.addressing.AttributedURIType;
020 import org.w3._2005._08.addressing.EndpointReferenceType;
021
022 public abstract class AbstractEndpoint {
023
024 protected final String name;
025
026 protected String address;
027
028 protected EndpointManager manager;
029
030 protected Object endpoint;
031
032 public AbstractEndpoint(String name) {
033 this.name = name;
034 this.address = createAddress();
035 }
036
037 public String getName() {
038 return name;
039 }
040
041 public String getAddress() {
042 return address;
043 }
044
045 public void setAddress(String address) {
046 this.address = address;
047 }
048
049 public void register() throws EndpointRegistrationException {
050 endpoint = manager.register(getAddress(), this);
051 }
052
053 public void unregister() throws EndpointRegistrationException {
054 if (endpoint != null) {
055 manager.unregister(endpoint);
056 }
057 }
058
059 public EndpointManager getManager() {
060 return manager;
061 }
062
063 public void setManager(EndpointManager manager) {
064 this.manager = manager;
065 }
066
067 protected abstract String createAddress();
068
069 public static EndpointReferenceType createEndpointReference(String address) {
070 EndpointReferenceType epr = new EndpointReferenceType();
071 AttributedURIType addressUri = new AttributedURIType();
072 addressUri.setValue(address);
073 epr.setAddress(addressUri);
074 return epr;
075 }
076
077 }