cleanup of xsd and documentation

This commit is contained in:
Simon Baslé
2015-06-22 11:54:25 +02:00
parent be46d1bdcd
commit 14e08e9717
6 changed files with 40 additions and 165 deletions

View File

@@ -19,7 +19,9 @@ package org.springframework.data.couchbase.config;
import java.util.ArrayList;
import java.util.List;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.env.CouchbaseEnvironment;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
@@ -29,6 +31,19 @@ import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
* The XML parser for a {@link Cluster} definition.
*
* Such a definition can be tuned by either referencing a {@link CouchbaseEnvironment} via
* the {@value #CLUSTER_ENVIRONMENT_REF} attribute or define a custom environment inline via
* the <{@value #CLUSTER_ENVIRONMENT_TAG}> tag (not recommended, environments should be
* shared as possible).
*
* To bootstrap the connection, one can provide IPs or hostnames of nodes to connect to
* via 1 or more <{@value #CLUSTER_NODE_TAG}> tags.
*
* @author Simon Baslé
*/
public class CouchbaseClusterParser extends AbstractSingleBeanDefinitionParser {
/**
@@ -39,12 +54,19 @@ public class CouchbaseClusterParser extends AbstractSingleBeanDefinitionParser {
/**
* The unique <env> element in a cluster definition define the environment customizations.
*
* @see CouchbaseEnvironmentParser for the possible fields.
* @see #CLUSTER_ENVIRONMENT_REF as an alternative (giving a reference to an env instead of inline description)
* @see CouchbaseEnvironmentParser CouchbaseEnvironmentParser for the possible fields.
* @see #CLUSTER_ENVIRONMENT_REF CLUSTER_ENVIRONMENT_REF as an alternative (giving a reference to
* an env instead of inline description, lower precedence)
*/
public static final String CLUSTER_ENVIRONMENT_TAG = "env";
/**
* The <env-ref> attribute allows to use a reference to an {@link CouchbaseEnvironment} to
* tune the connection.
*
* @see #CLUSTER_ENVIRONMENT_TAG CLUSTER_ENVIRONMENT_TAG for an inline alternative
* (which takes priority over this reference)
*/
public static final String CLUSTER_ENVIRONMENT_REF = "env-ref";
/**

View File

@@ -24,6 +24,11 @@ import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
import org.springframework.beans.factory.config.AbstractFactoryBean;
/**
* Factory Bean to help create a CouchbaseEnvironment (by offering setters for supported tuning methods).
*
* @author Simon Baslé
*/
/*package*/ class CouchbaseEnvironmentFactoryBean extends AbstractFactoryBean<CouchbaseEnvironment> {
private static final CouchbaseEnvironment DEFAULT_ENV = DefaultCouchbaseEnvironment.create();

View File

@@ -65,6 +65,8 @@ import org.springframework.util.StringUtils;
* <li>{@link DefaultCouchbaseEnvironment.Builder#autoreleaseAfter(long) autoreleaseAfter}</li>
* <li>{@link DefaultCouchbaseEnvironment.Builder#bufferPoolingEnabled(boolean) bufferPoolingEnabled}</li>
* </ul>
*
* @author Simon Baslé
*/
public class CouchbaseEnvironmentParser extends AbstractSingleBeanDefinitionParser {

View File

@@ -79,7 +79,7 @@ public class CouchbaseJmxParser implements BeanDefinitionParser {
*
* @param clazz the class type to register.
* @param compositeDef component that can hold nested components.
* @param refName the reference name to the couchbase client.
* @param refName the reference name to the couchbase bucket.
* @param eleSource source element to reference.
* @param parserContext encapsulates the parsing state and configuration.
*/

View File

@@ -42,37 +42,6 @@
</xsd:complexType>
</xsd:element>
<xsd:element name="couchbase" type="couchbaseType">
<xsd:annotation>
<xsd:documentation source="org.springframework.data.couchbase.core.CouchbaseFactoryBean"><![CDATA[
Defines a CouchbaseClient instance used for accessing a Couchbase Cluster.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="com.couchbase.client.CouchbaseClient"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="repositories">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="repository:repositories">
<xsd:attributeGroup ref="couchbase-repository-attributes"/>
<xsd:attributeGroup ref="repository:repository-attributes"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="template">
<xsd:complexType>
<xsd:attribute name="id" type="xsd:string" use="optional">
@@ -81,14 +50,14 @@ Defines a CouchbaseClient instance used for accessing a Couchbase Cluster.
The id of the couchbase definition (by default "couchbaseFactory").]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="client-ref" type="xsd:string" use="optional">
<xsd:attribute name="bucket-ref" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation>
The reference to a CouchbaseClient object.
The reference to a Bucket object.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:assignable-to type="com.couchbase.client.CouchbaseClient"/>
<tool:assignable-to type="com.couchbase.client.java.Bucket"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
@@ -151,10 +120,10 @@ Defines a JMX Model MBeans for monitoring a Couchbase cluster'.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="couchbase-ref" type="couchbaseRef" use="optional">
<xsd:attribute name="bucket-ref" type="couchbaseBucketRef" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the Couchbase object that determines what connection to monitor. (by default "couchbase").
The name of the CouchbaseBucket object that determines what connection to monitor. (by default "couchbaseBucket").
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
@@ -183,56 +152,15 @@ The name of the Couchbase object that determines what connection to monitor. (by
<xsd:union memberTypes="xsd:string"/>
</xsd:simpleType>
<xsd:simpleType name="couchbaseRef">
<xsd:simpleType name="couchbaseBucketRef">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:assignable-to type="org.springframework.data.couchbase.core.CouchbaseFactoryBean"/>
<tool:assignable-to type="org.springframework.data.couchbase.config.CouchbaseBucketFactoryBean"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:union memberTypes="xsd:string"/>
</xsd:simpleType>
<xsd:attributeGroup name="couchbase-repository-attributes">
<xsd:attribute name="couchbase-template-ref" type="couchbaseTemplateRef" default="couchbaseTemplate">
<xsd:annotation>
<xsd:documentation>
The reference to a CouchbaseTemplate. Will default to 'couchbaseTemplate'.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:attributeGroup>
<xsd:complexType name="couchbaseType">
<xsd:attribute name="id" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the couchbase definition (by default "couchbase").]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="bucket" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the bucket to connect to. Default is "default".
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="password" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The password of the bucket to connect to. Default is "" (empty).
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="host" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The host to connect to a Couchbase server. Default is localhost.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:schema>

View File

@@ -132,87 +132,5 @@ public class CouchbaseBucketParserTest {
.getArgumentValue(2, Object.class);
assertThat(passwordHolder.getValue(), is(instanceOf(String.class)));
assertThat(passwordHolder.getValue().toString(), is((equalTo("123"))));
}
// @Test
// public void testClusterWithNodes() {
// BeanDefinition def = factory.getBeanDefinition("clusterWithNodes");
//
// assertThat(def, is(notNullValue()));
// assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(1)));
// assertThat(def.getPropertyValues().size(), is(equalTo(0)));
// assertThat(def.getFactoryMethodName(), is(equalTo("create")));
//
// ConstructorArgumentValues.ValueHolder holder = def.getConstructorArgumentValues()
// .getArgumentValue(0, List.class);
// assertThat(holder.getValue(), is(instanceOf(List.class)));
// List nodes = (List<String>) holder.getValue();
//
// assertThat(nodes.size(), is(equalTo(2)));
// assertThat((String) nodes.get(0), is(equalTo("192.1.2.3")));
// assertThat((String) nodes.get(1), is(equalTo("192.4.5.6")));
// }
//
// @Test
// public void testClusterWithEnvInline() {
// BeanDefinition def = factory.getBeanDefinition("clusterWithEnvInline");
//
// assertThat(def, is(notNullValue()));
// assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(1)));
// assertThat(def.getPropertyValues().size(), is(equalTo(0)));
//
// ConstructorArgumentValues.ValueHolder holder = def.getConstructorArgumentValues()
// .getArgumentValue(0, CouchbaseEnvironment.class);
// GenericBeanDefinition envDef = (GenericBeanDefinition) holder.getValue();
//
// assertThat(envDef.getBeanClassName(), is(equalTo(CouchbaseEnvironmentFactoryBean.class.getName())));
// assertThat("unexpected attribute", envDef.getPropertyValues().contains("managementTimeout"));
// }
//
// @Test
// public void testClusterWithEnvRef() {
// BeanDefinition def = factory.getBeanDefinition("clusterWithEnvRef");
//
// assertThat(def, is(notNullValue()));
// assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(1)));
// assertThat(def.getPropertyValues().size(), is(equalTo(0)));
//
// ConstructorArgumentValues.ValueHolder holder = def.getConstructorArgumentValues()
// .getArgumentValue(0, CouchbaseEnvironment.class);
//
// assertThat(holder.getValue(), instanceOf(RuntimeBeanReference.class));
// RuntimeBeanReference envRef = (RuntimeBeanReference) holder.getValue();
//
// assertThat(envRef.getBeanName(), is(equalTo("someEnv")));
// }
// @Test
// public void testClusterConfigurationPrecedence() {
// BeanDefinition def = factory.getBeanDefinition("clusterWithAll");
//
// assertThat(def, is(notNullValue()));
// assertThat(def.getConstructorArgumentValues().getArgumentCount(), is(equalTo(2)));
// assertThat(def.getPropertyValues().size(), is(equalTo(0)));
// assertThat(def.getFactoryMethodName(), is(equalTo("create")));
//
// assertThat(def.getConstructorArgumentValues().getIndexedArgumentValues().get(0).getValue(),
// instanceOf(GenericBeanDefinition.class));
// assertThat(def.getConstructorArgumentValues().getIndexedArgumentValues().get(1).getValue(),
// instanceOf(List.class));
//
// ConstructorArgumentValues.ValueHolder holderEnv = def.getConstructorArgumentValues()
// .getArgumentValue(0, CouchbaseEnvironment.class);
// GenericBeanDefinition envDef = (GenericBeanDefinition) holderEnv.getValue();
//
// assertThat(envDef.getBeanClassName(), is(equalTo(CouchbaseEnvironmentFactoryBean.class.getName())));
// assertThat("unexpected attribute", envDef.getPropertyValues().contains("autoreleaseAfter"));
//
// ConstructorArgumentValues.ValueHolder holderNodes = def.getConstructorArgumentValues()
// .getArgumentValue(1, List.class);
// List nodes = (List<String>) holderNodes.getValue();
//
// assertThat(nodes.size(), is(equalTo(2)));
// assertThat((String) nodes.get(0), is(equalTo("2.2.2.2")));
// assertThat((String) nodes.get(1), is(equalTo("4.4.4.4")));
// }
}