/**
* Copyright (c) 2009-2012 EBM WebSourcing, 2012-2015 Linagora
*
* This program/library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or (at your
* option) any later version.
*
* This program/library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program/library; If not, see
* for the GNU Lesser General Public License version 2.1.
*/
package org.ow2.petals.microkernel.service;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import org.ow2.petals.launcher.api.service.Location;
import org.ow2.petals.launcher.api.service.ServiceEndpoint;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import com.ebmwebsourcing.easycommons.xml.XMLHelper;
/**
* The PEtALS ESB service endpoint implementation.
* @author Christophe Hamerling - EBM WebSourcing
*/
public class ServiceEndpointImpl implements ServiceEndpoint, Serializable {
private static final Logger LOGGER = Logger.getLogger(ServiceEndpointImpl.class.getName());
/**
* Unique serial UID
*/
private static final long serialVersionUID = 3846565220895975538L;
/**
* This attribute is defined "transient" to avoid its serialization when sending message exchanges. This attribute
* is saved/loaded from the registry by the endpoint service.
*/
private transient Document description;
/**
* This is the string description, the document is loaded if needed...
*
* This attribute is defined "transient" to avoid its serialization when sending message exchanges. This attribute
* is saved/loaded from the registry by the endpoint service.
*/
private transient String stringDescription;
private String endpointName;
private QName serviceName;
private Location location;
private List interfacesName;
private EndpointType type;
/**
* Default constructor
*/
public ServiceEndpointImpl() {
this(null, null, new ArrayList(0), null, new Location(),
new HashMap());
}
/**
*
* @param endpointName
* @param serviceName
* @param interfacesName
* @param description
* @param location
*/
public ServiceEndpointImpl(String endpointName, QName serviceName, List interfacesName,
Document description, Location location, Map properties) {
super();
this.endpointName = endpointName;
this.serviceName = serviceName;
this.interfacesName = interfacesName;
this.description = description;
this.location = location;
}
/**
* {@inheritDoc}
*/
public synchronized Document getDescription() {
// transform the string description as DOM one on first call since this
// is not always used, takes time and memory!
if ((this.description == null) && (this.stringDescription != null)) {
try {
this.description = XMLHelper.createDocumentFromString(this.stringDescription);
} catch (SAXException e) {
LOGGER.log(Level.SEVERE, "Bad XML fragment can't be transformed to a DOM tree.", e);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Unexpected Error", e);
}
}
return this.description;
}
/**
* {@inheritDoc}
*/
public String getEndpointName() {
return this.endpointName;
}
/**
* {@inheritDoc}
*/
public List getInterfacesName() {
return this.interfacesName;
}
/**
* {@inheritDoc}
*/
public Location getLocation() {
return this.location;
}
/**
* {@inheritDoc}
*/
public QName getServiceName() {
return this.serviceName;
}
public void setDescription(Document description) {
this.description = description;
}
public void setEndpointName(String endpointName) {
this.endpointName = endpointName;
}
public void setServiceName(QName serviceName) {
this.serviceName = serviceName;
}
public void setLocation(Location location) {
this.location = location;
}
public void setInterfacesName(List interfacesName) {
this.interfacesName = interfacesName;
}
@Override
public String toString() {
return this.serviceName + " ->" + this.endpointName + " (" + this.getType() + "):"
+ this.location.getSubdomainName() + "/" + this.location.getContainerName() + "/"
+ this.location.getComponentName();
}
public EndpointType getType() {
return this.type;
}
public void setType(EndpointType type) {
this.type = type;
}
public String getStringDescription() {
return this.stringDescription;
}
public void setStringDescription(String stringDescription) {
this.stringDescription = stringDescription;
}
}