From 132aa8a77685ec92bc90c03f987650d275a7b639 Mon Sep 17 00:00:00 2001 From: lresende Date: Mon, 30 Sep 2013 06:59:11 +0000 Subject: 2.0.1 RC1 release tag git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1527464 13f79535-47bb-0310-9956-ffa450edef68 --- .../provider/types/util/TypeHelpersProxy.java | 119 +++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/provider/types/util/TypeHelpersProxy.java (limited to 'sca-java-2.x/tags/2.0.1-RC1/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/provider/types/util/TypeHelpersProxy.java') diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/provider/types/util/TypeHelpersProxy.java b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/provider/types/util/TypeHelpersProxy.java new file mode 100644 index 0000000000..ded82bf12e --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/provider/types/util/TypeHelpersProxy.java @@ -0,0 +1,119 @@ +/* + * 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. + */ + +package org.apache.tuscany.sca.binding.corba.provider.types.util; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.binding.corba.provider.types.NodeType; +import org.apache.tuscany.sca.binding.corba.provider.types.TypeTreeNode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +/** + * @version $Rev$ $Date$ + * Proxies getType(), write(), read() methods to appropriate TypeHelper implementation. + */ +public class TypeHelpersProxy { + + /** + * Maps primitive types to its TypeHelper implementations + */ + private static Map, TypeHelper> primitiveTypes = null; + + /** + * Maps other types to its TypeHelper implementations + */ + private static Map complexTypes = null; + + static { + // initiate type helpers + primitiveTypes = new HashMap, TypeHelper>(); + complexTypes = new HashMap(); + + primitiveTypes.put(boolean.class, new BooleanTypeHelper()); + primitiveTypes.put(char.class, new CharTypeHelper()); + primitiveTypes.put(byte.class, new ByteTypeHelper()); + primitiveTypes.put(short.class, new ShortTypeHelper()); + primitiveTypes.put(int.class, new IntTypeHelper()); + primitiveTypes.put(long.class, new LongTypeHelper()); + primitiveTypes.put(float.class, new FloatTypeHelper()); + primitiveTypes.put(double.class, new DoubleTypeHelper()); + primitiveTypes.put(String.class, new StringTypeHelper()); + primitiveTypes.put(Boolean.class, primitiveTypes.get(boolean.class)); + primitiveTypes.put(Character.class, primitiveTypes.get(char.class)); + primitiveTypes.put(Byte.class, primitiveTypes.get(byte.class)); + primitiveTypes.put(Short.class, primitiveTypes.get(short.class)); + primitiveTypes.put(Integer.class, primitiveTypes.get(int.class)); + primitiveTypes.put(Long.class, primitiveTypes.get(long.class)); + primitiveTypes.put(Float.class, primitiveTypes.get(float.class)); + primitiveTypes.put(Double.class, primitiveTypes.get(double.class)); + primitiveTypes.put(String.class, primitiveTypes.get(String.class)); + complexTypes.put(NodeType.array, new ArrayTypeHelper()); + complexTypes.put(NodeType.struct, new StructTypeHelper()); + complexTypes.put(NodeType.reference, new ReferenceTypeHelper()); + complexTypes.put(NodeType.sequence, new SequenceTypeHelper()); + complexTypes.put(NodeType.idl_enum, new EnumTypeHelper()); + complexTypes.put(NodeType.exception, new StructTypeHelper()); + complexTypes.put(NodeType.union, new UnionTypeHelper()); + } + + /** + * Gets type helper basing on given type + * + * @param node + * @return + */ + private static TypeHelper getTypeHelper(TypeTreeNode node) { + TypeHelper typeHelper = null; + NodeType type = node.getNodeType(); + if (type.equals(NodeType.primitive)) { + typeHelper = primitiveTypes.get(node.getJavaClass()); + } else { + typeHelper = complexTypes.get(type); + } + return typeHelper; + } + + /** + * Proxies read method invocation to appropriate TypeHelper implementation. + * + * @param node + * @param is + * @return + */ + public static final Object read(TypeTreeNode node, InputStream is) { + TypeHelper helper = getTypeHelper(node); + return helper.read(node, is); + } + + /** + * Proxies write method invocation to appropriate TypeHelper implementation. + * + * @param node + * @param os + * @param data + */ + public static final void write(TypeTreeNode node, OutputStream os, Object data) { + TypeHelper helper = getTypeHelper(node); + helper.write(node, os, data); + } + +} -- cgit v1.2.3