clesaec commented on code in PR #2513:
URL: https://github.com/apache/avro/pull/2513#discussion_r1400281529


##########
lang/java/avro/src/main/java/org/apache/avro/ParseContext.java:
##########
@@ -0,0 +1,292 @@
+/*
+ * 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
+ *
+ *     https://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.avro;
+
+import org.apache.avro.util.SchemaResolver;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Class to define a name context, useful to reference schemata with. This
+ * allows for the following:
+ *
+ * <ul>
+ * <li>Provide a default namespace for nested contexts, as found for example in
+ * JSON based schema definitions.</li>
+ * <li>Find schemata by name, including primitives.</li>
+ * <li>Collect new named schemata.</li>
+ * </ul>
+ *
+ * <p>
+ * Note: this class has no use for most Avro users, but is a key component when
+ * implementing a schema parser.
+ * </p>
+ *
+ * @see <a href="https://avro.apache.org/docs/current/specification/";>JSON 
based
+ *      schema definition</a>
+ **/
+public class ParseContext {
+  private static final Map<String, Schema.Type> PRIMITIVES = new HashMap<>();
+
+  static {
+    PRIMITIVES.put("string", Schema.Type.STRING);
+    PRIMITIVES.put("bytes", Schema.Type.BYTES);
+    PRIMITIVES.put("int", Schema.Type.INT);
+    PRIMITIVES.put("long", Schema.Type.LONG);
+    PRIMITIVES.put("float", Schema.Type.FLOAT);
+    PRIMITIVES.put("double", Schema.Type.DOUBLE);
+    PRIMITIVES.put("boolean", Schema.Type.BOOLEAN);
+    PRIMITIVES.put("null", Schema.Type.NULL);
+  }
+
+  private static final Set<Schema.Type> NAMED_SCHEMA_TYPES = 
EnumSet.of(Schema.Type.RECORD, Schema.Type.ENUM,
+      Schema.Type.FIXED);
+  private final Map<String, Schema> oldSchemas;
+  private final Map<String, Schema> newSchemas;
+  // Visible for use in JsonSchemaParser
+  final NameValidator nameValidator;
+  private final String namespace;

Review Comment:
   Yes, i think it's possible to remove "namespace" field from ParseContext 
class even without changing much current code as both Schema.parseNames... and 
IDLReader have their own "default namespace" stack (with function call stack 
for the first and  `private final Deque<String> namespaces;` field for second)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to