/*
* JBoss, Home of Professional Open Source.
* Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.cache;
import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.interceptors.InterceptorChain;
import org.jboss.cache.invocation.InvocationContextContainer;
import org.jboss.cache.invocation.NodeInvocationDelegate;
import org.jboss.cache.mvcc.ReadCommittedNode;
import org.jboss.cache.optimistic.TransactionWorkspace;
import org.jboss.cache.optimistic.WorkspaceNode;
import java.util.Map;
/**
* Generates new nodes based on the {@link CacheSPI} configuration.
*
* @author Manik Surtani (manik AT jboss DOT org)
*/
public abstract class AbstractNodeFactory implements NodeFactory
{
protected CacheSPI cache;
protected boolean useVersionedNode;
protected Configuration configuration;
protected InvocationContextContainer invocationContextContainer;
protected InterceptorChain interceptorChain;
protected CommandsFactory commandsFactory;
protected ComponentRegistry componentRegistry;
protected DataContainer dataContainer;
@Inject
void injectComponentRegistry(ComponentRegistry componentRegistry, DataContainer dataContainer)
{
this.componentRegistry = componentRegistry;
this.dataContainer = dataContainer;
}
@Inject
public void injectDependencies(CacheSPI cache, Configuration configuration,
InvocationContextContainer invocationContextContainer,
InterceptorChain interceptorChain, CommandsFactory commandsFactory)
{
this.cache = cache;
this.configuration = configuration;
this.invocationContextContainer = invocationContextContainer;
this.interceptorChain = interceptorChain;
this.commandsFactory = commandsFactory;
}
private NodeSPI initializeNodeInvocationDelegate(UnversionedNode internal)
{
// always assume that new nodes do not have data loaded
internal.setDataLoaded(false);
NodeSPI nid = createNodeInvocationDelegate(internal, false);
// back reference
internal.setDelegate(nid);
return nid;
}
public NodeSPI createNode(Fqn fqn, NodeSPI parent, Map data)
{
UnversionedNode internal = createInternalNode(fqn.getLastElement(), fqn, parent, data);
return initializeNodeInvocationDelegate(internal);
}
public NodeSPI createNode(Object childName, NodeSPI parent, Map data)
{
UnversionedNode internal = createInternalNode(childName, Fqn.fromRelativeElements(parent.getFqn(), childName), parent, data);
return initializeNodeInvocationDelegate(internal);
}
public NodeSPI createNode(Fqn fqn, NodeSPI parent)
{
UnversionedNode internal = createInternalNode(fqn.getLastElement(), fqn, parent, null);
return initializeNodeInvocationDelegate(internal);
}
public InternalNode createInternalNode(Fqn fqn)
{
throw new UnsupportedOperationException("Unsupported in this implementation (" + getClass().getSimpleName() + ")!");
}
public NodeSPI createNode(Object childName, NodeSPI parent)
{
UnversionedNode internal = createInternalNode(childName, Fqn.fromRelativeElements(parent.getFqn(), childName), parent, null);
return initializeNodeInvocationDelegate(internal);
}
protected UnversionedNode createInternalNode(Object childName, Fqn fqn, NodeSPI parent, Map data)
{
throw new UnsupportedOperationException("Unsupported in this implementation (" + getClass().getSimpleName() + ")!");
}
public WorkspaceNode createWrappedNode(NodeSPI dataNode, TransactionWorkspace workspace)
{
throw new UnsupportedOperationException("Unsupported in this implementation (" + getClass().getSimpleName() + ")!");
}
public ReadCommittedNode createWrappedNode(InternalNode node, InternalNode parent)
{
throw new UnsupportedOperationException("Unsupported in this implementation (" + getClass().getSimpleName() + ")!");
}
public ReadCommittedNode createWrappedNodeForRemoval(Fqn fqn, InternalNode node, InternalNode parent)
{
throw new UnsupportedOperationException("Unsupported in this implementation (" + getClass().getSimpleName() + ")!");
}
public NodeSPI createRootNode()
{
return createNode(Fqn.ROOT, null);
}
private NodeSPI createNodeInvocationDelegate(InternalNode internalNode, boolean wrapWithNodeReference)
{
if (wrapWithNodeReference)
throw new UnsupportedOperationException("wrapWithNodeReferences is not supported in this impl!");
NodeInvocationDelegate nid = new NodeInvocationDelegate(internalNode);
nid.initialize(configuration, invocationContextContainer, componentRegistry, interceptorChain);
nid.injectDependencies(cache);
return nid;
}
public InternalNode createChildNode(Fqn fqn, InternalNode parent, InvocationContext ctx, boolean attachToParent)
{
throw new UnsupportedOperationException("Unsupported in this implementation (" + getClass().getSimpleName() + ")!");
}
}