• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 package com.google.protobuf;
9 
10 @CheckReturnValue
11 final class ExtensionSchemas {
12   private static final ExtensionSchema<?> LITE_SCHEMA = new ExtensionSchemaLite();
13   private static final ExtensionSchema<?> FULL_SCHEMA = loadSchemaForFullRuntime();
14 
loadSchemaForFullRuntime()15   private static ExtensionSchema<?> loadSchemaForFullRuntime() {
16     if (Protobuf.assumeLiteRuntime) {
17       return null;
18     }
19     try {
20       Class<?> clazz = Class.forName("com.google.protobuf.ExtensionSchemaFull");
21       return (ExtensionSchema) clazz.getDeclaredConstructor().newInstance();
22     } catch (Exception e) {
23       return null;
24     }
25   }
26 
lite()27   static ExtensionSchema<?> lite() {
28     return LITE_SCHEMA;
29   }
30 
full()31   static ExtensionSchema<?> full() {
32     if (FULL_SCHEMA == null) {
33       throw new IllegalStateException("Protobuf runtime is not correctly loaded.");
34     }
35     return FULL_SCHEMA;
36   }
37 
ExtensionSchemas()38   private ExtensionSchemas() {}
39 }
40