001/* 002 * Copyright (c) 2021, Oracle and/or its affiliates. 003 * 004 * Licensed under the 2-clause BSD license. 005 * 006 * Redistribution and use in source and binary forms, with or without 007 * modification, are permitted provided that the following conditions are met: 008 * 009 * 1. Redistributions of source code must retain the above copyright notice, 010 * this list of conditions and the following disclaimer. 011 * 012 * 2. Redistributions in binary form must reproduce the above copyright notice, 013 * this list of conditions and the following disclaimer in the documentation 014 * and/or other materials provided with the distribution. 015 * 016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 017 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 018 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 019 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 020 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 021 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 022 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 023 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 024 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 025 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 026 * POSSIBILITY OF SUCH DAMAGE. 027 */ 028 029package com.oracle.labs.mlrg.olcut.config.protobuf; 030 031import com.oracle.labs.mlrg.olcut.config.ConfigurationData; 032import com.oracle.labs.mlrg.olcut.config.SerializedObject; 033import com.oracle.labs.mlrg.olcut.config.io.ConfigLoader; 034import com.oracle.labs.mlrg.olcut.config.io.ConfigLoaderException; 035import com.oracle.labs.mlrg.olcut.config.io.ConfigWriter; 036import com.oracle.labs.mlrg.olcut.config.io.ConfigWriterException; 037import com.oracle.labs.mlrg.olcut.config.io.FileFormatFactory; 038import com.oracle.labs.mlrg.olcut.config.io.URLLoader; 039import com.oracle.labs.mlrg.olcut.config.property.GlobalProperties; 040 041import java.io.IOException; 042import java.io.OutputStream; 043import java.util.Map; 044 045/** 046 * Configuration factory for reading and writing protobuf format configuration files. 047 */ 048public final class ProtoConfigFactory implements FileFormatFactory { 049 050 /** 051 * Construct a ProtoConfigFactory 052 */ 053 public ProtoConfigFactory() {} 054 055 @Override 056 public String getExtension() { 057 return "pb"; 058 } 059 060 @Override 061 public ConfigLoader getLoader(URLLoader parent, Map<String, ConfigurationData> rpdMap, 062 Map<String, ConfigurationData> existingRPD, 063 Map<String, SerializedObject> serializedObjects, 064 GlobalProperties globalProperties) throws ConfigLoaderException { 065 return new ProtoLoader(parent,rpdMap,existingRPD,serializedObjects,globalProperties,false); 066 } 067 068 @Override 069 public ConfigWriter getWriter(OutputStream writer) throws ConfigWriterException { 070 return new ProtoConfigWriter(writer,false); 071 } 072}