private Element createRootUrlElement(Document doc, ClusteringServiceConfiguration clusteringServiceConfiguration) { Element rootElement = doc.createElementNS(getNamespace().toString(), TC_CLUSTERED_NAMESPACE_PREFIX + CLUSTER_ELEMENT_NAME); Element urlElement = createUrlElement(doc, clusteringServiceConfiguration); rootElement.appendChild(urlElement); return rootElement; }
private Element createServerElement(Document doc, ClusteringServiceConfiguration clusteringServiceConfiguration) { if (!(clusteringServiceConfiguration.getConnectionSource() instanceof ConnectionSource.ServerList)) { throw new IllegalArgumentException("When connection URL is null, source of connection MUST be of type ConnectionSource.ServerList.class"); } ConnectionSource.ServerList servers = (ConnectionSource.ServerList)clusteringServiceConfiguration.getConnectionSource(); Element rootElement = doc.createElementNS(getNamespace().toString(), TC_CLUSTERED_NAMESPACE_PREFIX + CLUSTER_ELEMENT_NAME); Element connElement = createConnectionElementWrapper(doc, clusteringServiceConfiguration); servers.getServers().forEach(server -> { Element serverElement = doc.createElement(TC_CLUSTERED_NAMESPACE_PREFIX + SERVER_ELEMENT_NAME); serverElement.setAttribute(HOST_ATTRIBUTE_NAME, server.getHostName()); /* If port is greater than 0, set the attribute. Otherwise, do not set. Default value will be taken. */ if (server.getPort() > 0) { serverElement.setAttribute(PORT_ATTRIBUTE_NAME, Integer.toString(server.getPort())); } connElement.appendChild(serverElement); }); rootElement.appendChild(connElement); return rootElement; }
protected Element processServerSideElements(Document doc, ClusteringServiceConfiguration clusteringServiceConfiguration) { Element serverSideConfigurationElem = createServerSideConfigurationElement(doc, clusteringServiceConfiguration); if (clusteringServiceConfiguration.getServerConfiguration() != null) { ServerSideConfiguration serverSideConfiguration = clusteringServiceConfiguration.getServerConfiguration(); String defaultServerResource = serverSideConfiguration.getDefaultServerResource(); if (!(defaultServerResource == null || defaultServerResource.trim().length() == 0)) { Element defaultResourceElement = createDefaultServerResourceElement(doc, defaultServerResource); serverSideConfigurationElem.appendChild(defaultResourceElement); } Map<String, ServerSideConfiguration.Pool> resourcePools = serverSideConfiguration.getResourcePools(); if (resourcePools != null) { resourcePools.forEach( (key, value) -> { Element poolElement = createSharedPoolElement(doc, key, value); serverSideConfigurationElem.appendChild(poolElement); } ); } } return serverSideConfigurationElem; }
@Override protected Element createRootElement(Document doc, ClusteringServiceConfiguration clusteringServiceConfiguration) { Element rootElement; if (clusteringServiceConfiguration.getConnectionSource() instanceof ConnectionSource.ClusterUri) { rootElement = createRootUrlElement(doc, clusteringServiceConfiguration); } else { rootElement = createServerElement(doc, clusteringServiceConfiguration); } processTimeUnits(doc, rootElement, clusteringServiceConfiguration); Element serverSideConfigurationElem = processServerSideElements(doc, clusteringServiceConfiguration); rootElement.appendChild(serverSideConfigurationElem); return rootElement; }
getTimeout = processTimeout(fragment, item); putTimeout = processTimeout(fragment, item); connectionTimeout = processTimeout(fragment, item); serverConfig = processServerSideConfig(item); break; default: Timeouts timeouts = getTimeouts(getTimeout, putTimeout, connectionTimeout); if (serverConfig == null) { if (connectionUri != null) {
/** * Ensures the namespace declared by {@link ClusteringCacheManagerServiceConfigurationParser} and its * schema are the same. */ @Test public void testSchema() throws Exception { final ClusteringCacheManagerServiceConfigurationParser parser = new ClusteringCacheManagerServiceConfigurationParser(); final StreamSource schemaSource = (StreamSource) parser.getXmlSchema(); final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); final DocumentBuilder domBuilder = factory.newDocumentBuilder(); final Element schema = domBuilder.parse(schemaSource.getInputStream()).getDocumentElement(); final Attr targetNamespaceAttr = schema.getAttributeNode("targetNamespace"); assertThat(targetNamespaceAttr, is(not(nullValue()))); assertThat(targetNamespaceAttr.getValue(), is(parser.getNamespace().toString())); }
private void processTimeUnits(Document doc, Element parent, ClusteringServiceConfiguration clusteringServiceConfiguration) { if (clusteringServiceConfiguration.getTimeouts() != null) { Timeouts timeouts = clusteringServiceConfiguration.getTimeouts(); Element readTimeoutElem = createTimeoutElement(doc, READ_TIMEOUT_ELEMENT_NAME, timeouts.getReadOperationTimeout()); Element writeTimeoutElem = createTimeoutElement(doc, WRITE_TIMEOUT_ELEMENT_NAME, timeouts.getWriteOperationTimeout()); Element connectionTimeoutElem = createTimeoutElement(doc, CONNECTION_TIMEOUT_ELEMENT_NAME, timeouts.getConnectionTimeout()); /* Important: do not change the order of following three elements if corresponding change is not done in xsd */ parent.appendChild(readTimeoutElem); parent.appendChild(writeTimeoutElem); parent.appendChild(connectionTimeoutElem); } }
@Override protected Element createRootElement(Document doc, ClusteringServiceConfiguration clusteringServiceConfiguration) { Element rootElement; if (clusteringServiceConfiguration.getConnectionSource() instanceof ConnectionSource.ClusterUri) { rootElement = createRootUrlElement(doc, clusteringServiceConfiguration); } else { rootElement = createServerElement(doc, clusteringServiceConfiguration); } processTimeUnits(doc, rootElement, clusteringServiceConfiguration); Element serverSideConfigurationElem = processServerSideElements(doc, clusteringServiceConfiguration); rootElement.appendChild(serverSideConfigurationElem); return rootElement; }
getTimeout = processTimeout(fragment, item); putTimeout = processTimeout(fragment, item); connectionTimeout = processTimeout(fragment, item); serverConfig = processServerSideConfig(item); break; default: Timeouts timeouts = getTimeouts(getTimeout, putTimeout, connectionTimeout); if (serverConfig == null) { if (connectionUri != null) {
private void processTimeUnits(Document doc, Element parent, ClusteringServiceConfiguration clusteringServiceConfiguration) { if (clusteringServiceConfiguration.getTimeouts() != null) { Timeouts timeouts = clusteringServiceConfiguration.getTimeouts(); Element readTimeoutElem = createTimeoutElement(doc, READ_TIMEOUT_ELEMENT_NAME, timeouts.getReadOperationTimeout()); Element writeTimeoutElem = createTimeoutElement(doc, WRITE_TIMEOUT_ELEMENT_NAME, timeouts.getWriteOperationTimeout()); Element connectionTimeoutElem = createTimeoutElement(doc, CONNECTION_TIMEOUT_ELEMENT_NAME, timeouts.getConnectionTimeout()); /* Important: do not change the order of following three elements if corresponding change is not done in xsd */ parent.appendChild(readTimeoutElem); parent.appendChild(writeTimeoutElem); parent.appendChild(connectionTimeoutElem); } }
protected Element processServerSideElements(Document doc, ClusteringServiceConfiguration clusteringServiceConfiguration) { Element serverSideConfigurationElem = createServerSideConfigurationElement(doc, clusteringServiceConfiguration); if (clusteringServiceConfiguration.getServerConfiguration() != null) { ServerSideConfiguration serverSideConfiguration = clusteringServiceConfiguration.getServerConfiguration(); String defaultServerResource = serverSideConfiguration.getDefaultServerResource(); if (!(defaultServerResource == null || defaultServerResource.trim().length() == 0)) { Element defaultResourceElement = createDefaultServerResourceElement(doc, defaultServerResource); serverSideConfigurationElem.appendChild(defaultResourceElement); } Map<String, ServerSideConfiguration.Pool> resourcePools = serverSideConfiguration.getResourcePools(); if (resourcePools != null) { resourcePools.forEach( (key, value) -> { Element poolElement = createSharedPoolElement(doc, key, value); serverSideConfigurationElem.appendChild(poolElement); } ); } } return serverSideConfigurationElem; }
private Element createRootUrlElement(Document doc, ClusteringServiceConfiguration clusteringServiceConfiguration) { Element rootElement = doc.createElementNS(getNamespace().toString(), TC_CLUSTERED_NAMESPACE_PREFIX + CLUSTER_ELEMENT_NAME); Element urlElement = createUrlElement(doc, clusteringServiceConfiguration); rootElement.appendChild(urlElement); return rootElement; }
private Element createServerElement(Document doc, ClusteringServiceConfiguration clusteringServiceConfiguration) { if (!(clusteringServiceConfiguration.getConnectionSource() instanceof ConnectionSource.ServerList)) { throw new IllegalArgumentException("When connection URL is null, source of connection MUST be of type ConnectionSource.ServerList.class"); } ConnectionSource.ServerList servers = (ConnectionSource.ServerList)clusteringServiceConfiguration.getConnectionSource(); Element rootElement = doc.createElementNS(getNamespace().toString(), TC_CLUSTERED_NAMESPACE_PREFIX + CLUSTER_ELEMENT_NAME); Element connElement = createConnectionElementWrapper(doc, clusteringServiceConfiguration); servers.getServers().forEach(server -> { Element serverElement = doc.createElement(TC_CLUSTERED_NAMESPACE_PREFIX + SERVER_ELEMENT_NAME); serverElement.setAttribute(HOST_ATTRIBUTE_NAME, server.getHostName()); /* If port is greater than 0, set the attribute. Otherwise, do not set. Default value will be taken. */ if (server.getPort() > 0) { serverElement.setAttribute(PORT_ATTRIBUTE_NAME, Integer.toString(server.getPort())); } connElement.appendChild(serverElement); }); rootElement.appendChild(connElement); return rootElement; }