20 package org.vortex.FACE;
    23 import java.io.IOException;
    24 import java.util.HashSet;
    26 import javax.xml.XMLConstants;
    27 import javax.xml.parsers.DocumentBuilder;
    28 import javax.xml.parsers.DocumentBuilderFactory;
    29 import javax.xml.parsers.ParserConfigurationException;
    30 import javax.xml.transform.dom.DOMSource;
    31 import javax.xml.transform.stream.StreamSource;
    32 import javax.xml.validation.Schema;
    33 import javax.xml.validation.SchemaFactory;
    34 import javax.xml.validation.Validator;
    36 import org.omg.dds.core.QosProvider;
    37 import org.omg.dds.core.ServiceEnvironment;
    38 import org.omg.dds.domain.DomainParticipantQos;
    39 import org.omg.dds.pub.DataWriterQos;
    40 import org.omg.dds.pub.PublisherQos;
    41 import org.omg.dds.sub.DataReaderQos;
    42 import org.omg.dds.sub.SubscriberQos;
    43 import org.omg.dds.topic.TopicQos;
    44 import org.w3c.dom.Document;
    45 import org.w3c.dom.Element;
    46 import org.w3c.dom.Node;
    47 import org.w3c.dom.NodeList;
    48 import org.xml.sax.SAXException;
    50 import FACE.CONNECTION_DIRECTION_TYPE;
    54     private static final String SCHEMA_PATH = 
"vortex_face.xsd";
    58     private CONNECTION_DIRECTION_TYPE direction;
    59     private long platformViewGuid;
    60     private long refreshPeriod;
    61     private String topicName;
    62     private String typeName;
    63     private ServiceEnvironment env;
    64     private final HashSet<ConnectionDescription> configurations = 
new HashSet<ConnectionDescription>();
    73             String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
    74             SchemaFactory factory = SchemaFactory.newInstance(language);
    75             schema = factory.newSchema(
new StreamSource(this.getClass().getClassLoader().getResourceAsStream(SCHEMA_PATH)));
    76         } 
catch (Exception e) {
    80         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    81         factory.setSchema(schema);
    82         factory.setNamespaceAware(
true);
    83         DocumentBuilder builder;
    88         CONNECTION_DIRECTION_TYPE direction = null;
    89         long platformViewGuid;
    95             builder = factory.newDocumentBuilder();
    97             Document document = builder.parse(
new File(configurationUri));
    98             Validator validator = schema.newValidator();
    99             validator.validate(
new DOMSource(document));
   101             NodeList nList = document.getElementsByTagName(
"connection");
   102             for (
int temp = 0; temp < nList.getLength(); temp++) {
   103                 Node nNode = nList.item(temp);
   104                 if (nNode.getNodeType() == Node.ELEMENT_NODE) {
   105                     Element eElement = (Element) nNode;
   106                     type = this.getStringConfig(eElement, 
"type");
   108                     if (!
"DDS".
equals(type)) {
   112                     String dir = this.getStringConfig(eElement, 
"direction");
   114                     if (
"SOURCE".
equals(dir)) {
   115                         direction = CONNECTION_DIRECTION_TYPE.SOURCE;
   116                     } 
else if (
"DESTINATION".
equals(dir)) {
   117                         direction = CONNECTION_DIRECTION_TYPE.DESTINATION;
   120                                 "Only SOURCE and DESTINATION connections are supported (found: '"   123                     NodeList qosList = eElement.getElementsByTagName(
"qos");
   125                     if (qosList.getLength() == 0) {
   126                         qos = 
new QosConfiguration(env, null, null, null, null, null, null, null, null);
   128                         Element qosElement = (Element) qosList.item(0);
   129                         String qosUri = this.getStringConfig(qosElement, 
"uri");
   130                         String qosProfile = this.getStringConfig(qosElement, 
"profile");
   131                         String domainparticipant_qos_id = this.getStringConfig(qosElement, 
"domainparticipant_qos_id", 
true);
   132                         String topic_qos_id= this.getStringConfig(qosElement, 
"topic_qos_id", 
true);
   133                         String publisher_qos_id = this.getStringConfig(qosElement, 
"publisher_qos_id", 
true);
   134                         String datawriter_qos_id = this.getStringConfig(qosElement, 
"datawriter_qos_id", 
true);
   135                         String subscriber_qos_id = this.getStringConfig(qosElement, 
"subscriber_qos_id", 
true);
   136                         String datareader_qos_id = this.getStringConfig(qosElement, 
"datareader_qos_id", 
true);
   137                         qos = 
new QosConfiguration(env, qosUri, qosProfile, domainparticipant_qos_id, topic_qos_id, publisher_qos_id, datawriter_qos_id, subscriber_qos_id, datareader_qos_id);
   139                     name = this.getStringConfig(eElement, 
"name").toLowerCase();
   141                     platformViewGuid = this.getLongConfig(eElement, 
"platform_view_guid");
   142                     refreshPeriod = this.getLongConfig(eElement, 
"refresh_period");
   143                     domainId = this.getIntConfig(eElement, 
"domain_id", DDS.DOMAIN_ID_DEFAULT.value);
   144                     topicName = this.getStringConfig(eElement, 
"topic_name");
   145                     typeName = this.getStringConfig(eElement, 
"type_name");
   147                     configurations.add(config);
   150         } 
catch (ParserConfigurationException e) {
   152         } 
catch (SAXException e) {
   154         } 
catch (IOException e) {
   159     private long getLongConfig(Element element, String name)
   161         String value = this.getStringConfig(element, name);
   163             return Long.parseLong(value);
   164         } 
catch (NumberFormatException e) {
   169     private int getIntConfig(Element element, String name, 
int defaultValue)
   171         String value = this.getStringConfig(element, name, 
true);
   176                 return Integer.parseInt(value);
   177             } 
catch (NumberFormatException e) {
   183     private String getStringConfig(Element element, String name, 
boolean optional)
   185         String result = null;
   186         NodeList list = element.getElementsByTagName(name);
   188         if (list.getLength() != 1 && !optional) {
   191             if (list.getLength() == 1) {
   192                 Node child = list.item(0).getFirstChild();
   196                             + 
"' has no content.");
   198                 result = child.getNodeValue();
   204     private String getStringConfig(Element element, String name)
   206         NodeList list = element.getElementsByTagName(name);
   208         if (list.getLength() != 1) {
   211         Node child = list.item(0).getFirstChild();
   215                     + 
"' has no content.");
   217         return child.getNodeValue();
   223             CONNECTION_DIRECTION_TYPE direction, 
long platformViewGuid,
   224             long refreshPeriod, String topicName, String typeName) {
   227         this.domainId = domainId;
   228         this.direction = direction;
   229         this.platformViewGuid = platformViewGuid;
   230         this.refreshPeriod = refreshPeriod;
   231         this.topicName = topicName;
   232         this.typeName = typeName;
   246         return configurations;
   262         if (this.
getQos().getQP() == null) {
   266                 ? this.
getQos().
getQP().getDomainParticipantQos(this.
getQos().getDomainparticipant_qos_id())
   271         if (this.
getQos().getQP() == null) {
   274         return this.
getQos().
getQP().getPublisherQos(this.
getQos().getPublisher_qos_id());
   278         if (this.
getQos().getQP() == null) {
   287         if (this.
getQos().getQP() == null) {
   295         if (this.
getQos().getQP() == null) {
   304         if (this.
getQos().getQP() == null) {
   313         return this.domainId;
   317         return this.direction;
   321         return this.platformViewGuid;
   325         return this.refreshPeriod;
   329         return this.topicName;
   333         return this.typeName;
   338         final int prime = 31;
   340         result = prime * result + ((configurations == null) ? 0 : configurations.hashCode());
   341         result = prime * result + ((direction == null) ? 0 : direction.hashCode());
   342         result = prime * result + domainId;
   343         result = prime * result + ((env == null) ? 0 : env.hashCode());
   344         result = prime * result + (int) (
id ^ (
id >>> 32));
   345         result = prime * result + ((name == null) ? 0 : name.hashCode());
   346         result = prime * result + (int) (platformViewGuid ^ (platformViewGuid >>> 32));
   347         result = prime * result + ((qos == null) ? 0 : qos.hashCode());
   348         result = prime * result + (int) (refreshPeriod ^ (refreshPeriod >>> 32));
   349         result = prime * result + ((topicName == null) ? 0 : topicName.hashCode());
   350         result = prime * result + ((typeName == null) ? 0 : typeName.hashCode());
   360         if (getClass() != obj.getClass())
   363         if (configurations == null) {
   364             if (other.configurations != null)
   366         } 
else if (!configurations.equals(other.configurations))
   368         if (direction == null) {
   369             if (other.direction != null)
   371         } 
else if (!direction.equals(other.direction))
   373         if (domainId != other.domainId)
   376             if (other.env != null)
   378         } 
else if (!env.equals(other.env))
   383             if (other.name != null)
   385         } 
else if (!name.equals(other.name))
   387         if (platformViewGuid != other.platformViewGuid)
   390             if (other.qos != null)
   392         } 
else if (!qos.equals(other.qos))
   394         if (refreshPeriod != other.refreshPeriod)
   396         if (topicName == null) {
   397             if (other.topicName != null)
   399         } 
else if (!topicName.equals(other.topicName))
   401         if (typeName == null) {
   402             if (other.typeName != null)
   404         } 
else if (!typeName.equals(other.typeName))
   412         private String profile;
   413         private String domainparticipant_qos_id;
   414         private String topic_qos_id;
   415         private String publisher_qos_id;
   416         private String datawriter_qos_id;
   417         private String subscriber_qos_id;
   418         private String datareader_qos_id;
   419         private QosProvider qp;
   421         public QosConfiguration(ServiceEnvironment env, String uri, String profile, String domainparticipant_qos_id, String topic_qos_id,
   422                 String publisher_qos_id, String datawriter_qos_id, String subscriber_qos_id, String datareader_qos_id) {
   424             this.profile = profile;
   425             this.domainparticipant_qos_id = domainparticipant_qos_id;
   426             this.topic_qos_id = topic_qos_id;
   427             this.publisher_qos_id = publisher_qos_id;
   428             this.datawriter_qos_id = datawriter_qos_id;
   429             this.subscriber_qos_id = subscriber_qos_id;
   430             this.datareader_qos_id = datareader_qos_id;
   431             if (uri != null && profile != null) {
   432                 this.qp = QosProvider.newQosProvider(uri, profile, env);
   450             this.profile = profile;
   453             return domainparticipant_qos_id;
   456             this.domainparticipant_qos_id = domainparticipant_qos_id;
   462             this.topic_qos_id = topic_qos_id;
   465             return publisher_qos_id;
   468             this.publisher_qos_id = publisher_qos_id;
   471             return datawriter_qos_id;
   474             this.datawriter_qos_id = datawriter_qos_id;
   477             return subscriber_qos_id;
   480             this.subscriber_qos_id = subscriber_qos_id;
   483             return datareader_qos_id;
   486             this.datareader_qos_id = datareader_qos_id;
   491             final int prime = 31;
   493             result = prime * result + ((datareader_qos_id == null) ? 0 : datareader_qos_id.hashCode());
   494             result = prime * result + ((datawriter_qos_id == null) ? 0 : datawriter_qos_id.hashCode());
   495             result = prime * result + ((domainparticipant_qos_id == null) ? 0 : domainparticipant_qos_id.hashCode());
   496             result = prime * result + ((profile == null) ? 0 : profile.hashCode());
   497             result = prime * result + ((publisher_qos_id == null) ? 0 : publisher_qos_id.hashCode());
   498             result = prime * result + ((subscriber_qos_id == null) ? 0 : subscriber_qos_id.hashCode());
   499             result = prime * result + ((topic_qos_id == null) ? 0 : topic_qos_id.hashCode());
   500             result = prime * result + ((uri == null) ? 0 : uri.hashCode());
   501             result = prime * result + ((qp == null) ? 0 : qp.hashCode());
   510             if (getClass() != obj.getClass())
   513             if (datareader_qos_id == null) {
   514                 if (other.datareader_qos_id != null)
   516             } 
else if (!datareader_qos_id.equals(other.datareader_qos_id))
   518             if (datawriter_qos_id == null) {
   519                 if (other.datawriter_qos_id != null)
   521             } 
else if (!datawriter_qos_id.equals(other.datawriter_qos_id))
   523             if (domainparticipant_qos_id == null) {
   524                 if (other.domainparticipant_qos_id != null)
   526             } 
else if (!domainparticipant_qos_id.equals(other.domainparticipant_qos_id))
   528             if (profile == null) {
   529                 if (other.profile != null)
   531             } 
else if (!profile.equals(other.profile))
   533             if (publisher_qos_id == null) {
   534                 if (other.publisher_qos_id != null)
   536             } 
else if (!publisher_qos_id.equals(other.publisher_qos_id))
   538             if (subscriber_qos_id == null) {
   539                 if (other.subscriber_qos_id != null)
   541             } 
else if (!subscriber_qos_id.equals(other.subscriber_qos_id))
   543             if (topic_qos_id == null) {
   544                 if (other.topic_qos_id != null)
   546             } 
else if (!topic_qos_id.equals(other.topic_qos_id))
   549                 if (other.uri != null)
   551             } 
else if (!uri.equals(other.uri))
   554                 if (other.qp != null)
   556             } 
else if (!qp.equals(other.qp))
   563             return "QosConfiguration [uri=" + uri + 
", profile=" + profile + 
", domainparticipant_qos_id=" + domainparticipant_qos_id
   564                     + 
", topic_qos_id=" + topic_qos_id + 
", publisher_qos_id=" + publisher_qos_id
   565                     + 
", datawriter_qos_id=" + datawriter_qos_id + 
", subscriber_qos_id=" + subscriber_qos_id
   566                     + 
", datareader_qos_id=" + datareader_qos_id + 
"]";
 ServiceEnvironment getEnvironment()
long getPlatformViewGuid()
void setPublisher_qos_id(String publisher_qos_id)
void setSubscriber_qos_id(String subscriber_qos_id)
QosConfiguration getQos()
ConnectionDescription(ServiceEnvironment env, String name, long id, int domainId, QosConfiguration qos, CONNECTION_DIRECTION_TYPE direction, long platformViewGuid, long refreshPeriod, String topicName, String typeName)
String getDatawriter_qos_id()
boolean equals(Object obj)
void setProfile(String profile)
void setDomainparticipant_qos_id(String domainparticipant_qos_id)
String getPublisher_qos_id()
void setDatawriter_qos_id(String datawriter_qos_id)
String getDomainparticipant_qos_id()
ConnectionDescription(ServiceEnvironment env, String configurationUri)
SubscriberQos getSubscriberQos()
QosConfiguration(ServiceEnvironment env, String uri, String profile, String domainparticipant_qos_id, String topic_qos_id, String publisher_qos_id, String datawriter_qos_id, String subscriber_qos_id, String datareader_qos_id)
void setTopic_qos_id(String topic_qos_id)
This is a typed class which will be generated by idlpp. 
String getSubscriber_qos_id()
boolean equals(Object obj)
void setQos(QosConfiguration qos)
PublisherQos getPublisherQos()
void setDatareader_qos_id(String datareader_qos_id)
DataReaderQos getDataReaderQos()
CONNECTION_DIRECTION_TYPE getDirection()
DomainParticipantQos getDomainParticipantQos()
HashSet< ConnectionDescription > getConfigurations()
String getDatareader_qos_id()
DataWriterQos getDataWriterQos()