activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r679095 [2/2] - in /activemq/sandbox/zookeeper: src/c/ zookeeper-all/ zookeeper-c/ zookeeper-core/ zookeeper-core/src/ zookeeper-core/src/main/ zookeeper-core/src/test/ zookeeper-jmx/ zookeeper-jmx/src/ zookeeper-jmx/src/main/ zookeeper-jmx...
Date Wed, 23 Jul 2008 14:48:07 GMT
Added: activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/JVector.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/JVector.java?rev=679095&view=auto
==============================================================================
--- activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/JVector.java
(added)
+++ activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/JVector.java
Wed Jul 23 07:48:05 2008
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.jute.compiler;
+
+/**
+ *
+ * @author Milind Bhandarkar
+ */
+public class JVector extends JCompType {
+    
+    static private int level = 0;
+    
+    static private String getId(String id) { return id+getLevel(); }
+    
+    static private String getLevel() { return Integer.toString(level); }
+    
+    static private void incrLevel() { level++; }
+    
+    static private void decrLevel() { level--; }
+    
+    private JType mElement;
+    
+    /** Creates a new instance of JVector */
+    public JVector(JType t) {
+        super("struct " + extractVectorName(t), " ::std::vector<"+t.getCppType()+">",
"java.util.List<" + t.getJavaType() + ">", "Vector", "java.util.ArrayList<" + t.getJavaType()
+ ">");
+        mElement = t;
+    }
+    
+    public String getSignature() {
+        return "[" + mElement.getSignature() + "]";
+    }
+    
+    public String genJavaCompareTo(String fname) {
+        return "";
+    }
+    
+    public String genJavaReadWrapper(String fname, String tag, boolean decl) {
+        StringBuffer ret = new StringBuffer("");
+        if (decl) {
+            ret.append("      java.util.List "+fname+";\n");
+        }
+        ret.append("    {\n");
+        incrLevel();
+        ret.append("      Index "+getId("vidx")+" = a_.startVector(\""+tag+"\");\n");
+        ret.append("      if ("+getId("vidx")+"!= null) {");
+        ret.append("          "+fname+"=new java.util.ArrayList<"+ mElement.getJavaType()
+ ">();\n");
+        ret.append("          for (; !"+getId("vidx")+".done(); "+getId("vidx")+".incr())
{\n");
+        ret.append(mElement.genJavaReadWrapper(getId("e"), getId("e"), true));
+        ret.append("            "+fname+".add("+getId("e")+");\n");
+        ret.append("          }\n");
+        ret.append("      }\n");
+        ret.append("    a_.endVector(\""+tag+"\");\n");
+        decrLevel();
+        ret.append("    }\n");
+        return ret.toString();
+    }
+    
+    public String genJavaReadMethod(String fname, String tag) {
+        return genJavaReadWrapper(fname, tag, false);
+    }
+    
+    public String genJavaWriteWrapper(String fname, String tag) {
+        StringBuffer ret = new StringBuffer("    {\n");
+        incrLevel();
+        ret.append("      a_.startVector("+fname+",\""+tag+"\");\n");
+        ret.append("      if ("+fname+"!= null) {");
+        ret.append("          int "+getId("len")+" = "+fname+".size();\n");
+        ret.append("          for(int "+getId("vidx")+" = 0; "+getId("vidx")+"<"+getId("len")+";
"+getId("vidx")+"++) {\n");
+        ret.append("            "+mElement.getJavaWrapperType()+" "+getId("e")+" = ("+mElement.getJavaWrapperType()+")
"+fname+".get("+getId("vidx")+");\n");
+        ret.append(mElement.genJavaWriteWrapper(getId("e"), getId("e")));
+        ret.append("          }\n");
+        ret.append("      }\n");
+        ret.append("      a_.endVector("+fname+",\""+tag+"\");\n");
+        ret.append("    }\n");
+        decrLevel();
+        return ret.toString();
+    }
+    
+    public String genJavaWriteMethod(String fname, String tag) {
+        return genJavaWriteWrapper(fname, tag);
+    }
+    
+    public JType getElementType() {
+    	return mElement;
+    }
+
+	static public String extractVectorName(JType jvType) {
+		return JRecord.extractMethodSuffix(jvType)+"_vector";
+	}
+}

Added: activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/JavaGenerator.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/JavaGenerator.java?rev=679095&view=auto
==============================================================================
--- activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/JavaGenerator.java
(added)
+++ activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/JavaGenerator.java
Wed Jul 23 07:48:05 2008
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.jute.compiler;
+
+import java.util.ArrayList;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Iterator;
+
+/**
+ * Java Code generator front-end for Hadoop record I/O.
+ *
+ * @author Milind Bhandarkar
+ */
+class JavaGenerator {
+    private String mName;
+    private ArrayList mInclFiles;
+    private ArrayList mRecList;
+    private final File outputDirectory;
+    
+    /** Creates a new instance of JavaGenerator
+     *
+     * @param name possibly full pathname to the file
+     * @param incl included files (as JFile)
+     * @param records List of records defined within this file
+     * @param outputDirectory 
+     */
+    JavaGenerator(String name, ArrayList incl, ArrayList records, File outputDirectory) {
+        mName = name;
+        mInclFiles = incl;
+        mRecList = records;
+        this.outputDirectory = outputDirectory;
+    }
+    
+    /**
+     * Generate Java code for records. This method is only a front-end to
+     * JRecord, since one file is generated for each record.
+     */
+    void genCode() throws IOException {
+        for (Iterator i = mRecList.iterator(); i.hasNext(); ) {
+            JRecord rec = (JRecord) i.next();
+            rec.genJavaCode(outputDirectory);
+        }
+    }
+}

Added: activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/JuteMojo.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/JuteMojo.java?rev=679095&view=auto
==============================================================================
--- activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/JuteMojo.java
(added)
+++ activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/JuteMojo.java
Wed Jul 23 07:48:05 2008
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.jute.compiler;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.jute.compiler.generated.ParseException;
+import org.apache.jute.compiler.generated.Rcc;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * A Maven Mojo so that the Jute compiler can be used with maven.
+ * 
+ * @goal compile
+ * @phase process-sources
+ */
+public class JuteMojo extends AbstractMojo {
+
+
+    /**
+     * The maven project.
+     * 
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project;
+
+    /**
+     * The directory where the jute files (<code>*.jute</code>) are located.
+     * 
+     * @parameter expression="${sourceDirectory}" default-value="${basedir}/src/main/jute"
+     */
+    private File sourceDirectory;
+
+    /**
+     * The directory where the output files will be located.
+     * 
+     * @parameter expression="${outputDirectory}" default-value="${project.build.directory}/generated-sources/jute"
+     */
+    private File outputDirectory;
+
+    /**
+     * 
+     * @parameter default-value="java"
+     * @required
+     */
+    private String language;
+
+    public void execute() throws MojoExecutionException {
+            
+            List<File> recFiles = Arrays.asList(sourceDirectory.listFiles(new FileFilter(){
+                public boolean accept(File pathname) {
+                    return pathname.getName().endsWith(".jute");
+                }
+            }));
+
+            if (!"c++".equals(language) && !"java".equals(language) && !"c".equals(language))
{
+                throw new MojoExecutionException("Cannot recognize language:" + language);
+            }
+            if (recFiles.size() == 0) {
+                getLog().warn("No jute record files found in directory: "+sourceDirectory.getPath());
+                return;
+            }
+            for (File file : recFiles) {
+                JFile result;
+                try {
+                    result = Rcc.parseFile(file);
+                } catch (FileNotFoundException e) {
+                    throw new MojoExecutionException("File " + file.getPath()+" Not found.",
e);
+                } catch (ParseException e) {
+                    throw new MojoExecutionException(e.toString(), e);
+                }
+                getLog().info(file.getPath()+ " Parsed Successfully");
+                try {
+                    result.genCode(language, outputDirectory);
+                } catch (IOException e) {
+                    throw new MojoExecutionException(e.toString(), e);
+                }
+            }
+
+        this.project.addCompileSourceRoot( outputDirectory.getAbsolutePath() );
+    }
+
+
+}

Added: activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/package.html
URL: http://svn.apache.org/viewvc/activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/package.html?rev=679095&view=auto
==============================================================================
--- activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/package.html
(added)
+++ activemq/sandbox/zookeeper/zookeeper-jute-compiler/src/main/java/org/apache/jute/compiler/package.html
Wed Jul 23 07:48:05 2008
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+
+<html>
+  <head>
+    <title>Hadoop Record Compiler</title>
+  </head>
+  <body>
+  This package contains classes needed for code generation
+  from the hadoop record compiler. CppGenerator and JavaGenerator
+  are the main entry points from the parser. There are classes
+  corrsponding to every primitive type and compound type
+  included in Hadoop record I/O syntax.
+  </body>
+</html>

Added: activemq/sandbox/zookeeper/zookeeper-jute/pom.xml
URL: http://svn.apache.org/viewvc/activemq/sandbox/zookeeper/zookeeper-jute/pom.xml?rev=679095&view=auto
==============================================================================
--- activemq/sandbox/zookeeper/zookeeper-jute/pom.xml (added)
+++ activemq/sandbox/zookeeper/zookeeper-jute/pom.xml Wed Jul 23 07:48:05 2008
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF 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.apache.zookeeper</groupId>
+    <artifactId>zookeeper-pom</artifactId>
+    <version>3.0.0-SNAPSHOT</version>
+  </parent>
+
+  <groupId>org.apache.zookeeper</groupId>
+  <artifactId>zookeeper-jute</artifactId>
+  <version>3.0.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>ZooKeeper :: Jute Runtime</name>
+  <description></description>
+
+</project>
\ No newline at end of file



Mime
View raw message