Search in sources :

Example 1 with Eventable

use of org.openntf.domino.graph2.builtin.Eventable in project org.openntf.domino by OpenNTF.

the class DFramedTransactionalGraph method addVertex.

public <F> F addVertex(final Object id, final Class<F> kind, final boolean temporary) {
    if (id != null && id instanceof NoteCoordinate) {
        Object cacheChk = getElement(id, kind);
        if (cacheChk != null) {
            return (F) cacheChk;
        }
    }
    DGraph base = (DGraph) this.getBaseGraph();
    org.openntf.domino.graph2.DElementStore store = null;
    if (kind != null) {
        store = base.findElementStore(kind);
    }
    if (store == null) {
        // System.out.println("TEMP DEBUG store was null for type " + kind.getName());
        if (id instanceof NoteCoordinate) {
            store = base.findElementStore(id);
        } else {
            String typeid = getTypedId(id);
            if (typeid == null) {
                store = base.getDefaultElementStore();
            } else {
                store = base.findElementStore(typeid);
            }
        }
    } else {
    // System.out.println("TEMP DEBUG adding to store " + ((Database) store.getStoreDelegate()).getApiPath());
    }
    Vertex vertex = store.addVertex(id, temporary);
    String typeValue = ((DConfiguration) this.getConfig()).getTypeValue(kind);
    // System.out.println("TEMP DEBUG Creating new instance of " + kind.getName() + " with typeValue of " + typeValue);
    vertex.setProperty("form", typeValue);
    F result = frame(vertex, kind, temporary);
    if (result instanceof Eventable) {
    }
    if (!temporary) {
        getFramedElementCache().put(vertex.getId(), result);
    }
    return result;
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) DbInfoVertex(org.openntf.domino.graph2.builtin.DbInfoVertex) ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) CategoryVertex(org.openntf.domino.graph2.builtin.CategoryVertex) Vertex(com.tinkerpop.blueprints.Vertex) Eventable(org.openntf.domino.graph2.builtin.Eventable) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) DElementStore(org.openntf.domino.graph2.DElementStore)

Example 2 with Eventable

use of org.openntf.domino.graph2.builtin.Eventable 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)

Aggregations

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