chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1039269 - in /incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator: ./ src/ src/antlr/ src/antlr/org/ src/antlr/org/apache/ src/antlr/org/apache/chemistry/ src/antlr/org/apache/chemistry/opencmis/ src/antlr/org/apache/chemist...
Date Fri, 26 Nov 2010 08:38:59 GMT
Author: jens
Date: Fri Nov 26 08:38:59 2010
New Revision: 1039269

URL: http://svn.apache.org/viewvc?rev=1039269&view=rev
Log:
start with creating an experimental validator for Orderliy in Java (useful for the browser
binding integration)

Added:
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/build.xml
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/antlr/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/antlr/org/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/antlr/org/apache/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/antlr/org/apache/chemistry/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/antlr/org/apache/chemistry/opencmis/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/antlr/org/apache/chemistry/opencmis/orderly/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/antlr/org/apache/chemistry/opencmis/orderly/Orderly.g
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/java/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/java/org/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/java/org/apache/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/java/org/apache/chemistry/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/java/org/apache/chemistry/opencmis/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/java/org/apache/chemistry/opencmis/orderly/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/java/org/apache/chemistry/opencmis/orderly/validate/
    incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/java/org/apache/chemistry/opencmis/orderly/validate/Validator.java

Added: incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/build.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/build.xml?rev=1039269&view=auto
==============================================================================
--- incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/build.xml (added)
+++ incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/build.xml Fri Nov 26
08:38:59 2010
@@ -0,0 +1,93 @@
+<project name="orderlyvalidator" basedir="." default="compile">
+
+    <!-- properties for location of directories and files used in build -->
+    <property name="java.src.dir"   value="src/java"/>
+    <property name="build.dir"      value="build"/>
+    <property name="antgen.src.dir" value="${build.dir}/generated-sources/antlr3"/>
+    <property name="testsrc.dir"    value="testsrc"/>
+    <property name="antlr.jar.dir"  value="C:/Java/maven-repository/org/antlr/antlr/3.2"
/>
+    <property name="antlr.jar.file" value="antlr-3.2.jar" />
+	<property name="jackson.dir"    value="C:/Java/jackson-1.5.6/" />
+    <property name="antlr.jar"      value="${antlr.jar.dir}/${antlr.jar.file}" />
+	<property name="package"        value="org/apache/chemistry/opencmis/orderly"/>
+    <property name="grammar.dir"    value="src/antlr/${package}"/>
+    <property name="grammar.name"   value="Orderly.g"/>
+    <property name="classes.dir"    value="${build.dir}/classes"/>
+    <property name="jar.dir"        value="${build.dir}/jar"/>
+	
+    <!-- Path settings used for classpath and execution  -->
+    <path id="base.path">
+      <pathelement path="${classpath}"/>
+	    <fileset dir="${antlr.jar.dir}">
+		  <include name="${antlr.jar.file}"/>		
+	    </fileset>
+		
+        <fileset dir="${jackson.dir}">
+          <include name="jackson-core-asl-1.5.6.jar" />
+          <include name="jackson-mapper-asl-1.5.6.jar" />
+        </fileset>
+      <!-- <pathelement location="$classes"/> -->
+    </path>
+
+    <!-- build targets for cleaning before build, antlr code generation, javac
+         compilation, jar creation and running of the tests -->
+    <target name="clean">
+        <delete dir="${build.dir}"/>
+    </target>
+
+    <property name="antlr.libdir" location="./antlr3" />
+    
+    <property name="antlr.libdir" location="./antlr3" />
+    <patternset id="antlr.libs">
+        <include name="antlr-3.2.jar" />
+    </patternset>
+
+    <target name="init">
+        <!-- Create the time stamp -->
+        <tstamp />
+        <mkdir dir="${antgen.src.dir}/${package}" />
+        <mkdir dir="${classes.dir}/${package}" />
+    </target>
+ 
+    <target name="antlr" depends="init" description="run antlr on grammar">
+        <echo message="antlr ${grammar.dir}/${grammar.name}" />
+        <antlr:antlr3 xmlns:antlr="antlib:org/apache/tools/ant/antlr"
+            target="${grammar.dir}/${grammar.name}"
+               outputdirectory="${antgen.src.dir}/${package}"
+			   libdirectory="${antgen.src.dir}"
+               multithreaded="false"
+               report="false"
+               profile="false">
+        </antlr:antlr3>
+    </target>
+	
+    <target name="compile" depends="antlr">
+        <mkdir dir="${classes.dir}"/>
+        <javac srcdir="${antgen.src.dir}" destdir="${classes.dir}">
+		    <classpath refid="base.path"/>
+		</javac>
+        <javac srcdir="${java.src.dir}" destdir="${classes.dir}">
+		    <classpath refid="base.path"/>
+		</javac>
+    </target>
+
+    <target name="jar" depends="compile">
+        <mkdir dir="${jar.dir}"/>
+        <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
+<!--		
+            <manifest>
+                <attribute name="Main-Class" value="${main-class}"/>
+			<attribute name="Class-Path" value="${antlr.jar}" />
+		</manifest>
+-->		
+           <fileset dir="${antgen.src.dir}" />
+        </jar>
+    </target>
+
+    <target name="run" depends="jar">
+	    <java jar="${jar.dir}/${ant.project.name}.jar" fork="true" input="${test-file}"/>
+    </target>
+
+    <target name="clean-build" depends="clean,jar"/>
+
+</project>

Added: incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/antlr/org/apache/chemistry/opencmis/orderly/Orderly.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/antlr/org/apache/chemistry/opencmis/orderly/Orderly.g?rev=1039269&view=auto
==============================================================================
--- incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/antlr/org/apache/chemistry/opencmis/orderly/Orderly.g
(added)
+++ incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/antlr/org/apache/chemistry/opencmis/orderly/Orderly.g
Fri Nov 26 08:38:59 2010
@@ -0,0 +1,302 @@
+/*
+ * 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.
+ *
+ */
+
+grammar Orderly;
+
+options {
+  language = Java;
+  output = AST;
+}
+
+@header {
+/*
+ * THIS FILE IS AUTO-GENERATED, DO NOT EDIT.
+ *
+ * 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.
+ *
+ *
+ * THIS FILE IS AUTO-GENERATED, DO NOT EDIT.
+ */
+package org.apache.chemistry.opencmis.orderly;
+import java.util.Map;
+import java.util.HashMap;
+}
+
+@lexer::header{ 
+package org.apache.chemistry.opencmis.orderly;
+}
+
+@main {
+}
+
+orderly_schema returns [Object result]
+	: e=unnamed_entries? ';'? {$result = $e.result; }
+	;
+
+named_entries returns [Map<Object,Object> result]
+@init {
+	Map<Object,Object> map = new HashMap<Object,Object>();
+}
+@after{
+$result = map;
+}
+	: e=named_entry[map] { } (
+      ';' e2=named_entry[map] { }
+      )*
+    ;
+
+unnamed_entries returns [Object result] 
+@init {
+	List<Object> arr = new ArrayList<Object>();
+}
+@after{
+$result = (arr.size() > 1 ? arr : arr.get(0));
+System.out.println("unnamed_entries return type " + $result.getClass().getName());
+}
+	: e=unnamed_entry { arr.add($e.result); } (
+      ';' e2=unnamed_entry {  arr.add($e2.result); }
+      )*;
+
+named_entry [Map<Object,Object> parentMap]
+@init {
+	Map<Object,Object> map = new HashMap<Object,Object>();
+}
+  :  (definition_prefix[map] name=property_name definition_suffix[map]) {parentMap.put($name.result,
map);}
+  |  (string_prefix[map] name=property_name string_suffix[map])         {parentMap.put($name.result,
map);}
+  ;
+
+unnamed_entry returns [Map<Object,Object> result]
+@init {
+	Map<Object,Object> map = new HashMap<Object,Object>();
+}
+@after{
+    $result = map;
+}
+  :  definition_prefix[map] definition_suffix[map]
+  |  string_prefix[map] string_suffix[map]
+  ;
+
+definition_prefix[Map<Object, Object> map]
+  :  'integer' rng=optional_range[map]?   { map.put("type", "integer"); }
+  |  'number' rng=optional_range[map]?    { map.put("type", "number"); }
+  |  'boolean'                       { map.put("type", "boolean"); }
+  |  'null'                          { map.put("type", "null"); }
+  |  'any'                           { map.put("any", "null"); }
+  |  'array' (
+      ('{' e1=unnamed_entries? ';'? '}' o=optional_additional_marker[map]? rng=optional_range[map]?)
    
+      { 
+          map.put("type", "array"); 
+          map.put("items", $e1.result); 
+      }
+)//      | ('[' e2=unnamed_entry? ';'? ']' rng=optional_range[map]?)) { /*map.put("type",
"array"); map.put("items", $e2.result); */}
+  |  'object' '{' e3=named_entries? ';'? '}' o=optional_additional_marker[map]?  { map.put("type",
"object"); map.put("properties", $e3.result);}
+  |  'union'  '{' e1=unnamed_entries? ';'? '}'   { map.put("type", $e1.result); }    
+  ;
+ 
+string_prefix[Map<Object, Object> map]
+    :  
+	'string' rng=optional_range[map]? {map.put("type", "string");}
+	;
+
+string_suffix [Map<Object, Object> map]
+    :  
+	regex=OPTIONAL_PERL_REGEX? definition_suffix[map] { 
+		if ($regex != null)
+			map.put("pattern", $OPTIONAL_PERL_REGEX.text); 
+	}
+	;
+
+definition_suffix [Map<Object, Object> map]
+	:
+	enums=optional_enum_values?  { if (enums!= null && enums.result != null) map.put("enum",
enums.result);}
+	def=optional_default_value? { if (def!= null && def.result != null) map.put("default",
def.result);}
+	requires=optional_requires? { if (requires!= null &&requires.result != null) map.put("requires",
requires.result);}
+	optional=optional_optional_marker[map]?
+	extra=optional_extra_properties? { if (extra!= null && extra.result != null) map.putAll($extra.result);}
+	;
+
+csv_property_names returns [Object result]
+@init {
+	List<Object> csvs = new ArrayList<Object>();
+}	
+@after{
+$result = csvs;
+}
+   :
+    prop=property_name          { csvs.add($prop.result);}
+    (  ',' prop2=property_name  { csvs.add($prop2.result);}
+    ) * { }
+	;
+
+optional_extra_properties returns [Map<Object, Object> result]
+    :  ('`' obj=json_object '`') {$result=$obj.result;}
+	;
+
+optional_requires returns [Object result]
+    :  ('<' p=csv_property_names '>') {$result = $p.result;}
+	;
+
+optional_optional_marker [Map<Object, Object> map]
+	: OPTIONAL_OPTIONAL_MARKER {map.put("optional", true); }
+	;
+
+optional_additional_marker[Map<Object, Object> map]
+	: OPTIONAL_ADDITIONAL_MARKER {map.put("additionalProperties", true); };
+
+optional_enum_values returns [Object result]
+    : arr=json_array {$result = $arr.result;}
+	;
+
+optional_default_value returns [Object result]
+    : ('=' d=json_value) {$result = $d.result;}
+	;
+
+optional_range[Map<Object, Object> map]  
+    : '{' s=json_number? ',' e=json_number? '}' { map.put("minimum", $s.result); map.put("maximum",
$e.result); }
+	;
+
+property_name returns [Object result]
+  : s=json_string                             {$result = $s.result;}
+  | r=PROPERTY_NAME_TOKEN                     {$result = $r.text;}
+  ;
+
+///////////// JSON  //////////////////////////
+
+json_object returns [Map<Object, Object> result]
+   :  '{' m=members? '}' {$result = $m.result;};
+
+members  returns [Map<Object, Object> result]
+@init { 
+	Map<Object, Object> map = new HashMap<Object, Object>();
+}
+@after {
+ $result = map;
+}
+	:
+	pair[map] (',' pair[map] )* {$result = map;}
+	;
+
+pair[Map<Object, Object> map]
+	:  
+	k=json_string ':' v=json_value { map.put($k.result, $v.result);}
+	;
+
+json_array  returns [List<Object> result]
+    : 
+	'[' elem=elements? ']' {$result = $elem.result;}
+	;
+
+json_number  returns [Object result]
+	: 
+	NUM_LIT
+    {
+        try {
+            $result = Long.valueOf($NUM_LIT.text);
+        } catch (NumberFormatException e) {
+            $result = Double.valueOf($NUM_LIT.text);
+        }
+    }	
+	;
+
+elements returns [List<Object> result]
+@init {
+    List<Object> values = new ArrayList<Object>();
+}
+@after {
+    $result = values; 
+} 
+	: 
+	v=json_value {values.add($v.result); }
+	(',' v2=json_value {values.add($v2.result); }
+	)*
+	;
+
+json_value returns [Object result]
+  :  val1=json_string                          {$result = $val1.result;}
+  |  val2=json_number                          {$result = $val2.result;}
+  |  val3=json_object                          {$result = $val3.result;}
+  |  val4=json_array                           {$result = $val4.result;}
+  |  'true'                                    {$result = Boolean.TRUE;}
+  |  'false'                                   {$result = Boolean.FALSE;}
+  |  'null'                                    {$result = null;}
+  ;
+
+json_string returns [String result]
+	: 
+	STRING {$result=$STRING.text;}
+	;
+
+// ----------------------------------------
+
+OPTIONAL_OPTIONAL_MARKER : '?' ;
+
+OPTIONAL_ADDITIONAL_MARKER : '*' ;
+
+PROPERTY_NAME_TOKEN : ('a' .. 'z' | 'A' .. 'Z' | '_' | '-' )+;
+
+OPTIONAL_PERL_REGEX : ('/' ( (~'/') | '\\/' )+ '/');
+
+WS : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+   { $channel = HIDDEN; } ;
+
+COMMENT : ('//' | '#') (~'\n')* {$channel = HIDDEN; };
+
+fragment
+QUOTE_OR_BACKSLASH_OR_CONTROL_CHARACTER
+  :  '"'
+  |  '\\'
+  |  '\\' .
+  ;
+
+STRING  :  '"' ~'"'* '"';
+
+fragment
+HEX  :  'a'..'f'
+  |  'A'..'F'
+  |  '0'..'9';
+
+ESC : '\\\\' ;
+
+/*
+integer : '-'? ('0'..'9')+ ;
+exp     : ('e' | 'E') ('-' | '+') ?  ('0' .. '9')+ ;
+frac    : '.' ('0' .. '9')+ ;
+NUM_LIT : integer frac? exp?;
+*/
+fragment Sign : ('+'|'-')?;
+fragment Digits : ('0'..'9')+;
+fragment FloatBase : Digits DOT Digits | Digits DOT | DOT Digits | Digits;
+fragment ExpNumLit : ('e'|'E') Sign Digits;
+DOT : '.';
+NUM_LIT : Sign FloatBase ExpNumLit?;

Added: incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/java/org/apache/chemistry/opencmis/orderly/validate/Validator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/java/org/apache/chemistry/opencmis/orderly/validate/Validator.java?rev=1039269&view=auto
==============================================================================
--- incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/java/org/apache/chemistry/opencmis/orderly/validate/Validator.java
(added)
+++ incubator/chemistry/playground/chemistry-opencmis-orderlyvalidator/src/java/org/apache/chemistry/opencmis/orderly/validate/Validator.java
Fri Nov 26 08:38:59 2010
@@ -0,0 +1,75 @@
+/*
+ * 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.chemistry.opencmis.orderly.validate;
+
+import java.io.FileInputStream;
+import java.io.File;
+
+
+import java.util.Map;
+
+import org.antlr.runtime.ANTLRInputStream;
+import org.antlr.runtime.CharStream;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.TokenSource;
+import org.antlr.runtime.TokenStream;
+import org.antlr.runtime.tree.CommonTree;
+import org.apache.chemistry.opencmis.orderly.OrderlyLexer;
+import org.apache.chemistry.opencmis.orderly.OrderlyParser;
+import org.apache.chemistry.opencmis.orderly.OrderlyParser.orderly_schema_return;
+import org.codehaus.jackson.map.ObjectMapper;
+
+public class Validator {
+
+    /**
+     * @param args
+     */
+    public static void main(String[] args) {
+        if (args.length < 0 || args.length > 1) {
+            System.err.println("Usage: Validator <file-name>");
+            System.exit(1);
+        }
+        try {
+            CharStream input = new ANTLRInputStream(new FileInputStream(args[0]));
+            TokenSource lexer = new OrderlyLexer(input);
+            TokenStream tokens = new CommonTokenStream(lexer);
+            OrderlyParser parser = new OrderlyParser(tokens);
+
+            orderly_schema_return result = parser.orderly_schema();
+            CommonTree parserTree = (CommonTree) result.getTree();
+            System.out.println("tree="+parserTree.toStringTree()); 
+            
+            // Extract hashmap from parsed tree
+            Object untyped = result.result;
+            System.err.println("Parser result map " + untyped);
+
+            ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
+            mapper.writeValue(System.out, untyped);
+            mapper.writeValue(new File("json-schema.json"), untyped);
+
+
+        } catch (Exception e) {
+            System.err.println("Error parsing inout file " + args[0] + ": " + e);
+            e.printStackTrace();
+        }
+        
+
+    }
+
+}



Mime
View raw message