diff --git a/src/main/java/org/springframework/data/gemfire/IndexFactoryBean.java b/src/main/java/org/springframework/data/gemfire/IndexFactoryBean.java
index a46efdc1..5f657157 100644
--- a/src/main/java/org/springframework/data/gemfire/IndexFactoryBean.java
+++ b/src/main/java/org/springframework/data/gemfire/IndexFactoryBean.java
@@ -44,7 +44,7 @@ public class IndexFactoryBean implements InitializingBean, BeanNameAware, Factor
private RegionService cache;
private String beanName;
private String name, expression, from, imports;
- private IndexType type;
+ private IndexType type = IndexType.FUNCTIONAL;
public void afterPropertiesSet() throws Exception {
if (queryService == null) {
@@ -60,8 +60,13 @@ public class IndexFactoryBean implements InitializingBean, BeanNameAware, Factor
}
Assert.notNull(queryService, "Query service required for index creation");
+ Assert.hasText(expression, "Index expression is required");
+ Assert.hasText(from, "Index from clause is required");
String indexName = StringUtils.hasText(name) ? name : beanName;
+
+ Assert.hasText(indexName, "Index bean id or name is required");
+
index = createIndex(queryService, indexName);
}
diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java b/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java
index 62a93ae1..57eeafe6 100644
--- a/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java
+++ b/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java
@@ -34,6 +34,7 @@ class GemfireNamespaceHandler extends NamespaceHandlerSupport {
registerBeanDefinitionParser("partitioned-region", new PartitionedRegionParser());
registerBeanDefinitionParser("client-region", new ClientRegionParser());
registerBeanDefinitionParser("pool", new PoolParser());
+ registerBeanDefinitionParser("index", new IndexParser());
registerBeanDefinitionParser("cache-server", new CacheServerParser());
registerBeanDefinitionParser("transaction-manager", new TransactionManagerParser());
diff --git a/src/main/java/org/springframework/data/gemfire/config/IndexParser.java b/src/main/java/org/springframework/data/gemfire/config/IndexParser.java
new file mode 100644
index 00000000..b97f428c
--- /dev/null
+++ b/src/main/java/org/springframework/data/gemfire/config/IndexParser.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.data.gemfire.config;
+
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.data.gemfire.IndexFactoryBean;
+import org.w3c.dom.Element;
+
+/**
+ * Parser for <index;gt; definitions.
+ *
+ * @author Costin Leau
+ */
+class IndexParser extends AbstractSimpleBeanDefinitionParser {
+
+ protected Class> getBeanClass(Element element) {
+ return IndexFactoryBean.class;
+ }
+
+ @Override
+ protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
+ ParsingUtils.setPropertyReference(element, builder, "cache-ref", "cache");
+ super.doParse(element, parserContext, builder);
+ }
+
+ @Override
+ protected boolean isEligibleAttribute(String attributeName) {
+ if ("cache-ref".equals(attributeName)) {
+ return false;
+ }
+ return super.isEligibleAttribute(attributeName);
+ }
+}
diff --git a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.1.xsd b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.1.xsd
index 97bf572d..286bbc39 100644
--- a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.1.xsd
+++ b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.1.xsd
@@ -1174,6 +1174,21 @@ The name of the index.]]>
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java
new file mode 100644
index 00000000..ad823b3a
--- /dev/null
+++ b/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.data.gemfire.config;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.data.gemfire.IndexFactoryBean;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ *
+ * @author Costin Leau
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("index-ns.xml")
+public class IndexNamespaceTest {
+
+ @Autowired
+ private ApplicationContext context;
+
+ @Test
+ public void testBasicIndex() throws Exception {
+ IndexFactoryBean ifb = null;
+
+ ifb = (IndexFactoryBean) context.getBean("&simple");
+ System.out.println("Ifb is " + ifb);
+ }
+
+ @Test
+ public void testComplexIndex() throws Exception {
+ }
+
+}
diff --git a/src/test/resources/org/springframework/data/gemfire/config/index-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/index-ns.xml
new file mode 100644
index 00000000..ed92e517
--- /dev/null
+++ b/src/test/resources/org/springframework/data/gemfire/config/index-ns.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file