Author: rhauch
Date: 2009-01-15 11:09:50 -0500 (Thu, 15 Jan 2009)
New Revision: 706
Removed:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/BasicExecutionContext.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/BasicExecutionContextFactory.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContexts.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/BasicJcrExecutionContext.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/util/MockJcrExecutionContext.java
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/jcr/AbstractJcrRepositoryTest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContext.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/mimetype/ExtensionBasedMimeTypeDetector.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/SequencerContext.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/xml/XmlHandler.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/test/AbstractConnectorTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/AbstractRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencers/MockSequencerContext.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/xml/XmlHandlerTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrExecutionContext.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencingServiceTest.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java
trunk/docs/gettingstarted/src/main/docbook/en-US/content/downloading_and_running.xml
trunk/docs/gettingstarted/src/main/docbook/en-US/content/using_dna_for_sequencing.xml
trunk/docs/gettingstarted/src/main/docbook/en-US/content/using_dna_repositories.xml
trunk/docs/reference/src/main/docbook/en-US/content/environment.xml
trunk/docs/reference/src/main/docbook/en-US/content/repositories.xml
trunk/docs/reference/src/main/docbook/en-US/content/sequencing.xml
trunk/docs/reference/src/main/docbook/en-US/custom.dtd
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositoryTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionPathRuleTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategyTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategyTest.java
trunk/extensions/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/models/basic/BasicModelTest.java
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/models/basic/ChildEntityTest.java
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/models/basic/SubgraphQueryTest.java
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/RequestProcessorCacheTest.java
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/SerializerTest.java
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencerHandler.java
Log:
DNA-270 Simplify the ExecutionContext framework
Changed ExecutionContext from an interface to a concrete class, and made it implement
ExecutionContextFactory. This allowed removing the BasicExecutionContext and
BasicExecutionContextFactory implementations. Also added methods to ExecutionContext to
create "subcontext" (or context that inherit all of the same components except
for one), allowing removal of the ExecutionContexts class. These changes made it much
easier to use (no need to know about an implementation, anybody can create a context or
create a modified form of another context, less of a distinction between ExecutionContext
and ExecutionContextFactory, etc.), yet provides a lot of flexibility for defining
different combinations of components (including custom components) without requiring
subclassing (though subclassing is not precluded).
There were two primary subinterfaces of ExecutionContext (SequencerContext and
JcrExecutionContext); both of these were converted from classes to interfaces, eliminating
their implementation classes. Since both provide special kinds of contexts that only
added components to the "context" (rather than changing the behavior of the
existing components).
Also changed the documentation and examples to reflect these improvements.
Modified:
trunk/dna-common/src/test/java/org/jboss/dna/common/jcr/AbstractJcrRepositoryTest.java
===================================================================
---
trunk/dna-common/src/test/java/org/jboss/dna/common/jcr/AbstractJcrRepositoryTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-common/src/test/java/org/jboss/dna/common/jcr/AbstractJcrRepositoryTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -42,8 +42,8 @@
* Typically, unit test classes need a repository for just some of it's unit tests
(other unit tests don't need the repository
* because they are just testing other functionality of the class under test), and this
class was designed for this scenario. A
* unit test method that needs a repository should call {@link #startRepository()}, and
then may proceed to use the
- * {@link #getRepository() repository}. The test method need not call {@link
#shutdownRepository()}, as it is called
- * automatically after every test (and does nothing if the repository was not started in
the first place).
+ * {@link #getRepository() repository}. The test method need not call {@link
#shutdownRepository()}, as it is called automatically
+ * after every test (and does nothing if the repository was not started in the first
place).
* </p>
* <p>
* Some unit test methods may have a need to repeatedly start and stop the repository,
and this can be done by calling
@@ -172,4 +172,5 @@
public Credentials getTestCredentials() {
return this.simpleCredentials;
}
+
}
Deleted: trunk/dna-graph/src/main/java/org/jboss/dna/graph/BasicExecutionContext.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/BasicExecutionContext.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/BasicExecutionContext.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -1,218 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, 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.dna.graph;
-
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import javax.security.auth.Subject;
-import javax.security.auth.login.LoginContext;
-import org.jboss.dna.common.component.ClassLoaderFactory;
-import org.jboss.dna.common.component.StandardClassLoaderFactory;
-import org.jboss.dna.common.util.Logger;
-import org.jboss.dna.graph.mimetype.ExtensionBasedMimeTypeDetector;
-import org.jboss.dna.graph.mimetype.MimeTypeDetector;
-import org.jboss.dna.graph.properties.NamespaceRegistry;
-import org.jboss.dna.graph.properties.PropertyFactory;
-import org.jboss.dna.graph.properties.ValueFactories;
-import org.jboss.dna.graph.properties.basic.BasicNamespaceRegistry;
-import org.jboss.dna.graph.properties.basic.BasicPropertyFactory;
-import org.jboss.dna.graph.properties.basic.StandardValueFactories;
-
-/**
- * @author Randall Hauch
- * @author John Verhaeg
- */
-public class BasicExecutionContext implements ExecutionContext {
-
- private final ClassLoaderFactory classLoaderFactory;
- private final LoginContext loginContext;
- private final AccessControlContext accessControlContext;
- private final Subject subject;
- private final PropertyFactory propertyFactory;
- private final ValueFactories valueFactories;
- private final NamespaceRegistry namespaceRegistry;
- private final MimeTypeDetector mimeTypeDetector;
-
- public BasicExecutionContext() {
- this(null, null, null, null, null, null);
- }
-
- public BasicExecutionContext( LoginContext loginContext ) {
- this(loginContext, null, null, null, null, null);
- }
-
- public BasicExecutionContext( AccessControlContext accessControlContext ) {
- this(null, accessControlContext, null, null, null, null);
- }
-
- public BasicExecutionContext( NamespaceRegistry namespaceRegistry,
- ValueFactories valueFactories,
- PropertyFactory propertyFactory ) {
- this(null, null, namespaceRegistry, valueFactories, propertyFactory, null);
- }
-
- public BasicExecutionContext( NamespaceRegistry namespaceRegistry ) {
- this(null, null, namespaceRegistry, null, null, null);
- }
-
- public BasicExecutionContext( LoginContext loginContext,
- NamespaceRegistry namespaceRegistry,
- ValueFactories valueFactories,
- PropertyFactory propertyFactory ) {
- this(loginContext, null, namespaceRegistry, valueFactories, propertyFactory,
null);
- }
-
- public BasicExecutionContext( AccessControlContext accessControlContext,
- NamespaceRegistry namespaceRegistry,
- ValueFactories valueFactories,
- PropertyFactory propertyFactory ) {
- this(null, accessControlContext, namespaceRegistry, valueFactories,
propertyFactory, null);
- }
-
- public BasicExecutionContext( AccessControlContext accessControlContext,
- NamespaceRegistry namespaceRegistry,
- ValueFactories valueFactories,
- PropertyFactory propertyFactory,
- MimeTypeDetector mimeTypeDetector ) {
- this(null, accessControlContext, namespaceRegistry, valueFactories,
propertyFactory, mimeTypeDetector);
- }
-
- public BasicExecutionContext( ExecutionContext inheritedContext,
- NamespaceRegistry namespaceRegistry ) {
- this(inheritedContext.getLoginContext(),
inheritedContext.getAccessControlContext(), namespaceRegistry, null, null,
- inheritedContext.getMimeTypeDetector());
- }
-
- public BasicExecutionContext( ExecutionContext inheritedContext,
- MimeTypeDetector mimeTypeDetector ) {
- this(inheritedContext.getLoginContext(),
inheritedContext.getAccessControlContext(),
- inheritedContext.getNamespaceRegistry(),
inheritedContext.getValueFactories(),
- inheritedContext.getPropertyFactory(), mimeTypeDetector);
- }
-
- /*
- * This constructor exists to deal with mutually-exclusive parameters, such as
LoginContext and AccessControlContext.
- */
- private BasicExecutionContext( LoginContext loginContext,
- AccessControlContext accessControlContext,
- NamespaceRegistry namespaceRegistry,
- ValueFactories valueFactories,
- PropertyFactory propertyFactory,
- MimeTypeDetector mimeTypeDetector ) {
- this.loginContext = loginContext;
- this.accessControlContext = accessControlContext;
- if (loginContext == null) {
- this.subject = Subject.getSubject(accessControlContext == null ?
AccessController.getContext() : accessControlContext);
- } else {
- this.subject = loginContext.getSubject();
- }
- this.namespaceRegistry = namespaceRegistry == null ? new BasicNamespaceRegistry()
: namespaceRegistry;
- this.valueFactories = valueFactories == null ? new
StandardValueFactories(this.namespaceRegistry) : valueFactories;
- this.propertyFactory = propertyFactory == null ? new
BasicPropertyFactory(this.valueFactories) : propertyFactory;
- this.classLoaderFactory = new StandardClassLoaderFactory();
- this.mimeTypeDetector = mimeTypeDetector != null ? mimeTypeDetector :
ExtensionBasedMimeTypeDetector.getInstance();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.common.component.ClassLoaderFactory#getClassLoader(java.lang.String[])
- */
- public ClassLoader getClassLoader( String... classpath ) {
- return this.classLoaderFactory.getClassLoader(classpath);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getAccessControlContext()
- */
- public AccessControlContext getAccessControlContext() {
- return accessControlContext;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLoginContext()
- */
- public LoginContext getLoginContext() {
- return loginContext;
- }
-
- /**
- * {@inheritDoc}
- */
- public NamespaceRegistry getNamespaceRegistry() {
- return namespaceRegistry;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getMimeTypeDetector()
- */
- public MimeTypeDetector getMimeTypeDetector() {
- return mimeTypeDetector;
- }
-
- /**
- * {@inheritDoc}
- */
- public PropertyFactory getPropertyFactory() {
- return propertyFactory;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getSubject()
- */
- public Subject getSubject() {
- return subject;
- }
-
- /**
- * {@inheritDoc}
- */
- public ValueFactories getValueFactories() {
- return valueFactories;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLogger(java.lang.Class)
- */
- public Logger getLogger( Class<?> clazz ) {
- return Logger.getLogger(clazz);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLogger(java.lang.String)
- */
- public Logger getLogger( String name ) {
- return Logger.getLogger(name);
- }
-}
Deleted:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/BasicExecutionContextFactory.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/BasicExecutionContextFactory.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/BasicExecutionContextFactory.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -1,163 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, 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.dna.graph;
-
-import java.security.AccessControlContext;
-import javax.security.auth.Subject;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.login.LoginContext;
-import javax.security.auth.login.LoginException;
-import org.jboss.dna.graph.properties.NamespaceRegistry;
-import org.jboss.dna.graph.properties.basic.BasicNamespaceRegistry;
-
-/**
- * Basic implementation of a {@link ExecutionContextFactory} that returns {@link
BasicExecutionContext basic}
- * {@link ExecutionContext}s.
- *
- * @author Randall Hauch
- */
-public class BasicExecutionContextFactory implements ExecutionContextFactory {
-
- private final NamespaceRegistry defaultNamespaces = new BasicNamespaceRegistry();
-
- /**
- * Create a new instance of this factory.
- */
- public BasicExecutionContextFactory() {
- defaultNamespaces.register("jcr",
"http://www.jcp.org/jcr/1.0");
- defaultNamespaces.register("mix",
"http://www.jcp.org/jcr/mix/1.0");
- defaultNamespaces.register("nt",
"http://www.jcp.org/jcr/nt/1.0");
- defaultNamespaces.register("dna",
"http://www.jboss.org/dna");
- defaultNamespaces.register("dnadtd",
"http://www.jboss.org/dna/dtd/1.0");
- defaultNamespaces.register("dnaxml",
"http://www.jboss.org/dna/xml/1.0");
- }
-
- /**
- * Create a new instance of this factory.
- *
- * @param defaultNamespaceUri the URI of the namespace that should be used with names
that have no specified namespace prefix
- * @throws IllegalArgumentException if the URI is null
- */
- public BasicExecutionContextFactory( String defaultNamespaceUri ) {
- this();
- defaultNamespaces.register("", defaultNamespaceUri);
- }
-
- /**
- * @return defaultNamespaces
- */
- public NamespaceRegistry getDefaultNamespaces() {
- return defaultNamespaces;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContextFactory#create()
- */
- public ExecutionContext create() {
- ExecutionContext context = new BasicExecutionContext();
- initialize(context);
- return context;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.ExecutionContextFactory#create(java.security.AccessControlContext)
- */
- public ExecutionContext create( AccessControlContext accessControlContext ) {
- ExecutionContext context = new BasicExecutionContext(accessControlContext);
- initialize(context);
- return context;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.ExecutionContextFactory#create(javax.security.auth.login.LoginContext)
- */
- public ExecutionContext create( LoginContext loginContext ) {
- ExecutionContext context = new BasicExecutionContext(loginContext);
- initialize(context);
- return context;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContextFactory#create(java.lang.String)
- */
- public ExecutionContext create( String name ) throws LoginException {
- LoginContext loginContext = new LoginContext(name);
- ExecutionContext context = new BasicExecutionContext(loginContext);
- initialize(context);
- return context;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContextFactory#create(java.lang.String,
javax.security.auth.Subject)
- */
- public ExecutionContext create( String name,
- Subject subject ) throws LoginException {
- LoginContext loginContext = new LoginContext(name, subject);
- ExecutionContext context = new BasicExecutionContext(loginContext);
- initialize(context);
- return context;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContextFactory#create(java.lang.String,
javax.security.auth.callback.CallbackHandler)
- */
- public ExecutionContext create( String name,
- CallbackHandler callbackHandler ) throws
LoginException {
- LoginContext loginContext = new LoginContext(name, callbackHandler);
- ExecutionContext context = new BasicExecutionContext(loginContext);
- initialize(context);
- return context;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContextFactory#create(java.lang.String,
javax.security.auth.Subject,
- * javax.security.auth.callback.CallbackHandler)
- */
- public ExecutionContext create( String name,
- Subject subject,
- CallbackHandler callbackHandler ) throws
LoginException {
- LoginContext loginContext = new LoginContext(name, subject, callbackHandler);
- ExecutionContext context = new BasicExecutionContext(loginContext);
- initialize(context);
- return context;
- }
-
- protected synchronized void initialize( ExecutionContext context ) {
- for (NamespaceRegistry.Namespace namespace :
this.defaultNamespaces.getNamespaces()) {
- context.getNamespaceRegistry().register(namespace.getPrefix(),
namespace.getNamespaceUri());
- }
- }
-}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContext.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContext.java 2009-01-15
02:10:17 UTC (rev 705)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContext.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -22,34 +22,173 @@
package org.jboss.dna.graph;
import java.security.AccessControlContext;
+import java.security.AccessController;
import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+import net.jcip.annotations.Immutable;
import org.jboss.dna.common.component.ClassLoaderFactory;
+import org.jboss.dna.common.component.StandardClassLoaderFactory;
+import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.common.util.Logger;
+import org.jboss.dna.graph.mimetype.ExtensionBasedMimeTypeDetector;
import org.jboss.dna.graph.mimetype.MimeTypeDetector;
import org.jboss.dna.graph.properties.NamespaceRegistry;
import org.jboss.dna.graph.properties.Property;
import org.jboss.dna.graph.properties.PropertyFactory;
import org.jboss.dna.graph.properties.ValueFactories;
+import org.jboss.dna.graph.properties.basic.BasicNamespaceRegistry;
+import org.jboss.dna.graph.properties.basic.BasicPropertyFactory;
+import org.jboss.dna.graph.properties.basic.StandardValueFactories;
/**
* An ExecutionContext is a representation of the environment or context in which a
component or operation is operating. Some
* components require this context to be passed into individual methods, allowing the
context to vary with each method invocation.
* Other components require the context to be provided before it's used, and will use
that context for all its operations (until
* it is given a different one).
+ * <p>
+ * ExecutionContext instances are {@link Immutable immutable}, so components may hold
onto references to them without concern of
+ * those contexts changing. However, contexts may be used to create other context with
variations in the environment and/or
+ * security context. For example, an ExecutionContext could be used to create another
context that references the same
+ * {@link #getNamespaceRegistry() namespace registry} but which has a different {@link
#getSubject() JAAS subject}.
+ * </p>
*
* @author Randall Hauch
* @author John Verhaeg
- * @see ExecutionContextFactory
*/
-public interface ExecutionContext extends ClassLoaderFactory {
+@Immutable
+public class ExecutionContext implements ClassLoaderFactory, Cloneable,
ExecutionContextFactory {
+ private final ClassLoaderFactory classLoaderFactory;
+ private final LoginContext loginContext;
+ private final AccessControlContext accessControlContext;
+ private final Subject subject;
+ private final PropertyFactory propertyFactory;
+ private final ValueFactories valueFactories;
+ private final NamespaceRegistry namespaceRegistry;
+ private final MimeTypeDetector mimeTypeDetector;
+
/**
- * @return the access control context; may be <code>null</code>
+ * Create an instance of an execution context that inherits the {@link
AccessControlContext security context} from the
+ * {@link AccessController#getContext() current calling context}, with default
implementations for all other components
+ * (including default namespaces in the {@link #getNamespaceRegistry() namespace
registry}.
*/
- AccessControlContext getAccessControlContext();
+ public ExecutionContext() {
+ this(null, null, null, null, null, null, null);
+ initializeDefaultNamespaces(this.getNamespaceRegistry());
+ }
/**
+ * Create a copy of the supplied execution context.
+ *
+ * @param original the original
+ * @throws IllegalArgumentException if the original is null
+ */
+ protected ExecutionContext( ExecutionContext original ) {
+ CheckArg.isNotNull(original, "original");
+ this.loginContext = original.getLoginContext();
+ this.accessControlContext = original.getAccessControlContext();
+ this.subject = original.getSubject();
+ this.namespaceRegistry = original.getNamespaceRegistry();
+ this.valueFactories = original.getValueFactories();
+ this.propertyFactory = original.getPropertyFactory();
+ this.classLoaderFactory = original.getClassLoaderFactory();
+ this.mimeTypeDetector = original.getMimeTypeDetector();
+ }
+
+ /**
+ * Create a copy of the supplied execution context, but use the supplied {@link
AccessControlContext} instead.
+ *
+ * @param original the original
+ * @param accessControlContext the access control context
+ * @throws IllegalArgumentException if the original or access control context are is
null
+ */
+ protected ExecutionContext( ExecutionContext original,
+ AccessControlContext accessControlContext ) {
+ CheckArg.isNotNull(original, "original");
+ CheckArg.isNotNull(accessControlContext, "accessControlContext");
+ this.loginContext = null;
+ this.accessControlContext = accessControlContext;
+ this.subject = Subject.getSubject(this.accessControlContext);
+ this.namespaceRegistry = original.getNamespaceRegistry();
+ this.valueFactories = original.getValueFactories();
+ this.propertyFactory = original.getPropertyFactory();
+ this.classLoaderFactory = original.getClassLoaderFactory();
+ this.mimeTypeDetector = original.getMimeTypeDetector();
+ }
+
+ /**
+ * Create a copy of the supplied execution context, but use the supplied {@link
LoginContext} instead.
+ *
+ * @param original the original
+ * @param loginContext the login context
+ * @throws IllegalArgumentException if the original or login context are is null
+ */
+ protected ExecutionContext( ExecutionContext original,
+ LoginContext loginContext ) {
+ CheckArg.isNotNull(original, "original");
+ CheckArg.isNotNull(loginContext, "loginContext");
+ this.loginContext = loginContext;
+ this.accessControlContext = null;
+ this.subject = this.loginContext.getSubject();
+ this.namespaceRegistry = original.getNamespaceRegistry();
+ this.valueFactories = original.getValueFactories();
+ this.propertyFactory = original.getPropertyFactory();
+ this.classLoaderFactory = original.getClassLoaderFactory();
+ this.mimeTypeDetector = original.getMimeTypeDetector();
+ }
+
+ /**
+ * Create an instance of the execution context by supplying all parameters.
+ *
+ * @param loginContext the login context, or null if the {@link #getSubject()
subject} is to be retrieved from the
+ * {@link AccessController#getContext() current calling context}.
+ * @param accessControlContext the access control context, or null if a {@link
LoginContext} is provided or if the
+ * {@link AccessController#getContext() current calling context} should be
used
+ * @param namespaceRegistry the namespace registry implementation, or null if a
{@link BasicNamespaceRegistry} instance should
+ * be used
+ * @param valueFactories the {@link ValueFactories} implementation, or null if a
{@link StandardValueFactories} instance
+ * should be used
+ * @param propertyFactory the {@link PropertyFactory} implementation, or null if a
{@link BasicPropertyFactory} instance
+ * should be used
+ * @param mimeTypeDetector the {@link MimeTypeDetector} implementation, or null if an
{@link ExtensionBasedMimeTypeDetector}
+ * instance should be used
+ * @param classLoaderFactory the {@link ClassLoaderFactory} implementation, or null
if a {@link StandardClassLoaderFactory}
+ * instance should be used
+ */
+ protected ExecutionContext( LoginContext loginContext,
+ AccessControlContext accessControlContext,
+ NamespaceRegistry namespaceRegistry,
+ ValueFactories valueFactories,
+ PropertyFactory propertyFactory,
+ MimeTypeDetector mimeTypeDetector,
+ ClassLoaderFactory classLoaderFactory ) {
+ this.loginContext = loginContext;
+ this.accessControlContext = accessControlContext;
+ if (loginContext == null) {
+ this.subject = Subject.getSubject(accessControlContext == null ?
AccessController.getContext() : accessControlContext);
+ } else {
+ this.subject = loginContext.getSubject();
+ }
+ this.namespaceRegistry = namespaceRegistry == null ? new BasicNamespaceRegistry()
: namespaceRegistry;
+ this.valueFactories = valueFactories == null ? new
StandardValueFactories(this.namespaceRegistry) : valueFactories;
+ this.propertyFactory = propertyFactory == null ? new
BasicPropertyFactory(this.valueFactories) : propertyFactory;
+ this.classLoaderFactory = classLoaderFactory == null ? new
StandardClassLoaderFactory() : classLoaderFactory;
+ this.mimeTypeDetector = mimeTypeDetector != null ? mimeTypeDetector : new
ExtensionBasedMimeTypeDetector();
+ }
+
+ /**
+ * Get the class loader factory used by this context.
+ *
+ * @return the class loader factory implementation; never null
+ */
+ protected ClassLoaderFactory getClassLoaderFactory() {
+ return classLoaderFactory;
+ }
+
+ /**
* Return a logger associated with this context. This logger records only those
activities within the context and provide a
* way to capture the context-specific activities. All log messages are also sent to
the system logger, so classes that log
* via this mechanism should <i>not</i> also {@link
Logger#getLogger(Class) obtain a system logger}.
@@ -58,7 +197,9 @@
* @return the logger, named after <code>clazz</code>; never null
* @see #getLogger(String)
*/
- Logger getLogger( Class<?> clazz );
+ public Logger getLogger( Class<?> clazz ) {
+ return Logger.getLogger(clazz);
+ }
/**
* Return a logger associated with this context. This logger records only those
activities within the context and provide a
@@ -69,45 +210,240 @@
* @return the logger, named after <code>clazz</code>; never null
* @see #getLogger(Class)
*/
- Logger getLogger( String name );
+ public Logger getLogger( String name ) {
+ return Logger.getLogger(name);
+ }
/**
* Return an object that can be used to determine the MIME type of some content, such
as the content of a file.
*
* @return the detector; never null
*/
- MimeTypeDetector getMimeTypeDetector();
+ public MimeTypeDetector getMimeTypeDetector() {
+ return this.mimeTypeDetector;
+ }
/**
+ * Get the {@link AccessControlContext JAAS access control context} for this
context.
+ *
+ * @return the access control context; may be <code>null</code>
+ */
+ public AccessControlContext getAccessControlContext() {
+ return this.accessControlContext;
+ }
+
+ /**
+ * Get the {@link LoginContext JAAS login context} for this context.
+ *
* @return the login context; may be <code>null</code>
*/
- LoginContext getLoginContext();
+ public LoginContext getLoginContext() {
+ return this.loginContext;
+ }
/**
- * Get the namespace registry for this context.
+ * Get the (mutable) namespace registry for this context.
*
* @return the namespace registry; never <code>null</code>
*/
- NamespaceRegistry getNamespaceRegistry();
+ public NamespaceRegistry getNamespaceRegistry() {
+ return this.namespaceRegistry;
+ }
/**
* Get the factory for creating {@link Property} objects.
*
* @return the property factory; never <code>null</code>
*/
- PropertyFactory getPropertyFactory();
+ public PropertyFactory getPropertyFactory() {
+ return this.propertyFactory;
+ }
/**
* Get the JAAS subject for which this context was created.
*
- * @return the subject; never <code>null</code>
+ * @return the subject; should never be null if JAAS is used, but will be null if
there is no
+ * {@link #getAccessControlContext() access control context} or {@link
#getLoginContext() login context}.
*/
- Subject getSubject();
+ public Subject getSubject() {
+ return this.subject;
+ }
/**
* Get the factories that should be used to create values for {@link Property
properties}.
*
* @return the property value factory; never null
*/
- ValueFactories getValueFactories();
+ public ValueFactories getValueFactories() {
+ return this.valueFactories;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.common.component.ClassLoaderFactory#getClassLoader(java.lang.String[])
+ */
+ public ClassLoader getClassLoader( String... classpath ) {
+ return this.classLoaderFactory.getClassLoader(classpath);
+ }
+
+ /**
+ * Create a new execution context that mirrors this context but that uses the
supplied namespace registry. The resulting
+ * context's {@link #getValueFactories() value factories} and {@link
#getPropertyFactory() property factory} all make use of
+ * the new namespace registry.
+ *
+ * @param namespaceRegistry the new namespace registry implementation, or null if the
default implementation should be used
+ * @return the new execution context
+ */
+ public ExecutionContext with( NamespaceRegistry namespaceRegistry ) {
+ // Don't supply the value factories or property factories, since they'll
have to be recreated
+ // to reference the supplied namespace registry ...
+ return new ExecutionContext(this.getLoginContext(),
this.getAccessControlContext(), namespaceRegistry, null, null,
+ this.getMimeTypeDetector(),
this.getClassLoaderFactory());
+ }
+
+ /**
+ * Create a new execution context that mirrors this context but that uses the
supplied {@link MimeTypeDetector MIME type
+ * detector}.
+ *
+ * @param mimeTypeDetector the new MIME type detector implementation, or null if the
default implementation should be used
+ * @return the new execution context
+ */
+ public ExecutionContext with( MimeTypeDetector mimeTypeDetector ) {
+ // Don't supply the value factories or property factories, since they'll
have to be recreated
+ // to reference the supplied namespace registry ...
+ return new ExecutionContext(getLoginContext(), getAccessControlContext(),
getNamespaceRegistry(), getValueFactories(),
+ getPropertyFactory(), mimeTypeDetector,
getClassLoaderFactory());
+ }
+
+ /**
+ * Create a new execution context that mirrors this context but that uses the
supplied {@link ClassLoaderFactory class loader
+ * factory}.
+ *
+ * @param classLoaderFactory the new class loader factory implementation, or null if
the default implementation should be used
+ * @return the new execution context
+ */
+ public ExecutionContext with( ClassLoaderFactory classLoaderFactory ) {
+ // Don't supply the value factories or property factories, since they'll
have to be recreated
+ // to reference the supplied namespace registry ...
+ return new ExecutionContext(getLoginContext(), getAccessControlContext(),
getNamespaceRegistry(), getValueFactories(),
+ getPropertyFactory(), getMimeTypeDetector(),
classLoaderFactory);
+ }
+
+ /**
+ * Creates an {@link ExecutionContext} using the supplied {@link AccessControlContext
access control context}.
+ *
+ * @param accessControlContext An access control context.
+ * @return the execution context; never <code>null</code>.
+ * @throws IllegalArgumentException if <code>accessControlContext</code>
is <code>null</code>.
+ */
+ public ExecutionContext create( AccessControlContext accessControlContext ) {
+ return new ExecutionContext(this, accessControlContext);
+ }
+
+ /**
+ * Create an {@link ExecutionContext} for the supplied {@link LoginContext}.
+ *
+ * @param loginContext the JAAS login context
+ * @return the execution context
+ * @throws IllegalArgumentException if the <code>loginContext</code> is
null
+ */
+ public ExecutionContext create( LoginContext loginContext ) {
+ return new ExecutionContext(this, loginContext);
+ }
+
+ /**
+ * @param name the name of the JAAS login context
+ * @return the execution context
+ * @throws IllegalArgumentException if the <code>name</code> is null
+ * @throws LoginException if there <code>name</code> is invalid (or there
is no login context named "other"), or if the
+ * default callback handler JAAS property was not set or could not be loaded
+ */
+ public ExecutionContext create( String name ) throws LoginException {
+ return new ExecutionContext(this, new LoginContext(name));
+ }
+
+ /**
+ * @param name the name of the JAAS login context
+ * @param subject the subject to authenticate
+ * @return the execution context
+ * @throws LoginException if there <code>name</code> is invalid (or there
is no login context named "other"), if the default
+ * callback handler JAAS property was not set or could not be loaded, or if
the <code>subject</code> is null or
+ * unknown
+ */
+ public ExecutionContext create( String name,
+ Subject subject ) throws LoginException {
+ return new ExecutionContext(this, new LoginContext(name, subject));
+ }
+
+ /**
+ * @param name the name of the JAAS login context
+ * @param callbackHandler the callback handler that will be used by {@link
LoginModule}s to communicate with the user.
+ * @return the execution context
+ * @throws LoginException if there <code>name</code> is invalid (or there
is no login context named "other"), or if the
+ * <code>callbackHandler</code> is null
+ */
+ public ExecutionContext create( String name,
+ CallbackHandler callbackHandler ) throws
LoginException {
+ return new ExecutionContext(this, new LoginContext(name, callbackHandler));
+ }
+
+ /**
+ * @param name the name of the JAAS login context
+ * @param subject the subject to authenticate
+ * @param callbackHandler the callback handler that will be used by {@link
LoginModule}s to communicate with the user.
+ * @return the execution context
+ * @throws LoginException if there <code>name</code> is invalid (or there
is no login context named "other"), if the default
+ * callback handler JAAS property was not set or could not be loaded, if the
<code>subject</code> is null or unknown,
+ * or if the <code>callbackHandler</code> is null
+ */
+ public ExecutionContext create( String name,
+ Subject subject,
+ CallbackHandler callbackHandler ) throws
LoginException {
+ return new ExecutionContext(this, new LoginContext(name, subject,
callbackHandler));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.ExecutionContextFactory#create()
+ */
+ public ExecutionContext create() {
+ return new ExecutionContext(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public ExecutionContext clone() {
+ return new ExecutionContext(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "Execution context for " + getSubject();
+ }
+
+ /**
+ * Method that initializes the default namespaces for namespace registries.
+ *
+ * @param namespaceRegistry the namespace registry
+ */
+ protected void initializeDefaultNamespaces( NamespaceRegistry namespaceRegistry ) {
+ if (namespaceRegistry == null) return;
+ namespaceRegistry.register(JcrLexicon.Namespace.PREFIX,
JcrLexicon.Namespace.URI);
+ namespaceRegistry.register(JcrMixLexicon.Namespace.PREFIX,
JcrMixLexicon.Namespace.URI);
+ namespaceRegistry.register(JcrNtLexicon.Namespace.PREFIX,
JcrNtLexicon.Namespace.URI);
+ namespaceRegistry.register(DnaLexicon.Namespace.PREFIX,
DnaLexicon.Namespace.URI);
+ // namespaceRegistry.register("dnadtd",
"http://www.jboss.org/dna/dtd/1.0");
+ // namespaceRegistry.register("dnaxml",
"http://www.jboss.org/dna/xml/1.0");
+ }
}
Deleted: trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContexts.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContexts.java 2009-01-15
02:10:17 UTC (rev 705)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/ExecutionContexts.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -1,251 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, 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.dna.graph;
-
-import java.security.AccessControlContext;
-import javax.security.auth.Subject;
-import javax.security.auth.login.LoginContext;
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.Logger;
-import org.jboss.dna.graph.mimetype.MimeTypeDetector;
-import org.jboss.dna.graph.properties.NameFactory;
-import org.jboss.dna.graph.properties.NamespaceRegistry;
-import org.jboss.dna.graph.properties.PathFactory;
-import org.jboss.dna.graph.properties.PropertyFactory;
-import org.jboss.dna.graph.properties.ValueFactories;
-import org.jboss.dna.graph.properties.basic.DelegatingValueFactories;
-
-/**
- * Utility methods for creating various execution contexts with replacement factories or
components.
- *
- * @author Randall Hauch
- * @author John Verhaeg
- */
-public class ExecutionContexts {
-
- /**
- * Create an context that can be used to replace the supplied context but that uses
the supplied path factory.
- *
- * @param context the base context
- * @param pathFactory the new path factory
- * @return the new execution context
- * @throws IllegalArgumentException if the context or factory references are null
- */
- public static ExecutionContext replace( ExecutionContext context,
- PathFactory pathFactory ) {
- CheckArg.isNotNull(context, "context");
- CheckArg.isNotNull(pathFactory, "pathFactory");
- return new DelegatingExecutionEnvironment(context, null, null, null,
pathFactory);
- }
-
- /**
- * Create an context that can be used to replace the supplied context but that uses
the supplied name factory.
- *
- * @param context the base context
- * @param nameFactory the new name factory
- * @return the new execution context
- * @throws IllegalArgumentException if the context or factory references are null
- */
- public static ExecutionContext replace( ExecutionContext context,
- NameFactory nameFactory ) {
- CheckArg.isNotNull(context, "context");
- CheckArg.isNotNull(nameFactory, "nameFactory");
- return new DelegatingExecutionEnvironment(context, null, null, nameFactory,
null);
- }
-
- /**
- * Create an context that can be used to replace the supplied context but that uses
the supplied name and path factories.
- *
- * @param context the base context
- * @param nameFactory the new name factory
- * @param pathFactory the new path factory
- * @return the new execution context
- * @throws IllegalArgumentException if the context or factory references are null
- */
- public static ExecutionContext replace( ExecutionContext context,
- NameFactory nameFactory,
- PathFactory pathFactory ) {
- CheckArg.isNotNull(context, "context");
- CheckArg.isNotNull(nameFactory, "nameFactory");
- CheckArg.isNotNull(pathFactory, "pathFactory");
- return new DelegatingExecutionEnvironment(context, null, null, nameFactory,
pathFactory);
- }
-
- /**
- * Create an context that can be used to replace the supplied context but that uses
the supplied namespace registry.
- *
- * @param context the base context
- * @param namespaceRegistry the new namespace registry
- * @return the new execution context
- * @throws IllegalArgumentException if the context or registry references are null
- */
- public static ExecutionContext replace( ExecutionContext context,
- NamespaceRegistry namespaceRegistry ) {
- CheckArg.isNotNull(context, "context");
- CheckArg.isNotNull(namespaceRegistry, "namespaceRegistry");
- return new DelegatingExecutionEnvironment(context, namespaceRegistry, null, null,
null);
- }
-
- protected static class DelegatingExecutionEnvironment implements ExecutionContext {
-
- private final ExecutionContext delegate;
- private final NamespaceRegistry newNamespaceRegistry;
- private final PropertyFactory newPropertyFactory;
- private final ValueFactories newValueFactories;
-
- public DelegatingExecutionEnvironment( ExecutionContext delegate,
- NamespaceRegistry newRegistry,
- PropertyFactory newPropertyFactory,
- ValueFactories newValueFactories ) {
- assert delegate != null;
- this.delegate = delegate;
- this.newNamespaceRegistry = newRegistry;
- this.newPropertyFactory = newPropertyFactory;
- this.newValueFactories = newValueFactories;
- }
-
- public DelegatingExecutionEnvironment( ExecutionContext delegate,
- NamespaceRegistry newRegistry,
- PropertyFactory newPropertyFactory,
- final NameFactory newNameFactory,
- final PathFactory newPathFactory ) {
- assert delegate != null;
- this.delegate = delegate;
- this.newNamespaceRegistry = newRegistry;
- this.newPropertyFactory = newPropertyFactory;
- final PathFactory pathFactory = newPathFactory != null ? newPathFactory :
delegate.getValueFactories().getPathFactory();
- final NameFactory nameFactory = newNameFactory != null ? newNameFactory :
delegate.getValueFactories().getNameFactory();
- this.newValueFactories = newPathFactory == null ? null : new
DelegatingValueFactories(delegate.getValueFactories()) {
-
- @Override
- public PathFactory getPathFactory() {
- return pathFactory;
- }
-
- @Override
- public NameFactory getNameFactory() {
- return nameFactory;
- }
- };
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.common.component.ClassLoaderFactory#getClassLoader(java.lang.String[])
- */
- public ClassLoader getClassLoader( String... classpath ) {
- return this.delegate.getClassLoader(classpath);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getAccessControlContext()
- */
- public AccessControlContext getAccessControlContext() {
- return delegate.getAccessControlContext();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLoginContext()
- */
- public LoginContext getLoginContext() {
- return delegate.getLoginContext();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getMimeTypeDetector()
- */
- public MimeTypeDetector getMimeTypeDetector() {
- return delegate.getMimeTypeDetector();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getNamespaceRegistry()
- */
- public NamespaceRegistry getNamespaceRegistry() {
- if (newNamespaceRegistry != null) return newNamespaceRegistry;
- return delegate.getNamespaceRegistry();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getPropertyFactory()
- */
- public PropertyFactory getPropertyFactory() {
- if (newPropertyFactory != null) return newPropertyFactory;
- return delegate.getPropertyFactory();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getValueFactories()
- */
- public ValueFactories getValueFactories() {
- if (newValueFactories != null) return newValueFactories;
- return delegate.getValueFactories();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getSubject()
- */
- public Subject getSubject() {
- return delegate.getSubject();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLogger(java.lang.Class)
- */
- public Logger getLogger( Class<?> clazz ) {
- return delegate.getLogger(clazz);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLogger(java.lang.String)
- */
- public Logger getLogger( String name ) {
- return delegate.getLogger(name);
- }
-
- /**
- * @return delegate
- */
- protected ExecutionContext getDelegate() {
- return delegate;
- }
- }
-}
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/mimetype/ExtensionBasedMimeTypeDetector.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/mimetype/ExtensionBasedMimeTypeDetector.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/mimetype/ExtensionBasedMimeTypeDetector.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -40,18 +40,7 @@
@Immutable
public class ExtensionBasedMimeTypeDetector implements MimeTypeDetector {
- protected static final ExtensionBasedMimeTypeDetector DEFAULT_INSTANCE = new
ExtensionBasedMimeTypeDetector();
-
/**
- * Get an immutable shared instance of this detector with the {@link
#MIME_TYPE_EXTENSIONS_RESOURCE_PATH default mappings}.
- *
- * @return the shared instance
- */
- public static ExtensionBasedMimeTypeDetector getInstance() {
- return DEFAULT_INSTANCE;
- }
-
- /**
* The default location of the properties file containing the extension patterns to
MIME types.
*/
public static final String MIME_TYPE_EXTENSIONS_RESOURCE_PATH =
"/org/jboss/dna/graph/MimeTypes.properties";
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/SequencerContext.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/SequencerContext.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/sequencers/SequencerContext.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -21,8 +21,13 @@
*/
package org.jboss.dna.graph.sequencers;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.jboss.dna.common.collection.Problems;
+import org.jboss.dna.common.collection.SimpleProblems;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.Path;
@@ -31,21 +36,48 @@
/**
* @author John Verhaeg
*/
-public interface SequencerContext extends ExecutionContext {
+public class SequencerContext extends ExecutionContext {
+ private final Path inputPath;
+ private final Map<Name, Property> inputPropertiesByName;
+ private final Set<Property> inputProperties;
+ private final Problems problems;
+ private final String mimeType;
+
+ public SequencerContext( ExecutionContext context,
+ Path inputPath,
+ Set<Property> inputProperties,
+ String mimeType,
+ Problems problems ) {
+ super(context);
+ this.inputPath = inputPath;
+ this.inputProperties = inputProperties != null ? new
HashSet<Property>(inputProperties) : new HashSet<Property>();
+ this.mimeType = mimeType;
+ this.problems = problems != null ? problems : new SimpleProblems();
+ Map<Name, Property> inputPropertiesByName = new HashMap<Name,
Property>();
+ for (Property property : this.inputProperties) {
+ inputPropertiesByName.put(property.getName(), property);
+ }
+ this.inputPropertiesByName = Collections.unmodifiableMap(inputPropertiesByName);
+ }
+
/**
* Return the path of the input node containing the content being sequenced.
*
* @return input node's path.
*/
- Path getInputPath();
+ public Path getInputPath() {
+ return inputPath;
+ }
/**
* Return the set of properties from the input node containing the content being
sequenced.
*
* @return the input node's properties; never <code>null</code>.
*/
- Set<Property> getInputProperties();
+ public Set<Property> getInputProperties() {
+ return inputProperties;
+ }
/**
* Return the property with the supplied name from the input node containing the
content being sequenced.
@@ -53,14 +85,18 @@
* @param name
* @return the input node property, or <code>null</code> if none exists.
*/
- Property getInputProperty( Name name );
+ public Property getInputProperty( Name name ) {
+ return inputPropertiesByName.get(name);
+ }
/**
* Return the MIME-type of the content being sequenced.
*
* @return the MIME-type
*/
- String getMimeType();
+ public String getMimeType() {
+ return this.mimeType;
+ }
/**
* Get an interface that can be used to record various problems, warnings, and errors
that are not extreme enough to warrant
@@ -68,5 +104,7 @@
*
* @return the interface for recording problems; never null
*/
- Problems getProblems();
+ public Problems getProblems() {
+ return this.problems;
+ }
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/xml/XmlHandler.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/xml/XmlHandler.java 2009-01-15
02:10:17 UTC (rev 705)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/xml/XmlHandler.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -31,7 +31,6 @@
import org.jboss.dna.common.text.TextDecoder;
import org.jboss.dna.common.text.XmlNameEncoder;
import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.NameFactory;
@@ -202,7 +201,7 @@
// Set up a local namespace registry that is kept in sync with the namespaces
found in this XML document ...
NamespaceRegistry namespaceRegistry = new
LocalNamespaceRegistry(this.context.getNamespaceRegistry());
- final ExecutionContext localContext = new BasicExecutionContext(this.context,
namespaceRegistry);
+ final ExecutionContext localContext = this.context.with(namespaceRegistry);
// Set up references to frequently-used objects in the context ...
this.nameFactory = localContext.getValueFactories().getNameFactory();
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphImporterTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -70,7 +70,7 @@
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
xmlContent = new
File("src/test/resources/repositoryImporterTestData1.xml").toURI();
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX,
DnaLexicon.Namespace.URI);
context.getNamespaceRegistry().register("jcr",
"http://www.jcp.org/jcr/1.0");
context.getNamespaceRegistry().register("nt",
"http://www.jcp.org/jcr/nt/1.0");
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphTest.java 2009-01-15 02:10:17
UTC (rev 705)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/GraphTest.java 2009-01-15 16:09:50
UTC (rev 706)
@@ -101,7 +101,7 @@
MockitoAnnotations.initMocks(this);
executedRequests = new LinkedList<Request>();
sourceName = "Source";
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
connection = new MockRepositoryConnection();
stub(connectionFactory.createConnection(sourceName)).toReturn(connection);
graph = new Graph(sourceName, connectionFactory, context);
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/test/AbstractConnectorTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/test/AbstractConnectorTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connectors/test/AbstractConnectorTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -34,7 +34,6 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.jboss.dna.common.stats.Stopwatch;
-import org.jboss.dna.graph.BasicExecutionContextFactory;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.ExecutionContextFactory;
import org.jboss.dna.graph.Graph;
@@ -84,7 +83,7 @@
// Set up the connection factory to other sources ...
// Set up the execution context ...
- contextFactory = new BasicExecutionContextFactory();
+ contextFactory = new ExecutionContext();
context = setUpExecutionContext(contextFactory);
// Set up the source ...
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/AbstractRequestTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/AbstractRequestTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/requests/AbstractRequestTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -24,7 +24,6 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import java.util.UUID;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.properties.Name;
@@ -53,7 +52,7 @@
@Before
public void beforeEach() {
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
Path validPath = createPath("/a/b/c");
UUID validUuid = UUID.randomUUID();
Name idProperty1Name = createName("id1");
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencers/MockSequencerContext.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencers/MockSequencerContext.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/sequencers/MockSequencerContext.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -21,176 +21,19 @@
*/
package org.jboss.dna.graph.sequencers;
-import java.security.AccessControlContext;
-import java.util.Set;
-import javax.security.auth.Subject;
-import javax.security.auth.login.LoginContext;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.collection.SimpleProblems;
-import org.jboss.dna.common.util.Logger;
-import org.jboss.dna.graph.BasicExecutionContext;
-import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
-import org.jboss.dna.graph.mimetype.MimeTypeDetector;
-import org.jboss.dna.graph.properties.Name;
-import org.jboss.dna.graph.properties.NamespaceRegistry;
-import org.jboss.dna.graph.properties.Path;
-import org.jboss.dna.graph.properties.Property;
-import org.jboss.dna.graph.properties.PropertyFactory;
-import org.jboss.dna.graph.properties.ValueFactories;
/**
* @author John Verhaeg
*/
@Immutable
-public class MockSequencerContext implements SequencerContext {
+public class MockSequencerContext extends SequencerContext {
- private final ExecutionContext context = new BasicExecutionContext();
- private final Problems problems = new SimpleProblems();
-
public MockSequencerContext() {
- NamespaceRegistry registry = context.getNamespaceRegistry();
- registry.register("jcr", "http://www.jcp.org/jcr/1.0");
- registry.register("mix", "http://www.jcp.org/jcr/mix/1.0");
- registry.register("nt", "http://www.jcp.org/jcr/nt/1.0");
- registry.register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
- registry.register("dnadtd",
"http://www.jboss.org/dna/dtd/1.0");
- registry.register("dnaxml",
"http://www.jboss.org/dna/xml/1.0");
+ super(new ExecutionContext(), null, null, null, new SimpleProblems());
+ getNamespaceRegistry().register("dnadtd",
"http://www.jboss.org/dna/dtd/1.0");
+ getNamespaceRegistry().register("dnaxml",
"http://www.jboss.org/dna/xml/1.0");
}
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.common.component.ClassLoaderFactory#getClassLoader(java.lang.String[])
- */
- public ClassLoader getClassLoader( String... classpath ) {
- return context.getClassLoader(classpath);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getMimeTypeDetector()
- */
- public MimeTypeDetector getMimeTypeDetector() {
- return context.getMimeTypeDetector();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.sequencers.SequencerContext#getInputPath()
- */
- public Path getInputPath() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.sequencers.SequencerContext#getInputProperties()
- */
- public Set<Property> getInputProperties() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.sequencers.SequencerContext#getInputProperty(org.jboss.dna.graph.properties.Name)
- */
- public Property getInputProperty( Name name ) {
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.sequencers.SequencerContext#getMimeType()
- */
- public String getMimeType() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.sequencers.SequencerContext#getProblems()
- */
- public Problems getProblems() {
- return problems;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getAccessControlContext()
- */
- public AccessControlContext getAccessControlContext() {
- return context.getAccessControlContext();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLogger(java.lang.Class)
- */
- public Logger getLogger( Class<?> clazz ) {
- return context.getLogger(clazz);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLogger(java.lang.String)
- */
- public Logger getLogger( String name ) {
- return context.getLogger(name);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLoginContext()
- */
- public LoginContext getLoginContext() {
- return context.getLoginContext();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getNamespaceRegistry()
- */
- public NamespaceRegistry getNamespaceRegistry() {
- return context.getNamespaceRegistry();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getPropertyFactory()
- */
- public PropertyFactory getPropertyFactory() {
- return context.getPropertyFactory();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getSubject()
- */
- public Subject getSubject() {
- return context.getSubject();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getValueFactories()
- */
- public ValueFactories getValueFactories() {
- return context.getValueFactories();
- }
}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/xml/XmlHandlerTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/xml/XmlHandlerTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/xml/XmlHandlerTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -35,7 +35,6 @@
import java.util.Map;
import org.jboss.dna.common.text.Jsr283Encoder;
import org.jboss.dna.common.text.TextDecoder;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.JcrLexicon;
import org.jboss.dna.graph.Location;
@@ -73,7 +72,7 @@
@Before
public void beforeEach() {
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
context.getNamespaceRegistry().register(JcrLexicon.Namespace.PREFIX,
JcrLexicon.Namespace.URI);
context.getNamespaceRegistry().register("nt", NT_NAMESPACE_URI);
destination = new RecordingDestination();
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java
===================================================================
---
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrMultiValuePropertyTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -35,7 +35,6 @@
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
import javax.jcr.nodetype.PropertyDefinition;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.Path;
@@ -53,7 +52,7 @@
private Property prop;
@Mock
private Node node;
- private ExecutionContext executionContext = new BasicExecutionContext();
+ private ExecutionContext executionContext = new ExecutionContext();
@Mock
Name name;
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2009-01-15 02:10:17
UTC (rev 705)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyTest.java 2009-01-15 16:09:50
UTC (rev 706)
@@ -34,7 +34,6 @@
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
import javax.jcr.nodetype.PropertyDefinition;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.Path;
@@ -52,7 +51,7 @@
private Property prop;
@Mock
private Node node;
- private ExecutionContext executionContext = new BasicExecutionContext();
+ private ExecutionContext executionContext = new ExecutionContext();
@Mock
Name name;
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java 2009-01-15 02:10:17 UTC
(rev 705)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TestUtil.java 2009-01-15 16:09:50 UTC
(rev 706)
@@ -26,7 +26,6 @@
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginContext;
import net.jcip.annotations.NotThreadSafe;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.ExecutionContextFactory;
import org.jboss.dna.graph.connectors.RepositoryConnection;
@@ -503,7 +502,7 @@
}
public static ExecutionContextFactory getExecutionContextFactory() {
- final ExecutionContext context = new
BasicExecutionContext(Mockito.mock(LoginContext.class));
+ final ExecutionContext context = new
ExecutionContext().create(Mockito.mock(LoginContext.class));
NamespaceRegistry registry = context.getNamespaceRegistry();
registry.register("dna", "http://www.jboss.org/dna/1.0");
registry.register("fn",
"http://www.w3.org/2005/xpath-functions");
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -33,7 +33,6 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.graph.BasicExecutionContextFactory;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.ExecutionContextFactory;
import org.jboss.dna.graph.connectors.RepositoryConnection;
@@ -113,7 +112,7 @@
* Create a new manager instance.
*/
public RepositoryLibrary() {
- this(new BasicExecutionContextFactory(), null);
+ this(new ExecutionContext(), null);
}
/**
@@ -123,7 +122,7 @@
* this manager; may be null if there is no delegate
*/
public RepositoryLibrary( RepositoryConnectionFactory delegate ) {
- this(new BasicExecutionContextFactory(), delegate);
+ this(new ExecutionContext(), delegate);
}
/**
Deleted:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencerNodeContext.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -1,304 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, 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.dna.repository.sequencers;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.AccessControlContext;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import javax.jcr.Node;
-import javax.jcr.PropertyIterator;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.security.auth.Subject;
-import javax.security.auth.login.LoginContext;
-import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.collection.Problems;
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.Logger;
-import org.jboss.dna.graph.mimetype.MimeTypeDetector;
-import org.jboss.dna.graph.properties.Name;
-import org.jboss.dna.graph.properties.NamespaceRegistry;
-import org.jboss.dna.graph.properties.Path;
-import org.jboss.dna.graph.properties.Property;
-import org.jboss.dna.graph.properties.PropertyFactory;
-import org.jboss.dna.graph.properties.ValueFactories;
-import org.jboss.dna.graph.sequencers.SequencerContext;
-import org.jboss.dna.graph.sequencers.StreamSequencer;
-import org.jboss.dna.repository.RepositoryI18n;
-import org.jboss.dna.repository.mimetype.MimeType;
-import org.jboss.dna.repository.util.JcrExecutionContext;
-
-/**
- * Contains context information that is passed to {@link StreamSequencer stream
sequencers}, including information about the input
- * node containing the data being sequenced.
- *
- * @author John Verhaeg
- */
-@Immutable
-public class SequencerNodeContext implements SequencerContext {
-
- private final javax.jcr.Property sequencedProperty;
- private final ValueFactories factories;
- private final Path path;
- private final Set<Property> props;
- private final JcrExecutionContext context;
- private final Problems problems;
-
- SequencerNodeContext( Node input,
- javax.jcr.Property sequencedProperty,
- JcrExecutionContext context,
- Problems problems ) throws RepositoryException {
- assert input != null;
- assert sequencedProperty != null;
- assert context != null;
- assert problems != null;
- this.context = context;
- this.sequencedProperty = sequencedProperty;
- this.problems = problems;
- this.factories = context.getValueFactories();
- // Translate JCR path and property values to DNA constructs and cache them to
improve performance and prevent
- // RepositoryException from being thrown by getters
- // Note: getMimeType() will still operate lazily, and thus throw a
SequencerException, since it is very intrusive and
- // potentially slow-running.
- path = factories.getPathFactory().create(input.getPath());
- Set<Property> props = new HashSet<Property>();
- for (PropertyIterator iter = input.getProperties(); iter.hasNext();) {
- javax.jcr.Property jcrProp = iter.nextProperty();
- Property prop;
- if (jcrProp.getDefinition().isMultiple()) {
- Value[] jcrVals = jcrProp.getValues();
- Object[] vals = new Object[jcrVals.length];
- int ndx = 0;
- for (Value jcrVal : jcrVals) {
- vals[ndx++] = convert(factories, jcrProp.getName(), jcrVal);
- }
- prop =
context.getPropertyFactory().create(factories.getNameFactory().create(jcrProp.getName()),
vals);
- } else {
- Value jcrVal = jcrProp.getValue();
- Object val = convert(factories, jcrProp.getName(), jcrVal);
- prop =
context.getPropertyFactory().create(factories.getNameFactory().create(jcrProp.getName()),
val);
- }
- props.add(prop);
- }
- this.props = Collections.unmodifiableSet(props);
- }
-
- private Object convert( ValueFactories factories,
- String name,
- Value jcrValue ) throws RepositoryException {
- switch (jcrValue.getType()) {
- case PropertyType.BINARY: {
- return factories.getBinaryFactory().create(jcrValue.getStream());
- }
- case PropertyType.BOOLEAN: {
- return factories.getBooleanFactory().create(jcrValue.getBoolean());
- }
- case PropertyType.DATE: {
- return factories.getDateFactory().create(jcrValue.getDate());
- }
- case PropertyType.DOUBLE: {
- return factories.getDoubleFactory().create(jcrValue.getDouble());
- }
- case PropertyType.LONG: {
- return factories.getLongFactory().create(jcrValue.getLong());
- }
- case PropertyType.NAME: {
- return factories.getNameFactory().create(jcrValue.getString());
- }
- case PropertyType.PATH: {
- return factories.getPathFactory().create(jcrValue.getString());
- }
- case PropertyType.REFERENCE: {
- return factories.getReferenceFactory().create(jcrValue.getString());
- }
- case PropertyType.STRING: {
- return factories.getStringFactory().create(jcrValue.getString());
- }
- default: {
- throw new
RepositoryException(RepositoryI18n.unknownPropertyValueType.text(name,
jcrValue.getType()));
- }
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getAccessControlContext()
- */
- public AccessControlContext getAccessControlContext() {
- return context.getAccessControlContext();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.common.component.ClassLoaderFactory#getClassLoader(java.lang.String[])
- */
- public ClassLoader getClassLoader( String... classpath ) {
- return context.getClassLoader(classpath);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getMimeTypeDetector()
- */
- public MimeTypeDetector getMimeTypeDetector() {
- return context.getMimeTypeDetector();
- }
-
- /**
- * {@inheritDoc}
- */
- public ValueFactories getValueFactories() {
- return factories;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.sequencers.SequencerContext#getInputPath()
- */
- public Path getInputPath() {
- return path;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.sequencers.SequencerContext#getInputProperties()
- */
- public Set<Property> getInputProperties() {
- return props;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.graph.sequencers.SequencerContext#getInputProperty(org.jboss.dna.graph.properties.Name)
- */
- public Property getInputProperty( Name name ) {
- CheckArg.isNotNull(name, "name");
- for (Property prop : props) {
- if (name.equals(prop.getName())) {
- return prop;
- }
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.sequencers.SequencerContext#getProblems()
- */
- public Problems getProblems() {
- return problems;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.sequencers.SequencerContext#getMimeType()
- */
- @SuppressWarnings( "null" )
- // The need for the SuppressWarnings looks like an Eclipse bug
- public String getMimeType() {
- SequencerException err = null;
- String mimeType = null;
- InputStream stream = null;
- try {
- stream = sequencedProperty.getStream();
- mimeType = MimeType.of(path.getLastSegment().getName().getLocalName(),
stream);
- return mimeType;
- } catch (Exception error) {
- err = new SequencerException(error);
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException error) {
- // Only throw exception if an exception was not already thrown
- if (err == null) err = new SequencerException(error);
- }
- }
- }
- if (err != null) throw err;
- return mimeType;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.sequencers.SequencerContext#getLogger(java.lang.Class)
- */
- public Logger getLogger( Class<?> clazz ) {
- return context.getLogger(clazz);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.sequencers.SequencerContext#getLogger(java.lang.String)
- */
- public Logger getLogger( String name ) {
- return context.getLogger(name);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLoginContext()
- */
- public LoginContext getLoginContext() {
- return context.getLoginContext();
- }
-
- /**
- * {@inheritDoc}
- */
- public NamespaceRegistry getNamespaceRegistry() {
- return factories.getNameFactory().getNamespaceRegistry();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getPropertyFactory()
- */
- public PropertyFactory getPropertyFactory() {
- return context.getPropertyFactory();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getSubject()
- */
- public Subject getSubject() {
- return context.getSubject();
- }
-}
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -21,7 +21,6 @@
*/
package org.jboss.dna.repository.sequencers;
-import java.security.AccessControlContext;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -32,15 +31,12 @@
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.observation.Event;
-import javax.security.auth.Subject;
-import javax.security.auth.login.LoginContext;
import net.jcip.annotations.Immutable;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.collection.SimpleProblems;
@@ -50,10 +46,6 @@
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.common.util.Logger;
-import org.jboss.dna.graph.mimetype.MimeTypeDetector;
-import org.jboss.dna.graph.properties.NamespaceRegistry;
-import org.jboss.dna.graph.properties.PropertyFactory;
-import org.jboss.dna.graph.properties.ValueFactories;
import org.jboss.dna.repository.RepositoryI18n;
import org.jboss.dna.repository.observation.NodeChange;
import org.jboss.dna.repository.observation.NodeChangeListener;
@@ -62,9 +54,7 @@
import org.jboss.dna.repository.services.AdministeredService;
import org.jboss.dna.repository.services.ServiceAdministrator;
import org.jboss.dna.repository.util.JcrExecutionContext;
-import org.jboss.dna.repository.util.JcrTools;
import org.jboss.dna.repository.util.RepositoryNodePath;
-import org.jboss.dna.repository.util.SessionFactory;
/**
* A sequencing system is used to monitor changes in the content of {@link Repository JCR
repositories} and to sequence the
@@ -524,10 +514,10 @@
assert outputPaths != null && outputPaths.size() != 0;
// Create a new execution context for each sequencer
- final Context executionContext = new Context(context);
final SimpleProblems problems = new SimpleProblems();
+ JcrExecutionContext sequencerContext = context.clone();
try {
- sequencer.execute(node, propertyName, changedNode,
outputPaths, executionContext, problems);
+ sequencer.execute(node, propertyName, changedNode,
outputPaths, sequencerContext, problems);
} catch (RepositoryException e) {
logger.error(e,
RepositoryI18n.errorInRepositoryWhileSequencingNode, sequencerName, changedNode);
} catch (SequencerException e) {
@@ -539,7 +529,7 @@
} finally {
// And always close the context.
// This closes all sessions that may have been created by
the sequencer.
- executionContext.close();
+ sequencerContext.close();
}
}
}
@@ -555,138 +545,6 @@
}
}
- protected class Context implements JcrExecutionContext {
-
- protected final JcrExecutionContext delegate;
- protected final SessionFactory factory;
- private final Set<Session> sessions = new HashSet<Session>();
- protected final AtomicBoolean closed = new AtomicBoolean(false);
-
- protected Context( JcrExecutionContext context ) {
- this.delegate = context;
- final SessionFactory delegateSessionFactory =
this.delegate.getSessionFactory();
- this.factory = new SessionFactory() {
-
- public Session createSession( String name ) throws RepositoryException {
- if (closed.get()) throw new
IllegalStateException(RepositoryI18n.executionContextHasBeenClosed.text());
- Session session = delegateSessionFactory.createSession(name);
- recordSession(session);
- return session;
- }
- };
- }
-
- public synchronized void close() {
- if (this.closed.get()) return;
- this.closed.set(true);
- for (Session session : sessions) {
- if (session != null) session.logout();
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.common.component.ClassLoaderFactory#getClassLoader(java.lang.String[])
- */
- public ClassLoader getClassLoader( String... classpath ) {
- return delegate.getClassLoader(classpath);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getMimeTypeDetector()
- */
- public MimeTypeDetector getMimeTypeDetector() {
- return delegate.getMimeTypeDetector();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getAccessControlContext()
- */
- public AccessControlContext getAccessControlContext() {
- return delegate.getAccessControlContext();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLoginContext()
- */
- public LoginContext getLoginContext() {
- return delegate.getLoginContext();
- }
-
- /**
- * {@inheritDoc}
- */
- public NamespaceRegistry getNamespaceRegistry() {
- return this.delegate.getNamespaceRegistry();
- }
-
- /**
- * {@inheritDoc}
- */
- public PropertyFactory getPropertyFactory() {
- return this.delegate.getPropertyFactory();
- }
-
- /**
- * {@inheritDoc}
- */
- public SessionFactory getSessionFactory() {
- return this.factory;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getSubject()
- */
- public Subject getSubject() {
- return this.delegate.getSubject();
- }
-
- /**
- * {@inheritDoc}
- */
- public JcrTools getTools() {
- return SequencingService.this.getExecutionContext().getTools();
- }
-
- /**
- * {@inheritDoc}
- */
- public ValueFactories getValueFactories() {
- return this.delegate.getValueFactories();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLogger(java.lang.Class)
- */
- public Logger getLogger( Class<?> clazz ) {
- return this.delegate.getLogger(clazz);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.ExecutionContext#getLogger(java.lang.String)
- */
- public Logger getLogger( String name ) {
- return this.delegate.getLogger(name);
- }
-
- protected synchronized void recordSession( Session session ) {
- if (session != null) sessions.add(session);
- }
- }
-
/**
* The statistics for the system. Each sequencing system has an instance of this
class that is updated.
*
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapter.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -21,26 +21,36 @@
*/
package org.jboss.dna.repository.sequencers;
+import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.Calendar;
+import java.util.Collections;
import java.util.Date;
+import java.util.HashSet;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.Value;
import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.util.Logger;
+import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.properties.Binary;
import org.jboss.dna.graph.properties.DateTime;
import org.jboss.dna.graph.properties.Name;
import org.jboss.dna.graph.properties.NamespaceRegistry;
import org.jboss.dna.graph.properties.Path;
import org.jboss.dna.graph.properties.PathFactory;
+import org.jboss.dna.graph.properties.ValueFactories;
+import org.jboss.dna.graph.sequencers.SequencerContext;
import org.jboss.dna.graph.sequencers.StreamSequencer;
import org.jboss.dna.repository.RepositoryI18n;
+import org.jboss.dna.repository.mimetype.MimeType;
import org.jboss.dna.repository.observation.NodeChange;
import org.jboss.dna.repository.util.JcrExecutionContext;
import org.jboss.dna.repository.util.RepositoryNodePath;
@@ -103,7 +113,7 @@
Throwable firstError = null;
try {
stream = sequencedProperty.getStream();
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
+ SequencerContext sequencerContext = createSequencerContext(input,
sequencedProperty, execContext, problems);
this.streamSequencer.sequence(stream, output, sequencerContext);
} catch (Throwable t) {
// Record the error ...
@@ -288,4 +298,105 @@
return null;
}
+ protected SequencerContext createSequencerContext( Node input,
+ Property sequencedProperty,
+ ExecutionContext context,
+ Problems problems ) throws
RepositoryException {
+ assert input != null;
+ assert sequencedProperty != null;
+ assert context != null;
+ assert problems != null;
+ // Translate JCR path and property values to DNA constructs and cache them to
improve performance and prevent
+ // RepositoryException from being thrown by getters
+ // Note: getMimeType() will still operate lazily, and thus throw a
SequencerException, since it is very intrusive and
+ // potentially slow-running.
+ ValueFactories factories = context.getValueFactories();
+ Path path = factories.getPathFactory().create(input.getPath());
+ Set<org.jboss.dna.graph.properties.Property> props = new
HashSet<org.jboss.dna.graph.properties.Property>();
+ for (PropertyIterator iter = input.getProperties(); iter.hasNext();) {
+ javax.jcr.Property jcrProp = iter.nextProperty();
+ org.jboss.dna.graph.properties.Property prop;
+ if (jcrProp.getDefinition().isMultiple()) {
+ Value[] jcrVals = jcrProp.getValues();
+ Object[] vals = new Object[jcrVals.length];
+ int ndx = 0;
+ for (Value jcrVal : jcrVals) {
+ vals[ndx++] = convert(factories, jcrProp.getName(), jcrVal);
+ }
+ prop =
context.getPropertyFactory().create(factories.getNameFactory().create(jcrProp.getName()),
vals);
+ } else {
+ Value jcrVal = jcrProp.getValue();
+ Object val = convert(factories, jcrProp.getName(), jcrVal);
+ prop =
context.getPropertyFactory().create(factories.getNameFactory().create(jcrProp.getName()),
val);
+ }
+ props.add(prop);
+ }
+ props = Collections.unmodifiableSet(props);
+ String mimeType = getMimeType(sequencedProperty,
path.getLastSegment().getName().getLocalName());
+ return new SequencerContext(context, path, props, mimeType, problems);
+ }
+
+ protected Object convert( ValueFactories factories,
+ String name,
+ Value jcrValue ) throws RepositoryException {
+ switch (jcrValue.getType()) {
+ case PropertyType.BINARY: {
+ return factories.getBinaryFactory().create(jcrValue.getStream());
+ }
+ case PropertyType.BOOLEAN: {
+ return factories.getBooleanFactory().create(jcrValue.getBoolean());
+ }
+ case PropertyType.DATE: {
+ return factories.getDateFactory().create(jcrValue.getDate());
+ }
+ case PropertyType.DOUBLE: {
+ return factories.getDoubleFactory().create(jcrValue.getDouble());
+ }
+ case PropertyType.LONG: {
+ return factories.getLongFactory().create(jcrValue.getLong());
+ }
+ case PropertyType.NAME: {
+ return factories.getNameFactory().create(jcrValue.getString());
+ }
+ case PropertyType.PATH: {
+ return factories.getPathFactory().create(jcrValue.getString());
+ }
+ case PropertyType.REFERENCE: {
+ return factories.getReferenceFactory().create(jcrValue.getString());
+ }
+ case PropertyType.STRING: {
+ return factories.getStringFactory().create(jcrValue.getString());
+ }
+ default: {
+ throw new
RepositoryException(RepositoryI18n.unknownPropertyValueType.text(name,
jcrValue.getType()));
+ }
+ }
+ }
+
+ @SuppressWarnings( "null" )
+ // The need for the SuppressWarnings looks like an Eclipse bug
+ protected String getMimeType( Property sequencedProperty,
+ String name ) {
+ SequencerException err = null;
+ String mimeType = null;
+ InputStream stream = null;
+ try {
+ stream = sequencedProperty.getStream();
+ mimeType = MimeType.of(name, stream);
+ return mimeType;
+ } catch (Exception error) {
+ err = new SequencerException(error);
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException error) {
+ // Only throw exception if an exception was not already thrown
+ if (err == null) err = new SequencerException(error);
+ }
+ }
+ }
+ if (err != null) throw err;
+ return mimeType;
+ }
}
Deleted:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/BasicJcrExecutionContext.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/BasicJcrExecutionContext.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/BasicJcrExecutionContext.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -1,72 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, 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.dna.repository.util;
-
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.graph.BasicExecutionContext;
-import org.jboss.dna.graph.properties.NamespaceRegistry;
-import org.jboss.dna.graph.properties.PropertyFactory;
-import org.jboss.dna.graph.properties.ValueFactories;
-
-/**
- * @author Randall Hauch
- * @author John Verhaeg
- */
-public class BasicJcrExecutionContext extends BasicExecutionContext implements
JcrExecutionContext {
-
- private final JcrTools tools = new JcrTools();
- private final SessionFactory sessionFactory;
-
- public BasicJcrExecutionContext( SessionFactory sessionFactory,
- String repositoryWorkspaceForNamespaceRegistry ) {
- this(sessionFactory, new JcrNamespaceRegistry(sessionFactory,
repositoryWorkspaceForNamespaceRegistry), null, null);
- }
-
- public BasicJcrExecutionContext( SessionFactory sessionFactory,
- NamespaceRegistry namespaceRegistry ) {
- this(sessionFactory, namespaceRegistry, null, null);
- }
-
- public BasicJcrExecutionContext( SessionFactory sessionFactory,
- NamespaceRegistry namespaceRegistry,
- ValueFactories valueFactories,
- PropertyFactory propertyFactory ) {
- super(namespaceRegistry, valueFactories, propertyFactory);
- CheckArg.isNotNull(sessionFactory, "session factory");
- this.sessionFactory = sessionFactory;
- }
-
- /**
- * {@inheritDoc}
- */
- public SessionFactory getSessionFactory() {
- return this.sessionFactory;
- }
-
- /**
- * {@inheritDoc}
- */
- public JcrTools getTools() {
- return this.tools;
- }
-
-}
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrExecutionContext.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrExecutionContext.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrExecutionContext.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -21,29 +21,103 @@
*/
package org.jboss.dna.repository.util;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.repository.RepositoryI18n;
/**
* The context of an execution within a JCR environment.
*
* @author Randall Hauch
*/
-public interface JcrExecutionContext extends ExecutionContext {
+public class JcrExecutionContext extends ExecutionContext {
+ private final String repositoryWorkspaceForNamespaceRegistry;
+ private final ClosableSessionFactory sessionFactory;
+ private final JcrTools jcrTools;
+
+ public JcrExecutionContext( ExecutionContext context,
+ final SessionFactory sessionFactory,
+ String repositoryWorkspaceForNamespaceRegistry ) {
+ super(context.with(new JcrNamespaceRegistry(sessionFactory,
repositoryWorkspaceForNamespaceRegistry)));
+ this.sessionFactory = new ClosableSessionFactory(sessionFactory);
+ this.jcrTools = new JcrTools();
+ this.repositoryWorkspaceForNamespaceRegistry =
repositoryWorkspaceForNamespaceRegistry;
+ }
+
+ public JcrExecutionContext( SessionFactory sessionFactory,
+ String repositoryWorkspaceForNamespaceRegistry ) {
+ this(new ExecutionContext(), sessionFactory,
repositoryWorkspaceForNamespaceRegistry);
+ }
+
/**
* Get the session factory, which can be used to obtain sessions temporarily for this
context. Any session obtained from this
* factory should be {@link Session#logout() closed} before the execution finishes.
*
* @return the session factory
*/
- SessionFactory getSessionFactory();
+ public SessionFactory getSessionFactory() {
+ return this.sessionFactory;
+ }
/**
* Get a set of utilities for working with JCR.
*
* @return the tools
*/
- JcrTools getTools();
+ public JcrTools getTools() {
+ return this.jcrTools;
+ }
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.ExecutionContext#clone()
+ */
+ @Override
+ public JcrExecutionContext clone() {
+ return new JcrExecutionContext(this, this.sessionFactory.getDelegateFactory(),
+ this.repositoryWorkspaceForNamespaceRegistry);
+ }
+
+ /**
+ * This this context and release all resources (including any Session instances
created).
+ */
+ public void close() {
+ this.sessionFactory.close();
+ }
+
+ protected static class ClosableSessionFactory implements SessionFactory {
+ private final SessionFactory delegateFactory;
+ private final Set<Session> sessions = new HashSet<Session>();
+ protected final AtomicBoolean closed = new AtomicBoolean(false);
+
+ protected ClosableSessionFactory( SessionFactory sessionFactory ) {
+ this.delegateFactory = sessionFactory;
+ }
+
+ public SessionFactory getDelegateFactory() {
+ return this.delegateFactory;
+ }
+
+ public Session createSession( String name ) throws RepositoryException {
+ if (closed.get()) throw new
IllegalStateException(RepositoryI18n.executionContextHasBeenClosed.text());
+ Session session = delegateFactory.createSession(name);
+ if (session != null) sessions.add(session);
+ return session;
+ }
+
+ public synchronized void close() {
+ if (this.closed.get()) return;
+ this.closed.set(true);
+ for (Session session : sessions) {
+ if (session != null) session.logout();
+ }
+ }
+ }
+
}
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -35,7 +35,6 @@
import java.util.concurrent.TimeUnit;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.connector.federation.FederationException;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.connectors.RepositoryConnection;
@@ -68,7 +67,7 @@
@Before
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX,
DnaLexicon.Namespace.URI);
configSourceName = "configSource";
configRepository = SimpleRepository.get("Configuration Repository");
Deleted:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencerNodeContextTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -1,178 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, 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.dna.repository.sequencers;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.junit.Assert.assertThat;
-import java.io.IOException;
-import java.util.Iterator;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import org.jboss.dna.common.collection.Problems;
-import org.jboss.dna.common.collection.SimpleProblems;
-import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
-import org.jboss.dna.graph.properties.NamespaceRegistry;
-import org.jboss.dna.graph.properties.Property;
-import org.jboss.dna.graph.sequencers.SequencerContext;
-import org.jboss.dna.repository.util.BasicJcrExecutionContext;
-import org.jboss.dna.repository.util.JcrExecutionContext;
-import org.jboss.dna.repository.util.JcrNamespaceRegistry;
-import org.jboss.dna.repository.util.JcrTools;
-import org.jboss.dna.repository.util.SessionFactory;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.MockitoAnnotations;
-import org.mockito.MockitoAnnotations.Mock;
-
-/**
- * @author John Verhaeg
- */
-public class SequencerNodeContextTest extends AbstractJcrRepositoryTest {
-
- private JcrExecutionContext execContext;
- private Session session;
- private JcrTools tools;
- private Problems problems;
- @Mock
- private javax.jcr.Property sequencedProperty;
-
- @Before
- public void before() throws Exception {
- MockitoAnnotations.initMocks(this);
- final SessionFactory sessionFactory = new SessionFactory() {
-
- public Session createSession( String name ) throws RepositoryException {
- try {
- return getRepository().login(getTestCredentials());
- } catch (IOException error) {
- throw new RepositoryException(error);
- }
- }
- };
- NamespaceRegistry registry = new JcrNamespaceRegistry(sessionFactory,
"doesn't matter");
- execContext = new BasicJcrExecutionContext(sessionFactory, registry, null,
null);
- startRepository();
- session = getRepository().login(getTestCredentials());
- tools = new JcrTools();
- problems = new SimpleProblems();
- }
-
- @After
- public void after() {
- if (session != null) {
- try {
- session.logout();
- } finally {
- session = null;
- }
- }
- }
-
- private void verifyProperty( SequencerContext context,
- String name,
- Object... values ) {
- Property prop =
context.getInputProperty(execContext.getValueFactories().getNameFactory().create(name));
- assertThat(prop, notNullValue());
- assertThat(prop.getName(),
is(execContext.getValueFactories().getNameFactory().create(name)));
- assertThat(prop.isEmpty(), is(false));
- assertThat(prop.size(), is(values.length));
- assertThat(prop.isMultiple(), is(values.length > 1));
- assertThat(prop.isSingle(), is(values.length == 1));
- Iterator<?> iter = prop.getValues();
- for (Object val : values) {
- assertThat(iter.hasNext(), is(true));
- assertThat(iter.next(), is(val));
- }
- }
-
- @Test( expected = java.lang.AssertionError.class )
- public void shouldNotAllowNullInputNode() throws Exception {
- new SequencerNodeContext(null, sequencedProperty, execContext, problems);
- }
-
- @Test( expected = java.lang.AssertionError.class )
- public void shouldNotAllowNullSequencedProperty() throws Exception {
- Node input = tools.findOrCreateNode(session, "/a");
- new SequencerNodeContext(input, null, execContext, problems);
- }
-
- @Test( expected = java.lang.AssertionError.class )
- public void shouldNotAllowNullExecutionContext() throws Exception {
- Node input = tools.findOrCreateNode(session, "/a");
- new SequencerNodeContext(input, sequencedProperty, null, problems);
- }
-
- @Test
- public void shouldProvideNamespaceRegistry() throws Exception {
- Node input = tools.findOrCreateNode(session, "/a/b/c");
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
- assertThat(sequencerContext.getNamespaceRegistry(), notNullValue());
- }
-
- @Test
- public void shouldProvideValueFactories() throws Exception {
- Node input = tools.findOrCreateNode(session, "/a/b/c");
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
- assertThat(sequencerContext.getValueFactories(), notNullValue());
- }
-
- @Test
- public void shouldProvidePathToInput() throws Exception {
- Node input = tools.findOrCreateNode(session, "/a/b/c");
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
- assertThat(sequencerContext.getInputPath(),
is(execContext.getValueFactories().getPathFactory().create("/a/b/c")));
- }
-
- @Test
- public void shouldNeverReturnNullInputProperties() throws Exception {
- Node input = tools.findOrCreateNode(session, "/a/b/c");
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
- assertThat(sequencerContext.getInputProperties(), notNullValue());
- assertThat(sequencerContext.getInputProperties().isEmpty(), is(false));
- }
-
- @Test
- public void shouldProvideInputProperties() throws Exception {
- Node input = tools.findOrCreateNode(session, "/a/b/c");
- input.setProperty("x", true);
- input.setProperty("y", new String[] {"asdf",
"xyzzy"});
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
- assertThat(sequencerContext.getInputProperties(), notNullValue());
- assertThat(sequencerContext.getInputProperties().isEmpty(), is(false));
- assertThat(sequencerContext.getInputProperties().size(), is(3));
- verifyProperty(sequencerContext,
- "jcr:primaryType",
-
execContext.getValueFactories().getNameFactory().create("{http://www...);
- verifyProperty(sequencerContext, "x", true);
- verifyProperty(sequencerContext, "y", "asdf",
"xyzzy");
- }
-
- @Test
- public void shouldProvideMimeType() throws Exception {
- Node input = tools.findOrCreateNode(session, "/a/b/c");
- SequencerNodeContext sequencerContext = new SequencerNodeContext(input,
sequencedProperty, execContext, problems);
- assertThat(sequencerContext.getMimeType(), is("text/plain"));
- }
-}
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencingServiceTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencingServiceTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencingServiceTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -28,15 +28,18 @@
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItem;
+import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.jcr.Node;
+import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.observation.Event;
+import org.jboss.dna.common.SystemFailureException;
import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
import org.jboss.dna.repository.observation.ObservationService;
import org.jboss.dna.repository.services.ServiceAdministrator;
import org.jboss.dna.repository.util.JcrExecutionContext;
-import org.jboss.dna.repository.util.MockJcrExecutionContext;
+import org.jboss.dna.repository.util.SessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -56,7 +59,17 @@
@Before
public void beforeEach() {
- this.executionContext = new MockJcrExecutionContext(this,
REPOSITORY_WORKSPACE_NAME);
+ SessionFactory sessionFactory = new SessionFactory() {
+ public Session createSession( String name ) throws RepositoryException {
+ assertThat(name, is(REPOSITORY_WORKSPACE_NAME));
+ try {
+ return getRepository().login(getTestCredentials());
+ } catch (IOException e) {
+ throw new SystemFailureException(e);
+ }
+ }
+ };
+ this.executionContext = new JcrExecutionContext(sessionFactory,
REPOSITORY_WORKSPACE_NAME);
this.sequencingService = new SequencingService();
this.sequencingService.setExecutionContext(this.executionContext);
this.observationService = new
ObservationService(this.executionContext.getSessionFactory());
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/StreamSequencerAdapterTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -27,10 +27,12 @@
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.Session;
@@ -38,15 +40,13 @@
import org.jboss.dna.common.collection.Problems;
import org.jboss.dna.common.collection.SimpleProblems;
import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
-import org.jboss.dna.graph.properties.NamespaceRegistry;
import org.jboss.dna.graph.properties.Path;
+import org.jboss.dna.graph.properties.Property;
import org.jboss.dna.graph.sequencers.SequencerContext;
import org.jboss.dna.graph.sequencers.SequencerOutput;
import org.jboss.dna.graph.sequencers.StreamSequencer;
import org.jboss.dna.repository.observation.NodeChange;
-import org.jboss.dna.repository.util.BasicJcrExecutionContext;
import org.jboss.dna.repository.util.JcrExecutionContext;
-import org.jboss.dna.repository.util.JcrNamespaceRegistry;
import org.jboss.dna.repository.util.JcrTools;
import org.jboss.dna.repository.util.RepositoryNodePath;
import org.jboss.dna.repository.util.SessionFactory;
@@ -71,6 +71,7 @@
private JcrExecutionContext context;
private String repositoryWorkspaceName = "something";
private Problems problems;
+ private javax.jcr.Property sequencedProperty;
@Before
public void beforeEach() {
@@ -83,8 +84,7 @@
}
};
problems = new SimpleProblems();
- NamespaceRegistry registry = new JcrNamespaceRegistry(sessionFactory,
"doesn't matter");
- this.context = new BasicJcrExecutionContext(sessionFactory, registry, null,
null);
+ this.context = new JcrExecutionContext(sessionFactory, "doesn't
matter");
this.sequencerOutput = new SequencerOutputMap(this.context.getValueFactories());
final SequencerOutputMap finalOutput = sequencerOutput;
this.streamSequencer = new StreamSequencer() {
@@ -400,4 +400,120 @@
});
}
+ @Test( expected = java.lang.AssertionError.class )
+ public void shouldNotAllowNullInputNode() throws Exception {
+ sequencer.createSequencerContext(null, sequencedProperty, context, problems);
+ }
+
+ @Test( expected = java.lang.AssertionError.class )
+ public void shouldNotAllowNullSequencedProperty() throws Exception {
+ startRepository();
+ session = getRepository().login(getTestCredentials());
+
+ Node input = tools.findOrCreateNode(session, "/a");
+ sequencer.createSequencerContext(input, null, context, problems);
+ }
+
+ @Test( expected = java.lang.AssertionError.class )
+ public void shouldNotAllowNullExecutionContext() throws Exception {
+ startRepository();
+ session = getRepository().login(getTestCredentials());
+
+ Node input = tools.findOrCreateNode(session, "/a");
+ sequencer.createSequencerContext(input, sequencedProperty, null, problems);
+ }
+
+ @Test
+ public void shouldProvideNamespaceRegistry() throws Exception {
+ startRepository();
+ session = getRepository().login(getTestCredentials());
+
+ this.sequencedProperty = mock(javax.jcr.Property.class);
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerContext sequencerContext = sequencer.createSequencerContext(input,
sequencedProperty, context, problems);
+ assertThat(sequencerContext.getNamespaceRegistry(), notNullValue());
+ }
+
+ @Test
+ public void shouldProvideValueFactories() throws Exception {
+ startRepository();
+ session = getRepository().login(getTestCredentials());
+
+ this.sequencedProperty = mock(javax.jcr.Property.class);
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerContext sequencerContext = sequencer.createSequencerContext(input,
sequencedProperty, context, problems);
+ assertThat(sequencerContext.getValueFactories(), notNullValue());
+ }
+
+ @Test
+ public void shouldProvidePathToInput() throws Exception {
+ startRepository();
+ session = getRepository().login(getTestCredentials());
+
+ this.sequencedProperty = mock(javax.jcr.Property.class);
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerContext sequencerContext = sequencer.createSequencerContext(input,
sequencedProperty, context, problems);
+ assertThat(sequencerContext.getInputPath(),
is(context.getValueFactories().getPathFactory().create("/a/b/c")));
+ }
+
+ @Test
+ public void shouldNeverReturnNullInputProperties() throws Exception {
+ startRepository();
+ session = getRepository().login(getTestCredentials());
+
+ this.sequencedProperty = mock(javax.jcr.Property.class);
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerContext sequencerContext = sequencer.createSequencerContext(input,
sequencedProperty, context, problems);
+ assertThat(sequencerContext.getInputProperties(), notNullValue());
+ assertThat(sequencerContext.getInputProperties().isEmpty(), is(false));
+ }
+
+ @Test
+ public void shouldProvideInputProperties() throws Exception {
+ startRepository();
+ session = getRepository().login(getTestCredentials());
+
+ this.sequencedProperty = mock(javax.jcr.Property.class);
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ input.setProperty("x", true);
+ input.setProperty("y", new String[] {"asdf",
"xyzzy"});
+ SequencerContext sequencerContext = sequencer.createSequencerContext(input,
sequencedProperty, context, problems);
+ assertThat(sequencerContext.getInputProperties(), notNullValue());
+ assertThat(sequencerContext.getInputProperties().isEmpty(), is(false));
+ assertThat(sequencerContext.getInputProperties().size(), is(3));
+ verifyProperty(sequencerContext,
+ "jcr:primaryType",
+
context.getValueFactories().getNameFactory().create("{http://www.jcp...);
+ verifyProperty(sequencerContext, "x", true);
+ verifyProperty(sequencerContext, "y", "asdf",
"xyzzy");
+ }
+
+ @Test
+ public void shouldCreateSequencerContextThatProvidesMimeType() throws Exception {
+ startRepository();
+ session = getRepository().login(getTestCredentials());
+
+ this.sequencedProperty = mock(javax.jcr.Property.class);
+ Node input = tools.findOrCreateNode(session, "/a/b/c");
+ SequencerContext sequencerContext = sequencer.createSequencerContext(input,
sequencedProperty, context, problems);
+ assertThat(sequencerContext.getMimeType(), is("text/plain"));
+ }
+
+ private void verifyProperty( SequencerContext context,
+ String name,
+ Object... values ) {
+ Property prop =
context.getInputProperty(context.getValueFactories().getNameFactory().create(name));
+ assertThat(prop, notNullValue());
+ assertThat(prop.getName(),
is(context.getValueFactories().getNameFactory().create(name)));
+ assertThat(prop.isEmpty(), is(false));
+ assertThat(prop.size(), is(values.length));
+ assertThat(prop.isMultiple(), is(values.length > 1));
+ assertThat(prop.isSingle(), is(values.length == 1));
+ Iterator<?> iter = prop.getValues();
+ for (Object val : values) {
+ assertThat(iter.hasNext(), is(true));
+ assertThat(iter.next(), is(val));
+ }
+ }
+
}
Deleted:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/util/MockJcrExecutionContext.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/util/MockJcrExecutionContext.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/util/MockJcrExecutionContext.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -1,51 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, 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.dna.repository.util;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import java.io.IOException;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import org.jboss.dna.common.SystemFailureException;
-import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
-
-/**
- * @author Randall Hauch
- */
-public class MockJcrExecutionContext extends BasicJcrExecutionContext {
-
- public MockJcrExecutionContext( final AbstractJcrRepositoryTest test, final String
repositoryName ) {
- super(new SessionFactory() {
-
- public Session createSession( String name ) throws RepositoryException {
- assertThat(name, is(repositoryName));
- try {
- return test.getRepository().login(test.getTestCredentials());
- } catch (IOException e) {
- throw new SystemFailureException(e);
- }
- }
- }, repositoryName);
- }
-
-}
Modified:
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -42,7 +42,6 @@
import org.jboss.dna.common.text.NoOpEncoder;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.connector.inmemory.InMemoryRepositorySource;
-import org.jboss.dna.graph.BasicExecutionContextFactory;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.ExecutionContextFactory;
import org.jboss.dna.graph.Graph;
@@ -130,7 +129,7 @@
if (repositoryService != null) return; // already started
// Create the factory for execution contexts.
- contextFactory = new BasicExecutionContextFactory();
+ contextFactory = new ExecutionContext();
// Create the execution context that we'll use for the services. If we'd
want to use JAAS, we'd create the context
// by supplying LoginContext, AccessControlContext, or even Subject with
CallbackHandlers. But no JAAS in this example.
Modified:
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java
===================================================================
---
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/docs/examples/gettingstarted/sequencers/src/main/java/org/jboss/example/dna/sequencers/SequencingClient.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -49,7 +49,6 @@
import org.jboss.dna.repository.observation.ObservationService;
import org.jboss.dna.repository.sequencers.SequencerConfig;
import org.jboss.dna.repository.sequencers.SequencingService;
-import org.jboss.dna.repository.util.BasicJcrExecutionContext;
import org.jboss.dna.repository.util.JcrExecutionContext;
import org.jboss.dna.repository.util.JcrTools;
import org.jboss.dna.repository.util.SessionFactory;
@@ -210,8 +209,7 @@
// Create an execution context for the sequencing service. This execution
context provides an environment
// for the DNA services which knows about the JCR repositories, workspaces,
and credentials used to
- // establish sessions to these workspaces. This example uses the
BasicJcrExecutionContext, but there is
- // implementation for use with JCR repositories registered in JNDI.
+ // establish sessions to these workspaces.
final String repositoryWorkspaceName = this.repositoryName + "/" +
this.workspaceName;
SimpleSessionFactory sessionFactory = new SimpleSessionFactory();
sessionFactory.registerRepository(this.repositoryName, this.repository);
@@ -219,7 +217,7 @@
Credentials credentials = new SimpleCredentials(this.username,
this.password);
sessionFactory.registerCredentials(repositoryWorkspaceName,
credentials);
}
- this.executionContext = new BasicJcrExecutionContext(sessionFactory,
repositoryWorkspaceName);
+ this.executionContext = new JcrExecutionContext(sessionFactory,
repositoryWorkspaceName);
// Create the sequencing service, passing in the execution context ...
this.sequencingService = new SequencingService();
Modified:
trunk/docs/gettingstarted/src/main/docbook/en-US/content/downloading_and_running.xml
===================================================================
---
trunk/docs/gettingstarted/src/main/docbook/en-US/content/downloading_and_running.xml 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/docs/gettingstarted/src/main/docbook/en-US/content/downloading_and_running.xml 2009-01-15
16:09:50 UTC (rev 706)
@@ -93,7 +93,7 @@
</note>
<sect1 id="downloading">
<title>Downloading and compiling</title>
- <para>The next step is to <ulink
url="http://www.jboss.org/file-access/default/members/dna/downloads/...
+ <para>The next step is to <ulink
url="http://www.jboss.org/file-access/default/members/dna/downloads/...
the example for this Getting Started guide, and extract the contents to a
convenient location on your local disk.
You'll find the example contains the following files, which are organized
according to the standard Maven directory structure:</para>
<programlisting><![CDATA[
Modified:
trunk/docs/gettingstarted/src/main/docbook/en-US/content/using_dna_for_sequencing.xml
===================================================================
---
trunk/docs/gettingstarted/src/main/docbook/en-US/content/using_dna_for_sequencing.xml 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/docs/gettingstarted/src/main/docbook/en-US/content/using_dna_for_sequencing.xml 2009-01-15
16:09:50 UTC (rev 706)
@@ -82,7 +82,7 @@
sessionFactory.registerRepository("Repository", this.repository);
Credentials credentials = new SimpleCredentials("jsmith",
"secret".toCharArray());
sessionFactory.registerCredentials("Repository/Workspace1", credentials);
-JcrExecutionContext context = new
BasicJcrExecutionContext(sessionFactory,"Repository/Workspace1");
+JcrExecutionContext context = new
JcrExecutionContext(sessionFactory,"Repository/Workspace1");
// Create the sequencing service, passing in the execution context ...
SequencingService sequencingService = new SequencingService();
Modified:
trunk/docs/gettingstarted/src/main/docbook/en-US/content/using_dna_repositories.xml
===================================================================
---
trunk/docs/gettingstarted/src/main/docbook/en-US/content/using_dna_repositories.xml 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/docs/gettingstarted/src/main/docbook/en-US/content/using_dna_repositories.xml 2009-01-15
16:09:50 UTC (rev 706)
@@ -107,16 +107,13 @@
<para>Here's sample code that shows how to set up and start the repository
service. You can see something similar
in the example application in the <code>startRepositories()</code> method
of the <code>org.jboss.example.dna.repository.RepositoryClient</code>
class.</para>
<programlisting role="JAVA"><![CDATA[
- // Create the factory for execution contexts.
- ExecutionContextFactory contextFactory = new BasicExecutionContextFactory();
-
// Create the execution context that we'll use for the services. If we'd want
to use JAAS, we'd
// create the context by supplying LoginContext, AccessControlContext, or even Subject
with
// CallbackHandlers. But this example doesn't use JAAS in this example.
ExecutionContext context = contextFactory.create();
// Create the library for the RepositorySource instances ...
- RepositoryLibrary sources = new RepositoryLibrary(contextFactory);
+ RepositoryLibrary sources = new RepositoryLibrary(context);
// Load into the source manager the repository source for the configuration repository
...
InMemoryRepositorySource configSource = new InMemoryRepositorySource();
@@ -151,7 +148,7 @@
So after we create a <code>JcrRepository</code> instance pointing to our
repository library, we can
then login to obtain a JCR session:</para>
<programlisting role="JAVA"><![CDATA[
- JcrRepository jcrRepository = new JcrRepository(contextFactory, sources);
+ JcrRepository jcrRepository = new JcrRepository(context, sources);
Session session = jcrRepository.login(sourceName);
]]></programlisting>
<para>Now, the above code doesn't do any authentication; it essentially
trusts the caller has the appropriate privileges.
@@ -184,7 +181,7 @@
Credentials credentials = new Credentials() {
public LoginContext getLoginContext() { return loginContext; }
};
- JcrRepository jcrRepository = new JcrRepository(contextFactory, sources);
+ JcrRepository jcrRepository = new JcrRepository(context, sources);
Session session = jcrRepository.login(credentials, sourceName);
]]></programlisting>
<para>Once you have a JCR session, you can then use it to find the node of
interest and access the necessary information. All of this
Modified: trunk/docs/reference/src/main/docbook/en-US/content/environment.xml
===================================================================
--- trunk/docs/reference/src/main/docbook/en-US/content/environment.xml 2009-01-15
02:10:17 UTC (rev 705)
+++ trunk/docs/reference/src/main/docbook/en-US/content/environment.xml 2009-01-15
16:09:50 UTC (rev 706)
@@ -135,43 +135,43 @@
added. Here is what the &ExecutionContext; interface looks like:
</para>
<programlisting>
-public interface &ExecutionContext; extends &ClassLoaderFactory; {
+public class &ExecutionContext; implements &ClassLoaderFactory; {
/**
* Get the factories that should be used to create values for {@link Property
properties}.
* @return the property value factory; never null
*/
- &ValueFactories; getValueFactories();
+ public &ValueFactories; getValueFactories() {...}
/**
* Get the namespace registry for this context.
* @return the namespace registry; never null
*/
- &NamespaceRegistry; getNamespaceRegistry();
+ public &NamespaceRegistry; getNamespaceRegistry() {...}
/**
* Get the factory for creating {@link Property} objects.
* @return the property factory; never null
*/
- &PropertyFactory; getPropertyFactory();
+ public &PropertyFactory; getPropertyFactory() {...}
/**
* Get the current JAAS access control context.
* @return the access control context; may be <code>null</code>
*/
- &AccessControlContext; getAccessControlContext();
+ public &AccessControlContext; getAccessControlContext() {...}
/**
* Get the current JAAS login context.
* @return the login context; may be <code>null</code>
*/
- &LoginContext; getLoginContext();
+ public &LoginContext; getLoginContext() {...}
/**
* Get the JAAS subject for which this context was created.
* @return the subject; never null
*/
- &Subject; getSubject();
+ public &Subject; getSubject() {...}
/**
* Return a logger associated with this context. This logger records only those
activities within the
@@ -181,7 +181,7 @@
* @param clazz the class that is doing the logging
* @return the logger, named after <code>clazz</code>; never null
*/
- &Logger; getLogger( Class<?> clazz );
+ public &Logger; getLogger( Class<?> clazz ) {...}
/**
* Return a logger associated with this context. This logger records only those
activities within the
@@ -191,12 +191,16 @@
* @param name the name for the logger
* @return the logger, named after <code>clazz</code>; never null
*/
- &Logger; getLogger( String name );
+ public &Logger; getLogger( String name ) {...}
+
+ ...
}
</programlisting>
<para>
- Notice that &ExecutionContext; extends the &ClassLoaderFactory; interface
described in the
- <link linkend="classloaders">previous chapter</link>.
+ Notice that &ExecutionContext; implements the &ClassLoaderFactory; interface
described in the
+ <link linkend="classloaders">previous chapter</link>, meaning it
can be used to create other contexts. These other methods are not shown,
+ but can be used to create create subcontexts with different <link
linkend="security">JAAS</link>
+ login or access control contexts, with different namespace registry, or with different
combinations of components.
</para>
<para>
The fact that so many of the JBoss DNA components take &ExecutionContext;
instances gives us some interesting possibilities.
@@ -207,23 +211,20 @@
to be recorded for user feedback, monitoring and/or auditing purposes.
</para>
<para>
- While execution contexts may sound complicated, they're actually very simple to
use. In fact, JBoss DNA provides an factory interface
- for creating &ExecutionContext; instances. Not surprisingly it's called
&ExecutionContextFactory;
- and it has methods for creating contexts using <link
linkend="security">JAAS</link> login or access control contexts.
- JBoss DNA even provides a &BasicExecutionContextFactory; implementation that can
be created using its no-arg
- constructor.
- </para>
- <para>
The following code fragment shows how easy it is to create various execution
contexts:
</para>
<programlisting>
-&ExecutionContextFactory; factory = new &BasicExecutionContextFactory;();
-&ExecutionContext; context1 = factory.create();
+&ExecutionContext; context1 = new &ExecutionContext;();
+&ExecutionContext; context2 = factory.create(); // same as 'context1'
// Create a context for a user, authenticating using JAAS ...
+&LoginContext; loginContext = new
LoginContext("username",callbackHandler);
+&ExecutionContext; context3 = context1.create(new
LoginContext("username"));
+
+// Create a context for the same user, authenticating using JAAS, and using a different
callback handler ...
&CallbackHandler; callbackHandler = ...
&LoginContext; loginContext = new
LoginContext("username",callbackHandler);
-&ExecutionContext; context2 = factory.create(loginContext);
+&ExecutionContext; context4 = context1.create(loginContext);
</programlisting>
<para>
These contexts (or the context factory) can then be passed to the various components
as needed.
Modified: trunk/docs/reference/src/main/docbook/en-US/content/repositories.xml
===================================================================
--- trunk/docs/reference/src/main/docbook/en-US/content/repositories.xml 2009-01-15
02:10:17 UTC (rev 705)
+++ trunk/docs/reference/src/main/docbook/en-US/content/repositories.xml 2009-01-15
16:09:50 UTC (rev 706)
@@ -219,12 +219,11 @@
<code>org.jboss.example.dna.repository.RepositoryClient</code> class.
</para>
<programlisting>
- // Create the factory for execution contexts, and create one ...
- &ExecutionContextFactory; contextFactory = new
&BasicExecutionContextFactory;();
+ // Create the top-level execution context (which is also a factory) ...
&ExecutionContext; context = contextFactory.create();
// Create the library for the RepositorySource instances ...
- &RepositoryLibrary; sources = new &RepositoryLibrary;(contextFactory);
+ &RepositoryLibrary; sources = new &RepositoryLibrary;(context);
// Load into the source manager the repository source for the configuration repository
...
&InMemoryRepositorySource; configSource = new &InMemoryRepositorySource;();
Modified: trunk/docs/reference/src/main/docbook/en-US/content/sequencing.xml
===================================================================
--- trunk/docs/reference/src/main/docbook/en-US/content/sequencing.xml 2009-01-15 02:10:17
UTC (rev 705)
+++ trunk/docs/reference/src/main/docbook/en-US/content/sequencing.xml 2009-01-15 16:09:50
UTC (rev 706)
@@ -72,7 +72,7 @@
</listitem>
</itemizedlist>
</para>
- <para>As mentioned above, the &ExecutionContext; provides access to a
&SessionFactory; that is used
+ <para>As mentioned above, the &JcrExecutionContext; provides access to a
&SessionFactory; that is used
by JBoss DNA to establish sessions to your JCR repositories. Two implementations
are available:
<itemizedlist>
<listitem>
@@ -85,15 +85,17 @@
with names, as well as methods to set the JCR &Credentials; for a given
workspace name.</para>
</listitem>
</itemizedlist>
- You can use the &BasicJcrExecutionContext; implementation of
&JcrExecutionContext; and supply
- a &SessionFactory; instance, or you can provide your own
implementation.</para>
+ You can use the &JcrExecutionContext; and use one of these &SessionFactory;
implementations or another
+ implementation that you provide.</para>
<para>Here's an example of how to instantiate and configure the
&SequencingService;:</para>
<programlisting>
&SimpleSessionFactory; sessionFactory = new &SimpleSessionFactory;();
sessionFactory.registerRepository("Main Repository", this.repository);
&Credentials; credentials = new &SimpleCredentials;("jsmith",
"secret".toCharArray());
sessionFactory.registerCredentials("Main Repository/Workspace1", credentials);
-ExecutionContext executionContext = new &BasicJcrExecutionContext;(sessionFactory);
+// Now create the JCR execution context, with a reference to the session factory
+// and the name of the repository from which sessions will be obtained ...
+ExecutionContext executionContext = new
&JcrExecutionContext;(sessionFactory,"Main Repository");
// Create the sequencing service, passing in the execution context ...
&SequencingService; sequencingService = new &SequencingService;();
Modified: trunk/docs/reference/src/main/docbook/en-US/custom.dtd
===================================================================
--- trunk/docs/reference/src/main/docbook/en-US/custom.dtd 2009-01-15 02:10:17 UTC (rev
705)
+++ trunk/docs/reference/src/main/docbook/en-US/custom.dtd 2009-01-15 16:09:50 UTC (rev
706)
@@ -60,10 +60,8 @@
<!ENTITY Node "<ulink
url='&API;graph/Node.html'><interface>Node</interface></ulink>">
<!ENTITY Results "<ulink
url='&API;graph/Results.html'><interface>Results</interface></ulink>">
<!ENTITY Location "<ulink
url='&API;graph/Location.html'><classname>Location</classname></ulink>">
-<!ENTITY ExecutionContext "<ulink
url='&API;graph/ExecutionContext.html'><interface>ExecutionContext</interface></ulink>">
+<!ENTITY ExecutionContext "<ulink
url='&API;graph/ExecutionContext.html'><classname>ExecutionContext</classname></ulink>">
<!ENTITY ExecutionContextFactory "<ulink
url='&API;graph/ExecutionContextFactory.html'><interface>ExecutionContextFactory</interface></ulink>">
-<!ENTITY BasicExecutionContext "<ulink
url='&API;graph/BasicExecutionContext.html'><classname>BasicExecutionContext</classname></ulink>">
-<!ENTITY BasicExecutionContextFactory "<ulink
url='&API;graph/BasicExecutionContextFactory.html'><classname>BasicExecutionContextFactory</classname></ulink>">
<!ENTITY Name "<ulink
url='&API;graph/properties/Name.html'><interface>Name</interface></ulink>">
<!ENTITY Path "<ulink
url='&API;graph/properties/Path.html'><interface>Path</interface></ulink>">
<!ENTITY PathSegment "<ulink
url='&API;graph/properties/Path.Segment.html'><interface>Path.Segment</interface></ulink>">
@@ -101,7 +99,6 @@
<!ENTITY JndiSessionFactory "<ulink
url='&API;repository/util/JndiSessionFactory.html'><classname>JndiSessionFactory</classname></ulink>">
<!ENTITY SimpleSessionFactory "<ulink
url='&API;repository/util/SimpleSessionFactory.html'><classname>SimpleSessionFactory</classname></ulink>">
<!ENTITY JcrExecutionContext "<ulink
url='&API;repository/util/JcrExecutionContext.html'><interface>JcrExecutionContext</interface></ulink>">
-<!ENTITY BasicJcrExecutionContext "<ulink
url='&API;repository/util/BasicJcrExecutionContext.html'><classname>BasicJcrExecutionContext</classname></ulink>">
<!ENTITY MimeType "<ulink
url='&API;repository/mimetype/MimeType.html'><classname>MimeType</classname></ulink>">
<!ENTITY MimeTypeDetectorConfig "<ulink
url='&API;repository/mimetype/MimeTypeDetectorConfig.html'><interface>MimeTypeDetectorConfig</interface></ulink>">
Modified:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -36,7 +36,6 @@
import java.util.List;
import javax.naming.Context;
import javax.security.auth.callback.CallbackHandler;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.ExecutionContextFactory;
@@ -101,7 +100,7 @@
MockitoAnnotations.initMocks(this);
// Set up the environment (ExecutionContext, JNDI, security, etc.)
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX,
DnaLexicon.Namespace.URI);
executionContextFactoryJndiName = "context factory jndi name";
repositoryConnectionFactoryJndiName = "repository connection factory jndi
name";
Modified:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -40,7 +40,6 @@
import javax.naming.spi.ObjectFactory;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginException;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.ExecutionContextFactory;
@@ -88,7 +87,7 @@
@Before
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX,
DnaLexicon.Namespace.URI);
configurationSourceName = "configuration source name";
repositoryName = "Test Repository";
Modified:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositoryTest.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositoryTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositoryTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -27,7 +27,6 @@
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItems;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.connectors.RepositoryConnectionFactory;
import org.jboss.dna.graph.connectors.RepositorySourceListener;
@@ -55,7 +54,7 @@
@Before
public void beforeEach() {
MockitoAnnotations.initMocks(this);
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
repository = new FederatedRepository(context, connectionFactory, config);
}
Modified:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionPathRuleTest.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionPathRuleTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionPathRuleTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -28,7 +28,6 @@
import static org.junit.matchers.JUnitMatchers.hasItems;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.text.UrlEncoder;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.properties.NamespaceRegistry;
import org.jboss.dna.graph.properties.Path;
@@ -52,7 +51,7 @@
@Before
public void beforeEach() {
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
pathFactory = context.getValueFactories().getPathFactory();
registry = context.getNamespaceRegistry();
encoder = new UrlEncoder();
Modified:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionTest.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/ProjectionTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -28,7 +28,6 @@
import static org.junit.matchers.JUnitMatchers.hasItems;
import static org.mockito.Mockito.stub;
import java.util.Set;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.properties.Path;
import org.jboss.dna.graph.properties.PathFactory;
@@ -57,7 +56,7 @@
@Before
public void beforeEach() {
MockitoAnnotations.initMocks(this);
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
pathFactory = context.getValueFactories().getPathFactory();
sourceName = "Valid name";
rules = new Projection.Rule[] {mockRule1, mockRule2, mockRule3};
Modified:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutorTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -41,7 +41,6 @@
import org.jboss.dna.connector.federation.Projection;
import org.jboss.dna.connector.federation.ProjectionParser;
import org.jboss.dna.connector.federation.contribution.Contribution;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.cache.BasicCachePolicy;
@@ -82,7 +81,7 @@
@Before
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
pathFactory = context.getValueFactories().getPathFactory();
sourceName = "Federated Source";
cachePolicy = new BasicCachePolicy(10L, TimeUnit.SECONDS);
Modified:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategyTest.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategyTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/OneContributionMergeStrategyTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -34,7 +34,6 @@
import org.jboss.dna.connector.federation.contribution.Contribution;
import org.jboss.dna.connector.federation.merge.FederatedNode;
import org.jboss.dna.connector.federation.merge.MergePlan;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Location;
@@ -67,7 +66,7 @@
strategy = new OneContributionMergeStrategy();
contributions = new LinkedList<Contribution>();
contributions.add(contribution);
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
context.getNamespaceRegistry().register("dna",
"http://www.jboss.org/dna/something");
context.getNamespaceRegistry().register("jcr",
"http://www.jcr.org");
parentPath =
context.getValueFactories().getPathFactory().create("/a/b/c");
Modified:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategyTest.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategyTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/merge/strategy/SimpleMergeStrategyTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -38,7 +38,6 @@
import org.jboss.dna.common.collection.IsIteratorContaining;
import org.jboss.dna.connector.federation.contribution.Contribution;
import org.jboss.dna.connector.federation.merge.FederatedNode;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Location;
@@ -68,7 +67,7 @@
MockitoAnnotations.initMocks(this);
strategy = new SimpleMergeStrategy();
contributions = new LinkedList<Contribution>();
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
context.getNamespaceRegistry().register("dna",
"http://www.jboss.org/dna/something");
context.getNamespaceRegistry().register("jcr",
"http://www.jcr.org");
parentPath =
context.getValueFactories().getPathFactory().create("/a/b/c");
Modified:
trunk/extensions/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java
===================================================================
---
trunk/extensions/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-jbosscache/src/test/java/org/jboss/dna/connector/jbosscache/JBossCacheConnectionTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -39,7 +39,6 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
@@ -80,7 +79,7 @@
@Before
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX,
DnaLexicon.Namespace.URI);
pathFactory = context.getValueFactories().getPathFactory();
propertyFactory = context.getPropertyFactory();
Modified:
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/models/basic/BasicModelTest.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/models/basic/BasicModelTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/models/basic/BasicModelTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -39,7 +39,6 @@
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.connector.store.jpa.JpaConnectorI18n;
import org.jboss.dna.connector.store.jpa.models.common.NamespaceEntity;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.properties.PropertyType;
import org.jboss.dna.graph.requests.processor.RequestProcessor;
@@ -70,7 +69,7 @@
@Before
public void beforeEach() throws Exception {
model = new BasicModel();
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
}
@After
Modified:
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/models/basic/ChildEntityTest.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/models/basic/ChildEntityTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/models/basic/ChildEntityTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -31,7 +31,6 @@
import javax.persistence.Query;
import org.hibernate.ejb.Ejb3Configuration;
import org.jboss.dna.connector.store.jpa.models.common.NamespaceEntity;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.properties.Path;
import org.junit.After;
@@ -51,7 +50,7 @@
@Before
public void beforeEach() throws Exception {
model = new BasicModel();
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
// Connect to the database ...
Ejb3Configuration configurator = new Ejb3Configuration();
model.configure(configurator);
Modified:
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/models/basic/SubgraphQueryTest.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/models/basic/SubgraphQueryTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/models/basic/SubgraphQueryTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -43,7 +43,6 @@
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.connector.store.jpa.models.common.NamespaceEntity;
import org.jboss.dna.connector.store.jpa.util.Namespaces;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.properties.Name;
@@ -76,7 +75,7 @@
@Before
public void beforeEach() throws Exception {
model = new BasicModel();
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
// Load in the large value ...
validLargeValues = new String[]
{IoUtil.read(getClass().getClassLoader().getResourceAsStream("LoremIpsum1.txt")),
Modified:
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/RequestProcessorCacheTest.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/RequestProcessorCacheTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/RequestProcessorCacheTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -29,7 +29,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.properties.Name;
@@ -58,7 +57,7 @@
@Before
public void beforeEach() {
- ExecutionContext context = new BasicExecutionContext();
+ ExecutionContext context = new ExecutionContext();
pathFactory = context.getValueFactories().getPathFactory();
nameFactory = context.getValueFactories().getNameFactory();
namespaces = context.getNamespaceRegistry();
Modified:
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/SerializerTest.java
===================================================================
---
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/SerializerTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-store-jpa/src/test/java/org/jboss/dna/connector/store/jpa/util/SerializerTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -46,7 +46,6 @@
import org.jboss.dna.common.util.SecureHash;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.connector.store.jpa.util.Serializer.ReferenceValues;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.properties.Binary;
import org.jboss.dna.graph.properties.Name;
@@ -72,7 +71,7 @@
@Before
public void beforeEach() {
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
propertyFactory = context.getPropertyFactory();
valueFactories = context.getValueFactories();
serializer = new Serializer(context, false);
Modified:
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java
===================================================================
---
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-connector-svn/src/test/java/org/jboss/dna/connector/svn/SVNRepositoryConnectionTest.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -25,7 +25,6 @@
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsSame.sameInstance;
import static org.jboss.dna.graph.IsNodeWithChildren.hasChild;
-import static org.jboss.dna.graph.IsNodeWithProperty.hasProperty;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import java.io.File;
@@ -35,7 +34,6 @@
import java.util.List;
import org.jboss.dna.common.text.UrlEncoder;
import org.jboss.dna.common.util.FileUtil;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
@@ -61,10 +59,8 @@
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
-import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.io.SVNRepository;
-import com.sun.org.apache.bcel.internal.generic.NEW;
/**
* @author Serge Pagop
@@ -90,7 +86,7 @@
@Before
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
- context = new BasicExecutionContext();
+ context = new ExecutionContext();
context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX,
DnaLexicon.Namespace.URI);
context.getNamespaceRegistry().register(JcrLexicon.Namespace.PREFIX,
JcrLexicon.Namespace.URI);
context.getNamespaceRegistry().register(JcrNtLexicon.Namespace.PREFIX,
JcrNtLexicon.Namespace.URI);
@@ -269,18 +265,16 @@
@Test
public void shouldAddAndDeleteChildUnderRootNode() throws Exception {
- graph.batch().create("/nodeC")
- .with(propertyFactory().create(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FOLDER))
- .and(propertyFactory().create(JcrLexicon.CREATED,dateFactory().create(new
Date()))).execute();
+
graph.batch().create("/nodeC").with(propertyFactory().create(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FOLDER)).and(propertyFactory().create(JcrLexicon.CREATED,
+
dateFactory().create(new
Date()))).execute();
// Now look up the root node ...
Node root = graph.getNodeAt("/");
assertThat(root, is(notNullValue()));
assertThat(root.getChildren(), hasChild(child("nodeC")));
SVNNodeKind nodeCKind = repository.checkPath("nodeC", -1);
assertThat(nodeCKind, is(SVNNodeKind.DIR));
- graph.batch().create("/nodeC/nodeC_1")
- .with(propertyFactory().create(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FOLDER))
-
.and(propertyFactory().create(JcrLexicon.CREATED,dateFactory().create(new
Date()))).execute();
+
graph.batch().create("/nodeC/nodeC_1").with(propertyFactory().create(JcrLexicon.PRIMARY_TYPE,
JcrNtLexicon.FOLDER)).and(propertyFactory().create(JcrLexicon.CREATED,
+
dateFactory().create(new
Date()))).execute();
// Now look up the root node ...
Node nodeC = graph.getNodeAt("/nodeC");
assertThat(nodeC, is(notNullValue()));
@@ -290,7 +284,6 @@
}
-
protected Collection<String> containsPaths( Collection<Location>
locations ) {
List<String> paths = new ArrayList<String>();
for (Location location : locations) {
Modified:
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencerHandler.java
===================================================================
---
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencerHandler.java 2009-01-15
02:10:17 UTC (rev 705)
+++
trunk/extensions/dna-sequencer-xml/src/main/java/org/jboss/dna/sequencer/xml/XmlSequencerHandler.java 2009-01-15
16:09:50 UTC (rev 706)
@@ -31,7 +31,6 @@
import org.jboss.dna.common.text.XmlNameEncoder;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.common.util.StringUtil;
-import org.jboss.dna.graph.BasicExecutionContext;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.JcrLexicon;
import org.jboss.dna.graph.properties.Name;
@@ -137,11 +136,11 @@
* @param scoping
*/
XmlSequencerHandler( SequencerOutput output,
- SequencerContext context,
- Name nameAttribute,
- Name defaultPrimaryType,
- TextDecoder textDecoder,
- XmlSequencer.AttributeScoping scoping ) {
+ SequencerContext context,
+ Name nameAttribute,
+ Name defaultPrimaryType,
+ TextDecoder textDecoder,
+ XmlSequencer.AttributeScoping scoping ) {
CheckArg.isNotNull(output, "output");
CheckArg.isNotNull(context, "context");
@@ -158,7 +157,7 @@
// Set up a local namespace registry that is kept in sync with the namespaces
found in this XML document ...
NamespaceRegistry namespaceRegistry = new
LocalNamespaceRegistry(this.context.getNamespaceRegistry());
- final ExecutionContext localContext = new BasicExecutionContext(this.context,
namespaceRegistry);
+ final ExecutionContext localContext = this.context.with(namespaceRegistry);
// Set up references to frequently-used objects in the context ...
this.nameFactory = localContext.getValueFactories().getNameFactory();