Search in sources :

Example 1 with DTypeManager

use of org.openntf.domino.graph2.impl.DConfiguration.DTypeManager in project org.openntf.domino by OpenNTF.

the class DFramedTransactionalGraph method frame.

public <F> F frame(final Vertex vertex, Class<F> kind, final boolean temporary) {
    if (vertex == null) {
        return null;
    }
    if (vertex instanceof DCategoryVertex) {
        kind = (Class<F>) CategoryVertex.class;
    } else {
        Map map = ((DVertex) vertex).getDelegate();
        if (map instanceof Document) {
            if (DesignFactory.isView((Document) map)) {
                kind = (Class<F>) ViewVertex.class;
            }
            if (DesignFactory.isIcon((Document) map) || DesignFactory.isACL((Document) map)) {
                // System.out.println("TEMP DEBUG framing an icon note");
                kind = (Class<F>) DbInfoVertex.class;
            }
        }
    }
    DConfiguration config = (DConfiguration) this.getConfig();
    Class<F> klazz = (Class<F>) (kind == null ? config.getDefaultVertexFrameType() : kind);
    if (config.getReplacementType(klazz) != null) {
        klazz = (Class<F>) config.getReplacementType(klazz);
    }
    DTypeManager manager = config.getTypeManager();
    klazz = (Class<F>) manager.initElement(klazz, this, vertex, temporary);
    for (FrameInitializer initializer : getConfig().getFrameInitializers()) {
        if (!(initializer instanceof JavaFrameInitializer)) {
            initializer.initElement(klazz, this, vertex);
        }
    }
    F result = null;
    try {
        result = super.frame(vertex, klazz);
    } catch (Throwable t) {
        System.out.println("Exception while attempting to frame a vertex " + vertex.getId() + " with class " + klazz.getName());
        t.printStackTrace();
        // DominoUtils.handleException(e);
        try {
            result = (F) super.frame(vertex, config.getDefaultVertexFrameType());
        } catch (Exception e) {
            System.out.println("Exception while attempting to frame a vertex " + vertex.getId() + " with class " + klazz.getName());
            e.printStackTrace();
            DominoUtils.handleException(e);
        }
    }
    for (FrameInitializer initializer : getConfig().getFrameInitializers()) {
        if (initializer instanceof JavaFrameInitializer) {
            ((JavaFrameInitializer) initializer).initElement(klazz, this, result);
        }
    }
    if (vertex instanceof DProxyVertex) {
        List<CaseInsensitiveString> proxied = config.getTypeRegistry().getProxied(klazz);
        if (proxied != null) {
            ((DProxyVertex) vertex).setProxied(proxied);
        }
    }
    if (result instanceof Eventable) {
        if (((Eventable) result).isNew()) {
            try {
                // $NON-NLS-1$
                Method crystal = result.getClass().getMethod("create");
                if (crystal != null) {
                    ((Eventable) result).create();
                }
            } catch (Throwable t) {
            // nothing
            }
        } else {
        // try {
        // Method crystal = result.getClass().getMethod("read", null);
        // if (crystal != null) {
        // ((Eventable) result).read();
        // }
        // } catch (Throwable t) {
        // //nothing
        // }
        }
    }
    return result;
}
Also used : CategoryVertex(org.openntf.domino.graph2.builtin.CategoryVertex) Eventable(org.openntf.domino.graph2.builtin.Eventable) Method(java.lang.reflect.Method) Document(org.openntf.domino.Document) JavaFrameInitializer(com.tinkerpop.frames.modules.javahandler.JavaFrameInitializer) FrameInitializer(com.tinkerpop.frames.FrameInitializer) InvalidCacheLoadException(com.google.common.cache.CacheLoader.InvalidCacheLoadException) UserAccessException(org.openntf.domino.exceptions.UserAccessException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) DbInfoVertex(org.openntf.domino.graph2.builtin.DbInfoVertex) DTypeManager(org.openntf.domino.graph2.impl.DConfiguration.DTypeManager) JavaFrameInitializer(com.tinkerpop.frames.modules.javahandler.JavaFrameInitializer) Map(java.util.Map)

Example 2 with DTypeManager

use of org.openntf.domino.graph2.impl.DConfiguration.DTypeManager in project org.openntf.domino by OpenNTF.

the class DFramedTransactionalGraph method frame.

@Override
@SuppressWarnings("deprecation")
public <F> F frame(final Edge edge, final Class<F> kind) {
    if (edge == null) {
        return null;
    }
    DConfiguration config = (DConfiguration) this.getConfig();
    Class<F> klazz = (Class<F>) (kind == null ? config.getDefaultEdgeFrameType() : kind);
    if (config.getReplacementType(klazz) != null) {
        klazz = (Class<F>) config.getReplacementType(klazz);
    }
    DTypeManager manager = config.getTypeManager();
    klazz = (Class<F>) manager.initElement(klazz, this, edge, false);
    for (FrameInitializer initializer : getConfig().getFrameInitializers()) {
        if (!(initializer instanceof JavaFrameInitializer)) {
            initializer.initElement(klazz, this, edge);
        }
    }
    F result = null;
    try {
        result = super.frame(edge, Direction.OUT, klazz);
    } catch (Throwable t) {
        System.out.println("Exception while attempting to frame a edge " + edge.getId() + " with class " + klazz.getName());
        t.printStackTrace();
        try {
            result = (F) super.frame(edge, Direction.OUT, config.getDefaultEdgeFrameType());
        } catch (Exception e) {
            System.out.println("Exception while attempting to frame a edge " + edge.getId() + " with class " + klazz.getName());
            e.printStackTrace();
            DominoUtils.handleException(e);
        }
    }
    for (FrameInitializer initializer : getConfig().getFrameInitializers()) {
        if (initializer instanceof JavaFrameInitializer) {
            ((JavaFrameInitializer) initializer).initElement(klazz, this, result);
        }
    }
    return result;
}
Also used : DTypeManager(org.openntf.domino.graph2.impl.DConfiguration.DTypeManager) JavaFrameInitializer(com.tinkerpop.frames.modules.javahandler.JavaFrameInitializer) JavaFrameInitializer(com.tinkerpop.frames.modules.javahandler.JavaFrameInitializer) FrameInitializer(com.tinkerpop.frames.FrameInitializer) InvalidCacheLoadException(com.google.common.cache.CacheLoader.InvalidCacheLoadException) UserAccessException(org.openntf.domino.exceptions.UserAccessException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException)

Aggregations

InvalidCacheLoadException (com.google.common.cache.CacheLoader.InvalidCacheLoadException)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)2 FrameInitializer (com.tinkerpop.frames.FrameInitializer)2 JavaFrameInitializer (com.tinkerpop.frames.modules.javahandler.JavaFrameInitializer)2 UserAccessException (org.openntf.domino.exceptions.UserAccessException)2 DTypeManager (org.openntf.domino.graph2.impl.DConfiguration.DTypeManager)2 Method (java.lang.reflect.Method)1 Map (java.util.Map)1 Document (org.openntf.domino.Document)1 CategoryVertex (org.openntf.domino.graph2.builtin.CategoryVertex)1 DbInfoVertex (org.openntf.domino.graph2.builtin.DbInfoVertex)1 Eventable (org.openntf.domino.graph2.builtin.Eventable)1 ViewVertex (org.openntf.domino.graph2.builtin.ViewVertex)1 CaseInsensitiveString (org.openntf.domino.types.CaseInsensitiveString)1