Permalink
Browse files

Created expression function json generator

  • Loading branch information...
1 parent 87ee2e2 commit dc52679fb8235ccd8aac57523299a8bab49f6fa4 @badong2210 badong2210 committed May 1, 2013
@@ -86,5 +86,10 @@
<artifactId>opencsv</artifactId>
<version>2.0</version>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ <version>1.9.1</version>
+ </dependency>
</dependencies>
</project>
@@ -21,10 +21,12 @@
import com.thoughtworks.xstream.XStream;
import org.apache.commons.lang.Validate;
import org.apache.log4j.Logger;
+import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.propertyeditors.ClassEditor;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
+import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.LinkedList;
@@ -93,4 +95,12 @@ private void register(Function function) {
functionMapper.setFunction(function.getPrefix(), function.getName(), method);
}
+
+ public void generateJSON(File file) throws IOException {
+ ObjectMapper mapper = new ObjectMapper();
+
+ // convert user object to json string, and save to a file
+ mapper.writeValue(file, registered);
+
+ }
}
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Copyright (c) 2012. JSpringBot. All Rights Reserved.
+ ~
+ ~ See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The JSpringBot licenses this file to You 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jspringbot</groupId>
+ <artifactId>jspringbot-libraries</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jspringbot-function-generator</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>jspringbot-function-generator</name>
+
+ <build>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <filtering>true</filtering>
+ </testResource>
+ </testResources>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit-addons</groupId>
+ <artifactId>junit-addons</artifactId>
+ <version>${junit.addons.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jspringbot</groupId>
+ <artifactId>jspringbot-expression</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jspringbot</groupId>
+ <artifactId>jspringbot-date</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jspringbot</groupId>
+ <artifactId>jspringbot-json</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jspringbot</groupId>
+ <artifactId>jspringbot-xml</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
@@ -0,0 +1,33 @@
+package org.jspringbot.function.generator;
+
+import org.jspringbot.keyword.expression.engine.function.SupportedFunctionsManager;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.core.io.Resource;
+
+import java.io.IOException;
+
+
+public class JSONGenerator implements ApplicationContextAware {
+
+ private Resource resource;
+
+ private ApplicationContext applicationContext;
+
+ public JSONGenerator(Resource resource) {
+ this.resource = resource;
+ }
+
+ public void generate() throws IOException {
+ SupportedFunctionsManager functionManager = new SupportedFunctionsManager(applicationContext);
+
+ System.out.println("Document: " + resource.getURI());
+ functionManager.generateJSON(resource.getFile());
+ }
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ this.applicationContext = applicationContext;
+ }
+}
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012. JSpringBot. All Rights Reserved.
+ *
+ * See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The JSpringBot licenses this file to You 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.jspringbot.function.generator;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * Responsible for generating json object from the list of expression functions
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations={"classpath:spring/spring-function-generator.xml"})
+public final class JSONGeneratorTest extends AbstractJUnit4SpringContextTests {
+
+ @Autowired
+ public JSONGenerator generator;
+
+ @Test
+ public void testGenerateFunctionDocuments() throws Exception {
+ generator.generate();
+ }
+}
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Copyright (c) 2012. JSpringBot. All Rights Reserved.
+ ~
+ ~ See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The JSpringBot licenses this file to You 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.
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <import resource="classpath:spring/spring-expression.xml"/>
+ <import resource="classpath:spring/spring-date.xml"/>
+ <import resource="classpath:spring/spring-json.xml"/>
+ <import resource="classpath:spring/spring-xml.xml"/>
+
+ <bean name="jsonFunctionGenerator" class="org.jspringbot.function.generator.JSONGenerator">
+ <constructor-arg value="file:${pom.build.directory}/functions.json"/>
+ </bean>
+</beans>
View
@@ -125,5 +125,6 @@
<module>jspringbot-db</module>
<module>jspringbot-i18n</module>
<module>jspringbot-expression</module>
+ <module>jspringbot-function-generator</module>
</modules>
</project>

0 comments on commit dc52679

Please sign in to comment.