Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.HashMap;

import java.lang.reflect.Modifier;

public class Main {
    private static HashMap<String, Long> unoTypes = new HashMap<String, Long>();
    private static HashMap<Long, Class<?>> unoFallbacks = new HashMap<Long, Class<?>>();
    private static HashMap<Class<?>, Long> unoFallbacksClassToPtr = new HashMap<Class<?>, Long>();

    public static long JavaToUnoType(Object obj, long fallbackTypePtr, boolean typeHasFallbackClass)
            throws ClassNotFoundException {
        Class<?> firstCls = obj.getClass();
        Long unoTypePtr = unoTypes.get(firstCls.getName());
        if (unoTypePtr != null) {
            return (long) unoTypePtr;
        } else {
            if (typeHasFallbackClass) {
                Class<?> itf = unoFallbacks.get(fallbackTypePtr);
                if (itf == null) {
                    throw new ClassNotFoundException(
                            "BINDING CLASS NOT FOUND (unoFallbacks): Not found for unoTypePtr:" + fallbackTypePtr);
                }
                Class<?> currentCls = firstCls;
                while (true) {
                    if ((!itf.equals(currentCls)) && itf.isAssignableFrom(currentCls)) {
                        Long potential = unoTypes.get(currentCls.getName());
                        if (potential != null) {
                            unoTypes.put(firstCls.getName(), potential);
                            return (long) potential;
                        }
                    } else {
                        unoTypes.put(firstCls.getName(), fallbackTypePtr);
                        return fallbackTypePtr;
                    }
                    currentCls = currentCls.getSuperclass();
                    if (currentCls == null) {
                        unoTypes.put(firstCls.getName(), fallbackTypePtr);
                        return fallbackTypePtr;
                    }
                }
            } else {
                Class<?> currentCls = firstCls;
                while (true) {
                    currentCls = currentCls.getSuperclass();
                    if (currentCls == null) {
                        unoTypes.put(firstCls.getName(), fallbackTypePtr);
                        return fallbackTypePtr;
                    } else {
                        Long potential = unoTypes.get(currentCls.getName());
                        if (potential != null) {
                            if (Modifier.isAbstract(currentCls.getModifiers())) {
                                Long fallbackClassPtr = unoFallbacksClassToPtr.get(currentCls);
                                if (fallbackClassPtr != null) {
                                    unoTypes.put(firstCls.getName(), fallbackClassPtr);
                                    return fallbackClassPtr;
                                }
                            } else {
                                unoTypes.put(firstCls.getName(), potential);
                                return (long) potential;
                            }
                        }
                    }
                }
            }
        }
    }
}