001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq.util;
018    import java.lang.reflect.Method;
019    import java.util.ArrayList;
020    import java.util.regex.Pattern;
021    
022    import org.apache.activemq.store.jdbc.Statements;
023    
024    
025    public class GenerateJDBCStatements {
026        public static String returnStatement(Object statement){
027            return ((String)statement).replace("<", "&lt;").replace(">", "&gt;");
028            
029        }
030            /**
031             * @param args
032             */
033            public static void main(String[] args) throws Exception{
034            Statements s=new Statements();
035            s.setTablePrefix("ACTIVEMQ.");
036            String[] stats=s.getCreateSchemaStatements();
037            System.out.println("<bean id=\"statements\" class=\"org.apache.activemq.store.jdbc.Statements\">");
038            System.out.println("<property name=\"createSchemaStatements\">");
039            System.out.println("<list>");
040            for(int i=0; i<stats.length;i++){
041                    System.out.println("<value>"+stats[i]+"</value>");
042            }
043            System.out.println("</list>");
044            System.out.println("</property>");
045            
046            
047            Method[] methods=Statements.class.getMethods();
048            Pattern sPattern= Pattern.compile("get.*Statement$");
049            Pattern setPattern= Pattern.compile("set.*Statement$");
050            ArrayList<String> setMethods=new ArrayList<String>();
051            for(int i=0; i<methods.length;i++){
052                    if(setPattern.matcher(methods[i].getName()).find()){
053                            setMethods.add(methods[i].getName());
054                    }
055            }
056            for(int i=0; i<methods.length;i++){
057                    if(sPattern.matcher(methods[i].getName()).find()&&setMethods.contains(methods[i].getName().replace("get","set"))){
058                            System.out.println("<property name=\""+methods[i].getName().substring(3,4).toLowerCase()+methods[i].getName().substring(4)+"\" value=\""+returnStatement(methods[i].invoke(s, (Object[])null))+"\" />");
059                    }
060            }
061            //for a typo is not needed if removeMessageStatment typo is corrected
062            Pattern sPattern2= Pattern.compile("get.*Statment$");
063            for(int i=0; i<methods.length;i++){
064                    if(sPattern2.matcher(methods[i].getName()).find()){
065                            System.out.println("<property name=\""+methods[i].getName().substring(3,4).toLowerCase()+methods[i].getName().substring(4)+"\" value=\""+returnStatement(methods[i].invoke(s, (Object[])null))+"\" />");
066                    }
067            }
068            //end of generating because of typo
069            
070            String[] statsDrop=s.getDropSchemaStatements();
071            System.out.println("<property name=\"dropSchemaStatements\">");
072            System.out.println("<list>");
073            for(int i=0; i<statsDrop.length;i++){
074                    System.out.println("<value>"+statsDrop[i]+"</value>");
075            }
076            System.out.println("</list>");
077            System.out.println("</property>");
078            System.out.println("</bean>");
079            
080    
081            }
082    
083    }