// $Id$
//
// 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.
//
using System;
using System.Collections.Generic;
using Org.Apache.Etch.Bindings.Csharp.Msg;
namespace Org.Apache.Etch.Bindings.Csharp.Transport
{
public abstract class FormatFactory
{
public const String BINARY = "binary";
public const String XML = "xml";
///
///
///
///
///
/// the tagged data input with the specified value factory and
/// initialized by terms from the uri.
abstract public TaggedDataInput NewTaggedDataInput( ValueFactory vf, string uri );
///
///
///
///
///
/// the tagged data output with the specified value factory and
/// initialized by terms from the uri.
abstract public TaggedDataOutput NewTaggedDataOutput( ValueFactory vf, string uri );
private readonly static Dictionary formatFactories = new Dictionary();
///
/// Gets the named format factory.
///
/// the name of a configured format factory.
/// the named format factory, or null if it isn't defined.
public static FormatFactory Get( String name )
{
Object factory = formatFactories[name];
if (factory == null)
return null;
if (factory is string)
{
try
{
Type c = Type.GetType((string) factory);
factory = Activator.CreateInstance(c);
if (!(factory is FormatFactory))
throw new ArgumentException(
String.Format(" Instance for format name {0} does not implement FormatFactory {1}", name, factory));
// formatFactories.Add(name,factory);
}
catch(Exception e)
{
throw new ArgumentException(" Could not create instance of format name " + name,e);
}
}
return (FormatFactory) factory;
}
///
/// Puts a named format factory.
///
/// the uri scheme of this format factory.
/// thefully qualified class name or instance
/// of the FormatFactory to associate with the name
public static void Put( String name, Object factory )
{
formatFactories.Add( name, factory );
}
static FormatFactory()
{
Put(BINARY, "Org.Apache.Etch.Bindings.Csharp.Transport.Fmt.Binary.BinaryTaggedDataFormatFactory");
}
}
}