private NodeType getNodeTypeProxy()

in shared/api/src/main/java/org/apache/sling/ide/transport/FallbackNodeTypeRegistry.java [73:125]


    private NodeType getNodeTypeProxy(final String name, final String[] superTypeNames) {

        InvocationHandler ih = new InvocationHandler() {

            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

                // NodeType.getName()
                if (method.getName().equals("getName") && method.getParameterTypes().length == 0) {
                    return name;
                }

                // NodeType.getSupertypeNames();
                if (method.getName().equals("getDeclaredSupertypeNames") && method.getParameterTypes().length == 0) {
                    return superTypeNames;
                }

                // NodeType.getDeclaredSupertypeNames();
                if (method.getName().equals("getSupertypes") && method.getParameterTypes().length == 0) {
                    NodeType[] superTypes = new NodeType[superTypeNames.length];
                    for (int i = 0; i < superTypeNames.length; i++) {
                        String aSuperTypeName = superTypeNames[i];
                        NodeType aSuperType = getNodeType(aSuperTypeName);
                        superTypes[i] = aSuperType;
                    }

                    return superTypes;
                }

                // Object.toString() , Object.hashCode(), Object.equals
                if (method.getDeclaringClass() == Object.class) {
                    if (method.getName().equals("toString") && method.getParameterTypes().length == 0) {
                        return proxy.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(proxy));
                    }

                    if (method.getName().equals("hashCode") && method.getParameterTypes().length == 0) {
                        return System.identityHashCode(proxy);
                    }

                    if (method.getName().equals("equals") && method.getParameterTypes().length == 1) {
                        return proxy == args[0];
                    }
                }

                return null;
            }
        };

        NodeType nodeType = (NodeType) Proxy.newProxyInstance(NodeType.class.getClassLoader(),
                new Class[] { NodeType.class }, ih);

        return nodeType;
    }