1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 //     * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //     * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 //     * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 package com.google.protobuf;
32 
33 import com.google.protobuf.testing.Proto2Testing;
34 import com.google.protobuf.testing.Proto2Testing.Proto2Empty;
35 import com.google.protobuf.testing.Proto2Testing.Proto2Message;
36 import com.google.protobuf.testing.Proto2Testing.Proto2MessageWithExtensions;
37 import com.google.protobuf.testing.Proto2Testing.Proto2MessageWithMaps;
38 import com.google.protobuf.testing.Proto3Testing.Proto3Empty;
39 import com.google.protobuf.testing.Proto3Testing.Proto3Message;
40 import com.google.protobuf.testing.Proto3Testing.Proto3MessageWithMaps;
41 
42 /** Schemas to support testing. */
43 public class TestSchemas {
44   public static final Schema<Proto2Message> genericProto2Schema =
45       new ManifestSchemaFactory().createSchema(Proto2Message.class);
46   public static final Schema<Proto3Message> genericProto3Schema =
47       new ManifestSchemaFactory().createSchema(Proto3Message.class);
48 
registerGenericProto2Schemas()49   public static void registerGenericProto2Schemas() {
50     registerProto2Schemas();
51   }
52 
registerGenericProto3Schemas()53   public static void registerGenericProto3Schemas() {
54     registerProto3Schemas();
55   }
56 
registerProto2Schemas()57   private static void registerProto2Schemas() {
58     Protobuf protobuf = Protobuf.getInstance();
59     ManifestSchemaFactory factory = new ManifestSchemaFactory();
60     protobuf.registerSchemaOverride(Proto2Message.class, factory.createSchema(Proto2Message.class));
61     protobuf.registerSchemaOverride(
62         Proto2Message.FieldGroup49.class, factory.createSchema(Proto2Message.FieldGroup49.class));
63     protobuf.registerSchemaOverride(
64         Proto2Message.FieldGroupList51.class,
65         factory.createSchema(Proto2Message.FieldGroupList51.class));
66     protobuf.registerSchemaOverride(
67         Proto2Message.FieldGroup69.class, factory.createSchema(Proto2Message.FieldGroup69.class));
68     protobuf.registerSchemaOverride(
69         Proto2Message.RequiredNestedMessage.class,
70         factory.createSchema(Proto2Message.RequiredNestedMessage.class));
71     protobuf.registerSchemaOverride(
72         Proto2Message.FieldRequiredGroup88.class,
73         factory.createSchema(Proto2Message.FieldRequiredGroup88.class));
74     protobuf.registerSchemaOverride(Proto2Empty.class, factory.createSchema(Proto2Empty.class));
75     protobuf.registerSchemaOverride(
76         Proto2MessageWithExtensions.class, factory.createSchema(Proto2MessageWithExtensions.class));
77     protobuf.registerSchemaOverride(
78         Proto2Testing.FieldGroup49.class, factory.createSchema(Proto2Testing.FieldGroup49.class));
79     protobuf.registerSchemaOverride(
80         Proto2Testing.FieldGroupList51.class,
81         factory.createSchema(Proto2Testing.FieldGroupList51.class));
82     protobuf.registerSchemaOverride(
83         Proto2MessageWithMaps.class, factory.createSchema(Proto2MessageWithMaps.class));
84   }
85 
registerProto3Schemas()86   private static void registerProto3Schemas() {
87     Protobuf protobuf = Protobuf.getInstance();
88     ManifestSchemaFactory factory = new ManifestSchemaFactory();
89     protobuf.registerSchemaOverride(Proto3Message.class, factory.createSchema(Proto3Message.class));
90     protobuf.registerSchemaOverride(Proto3Empty.class, factory.createSchema(Proto3Empty.class));
91     protobuf.registerSchemaOverride(
92         Proto3MessageWithMaps.class, factory.createSchema(Proto3MessageWithMaps.class));
93   }
94 }
95