001 /* 002 * JBoss, Home of Professional Open Source. 003 * Copyright 2008, Red Hat Middleware LLC, and individual contributors 004 * as indicated by the @author tags. See the copyright.txt file in the 005 * distribution for a full listing of individual contributors. 006 * 007 * This is free software; you can redistribute it and/or modify it 008 * under the terms of the GNU Lesser General Public License as 009 * published by the Free Software Foundation; either version 2.1 of 010 * the License, or (at your option) any later version. 011 * 012 * This software is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this software; if not, write to the Free 019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 021 */ 022 package org.jboss.dna.graph.connectors; 023 024 import java.security.AccessControlContext; 025 import java.security.AccessController; 026 import javax.security.auth.Subject; 027 import javax.security.auth.login.LoginContext; 028 import org.jboss.dna.common.component.ClassLoaderFactory; 029 import org.jboss.dna.common.component.StandardClassLoaderFactory; 030 import org.jboss.dna.common.util.CheckArg; 031 import org.jboss.dna.common.util.Logger; 032 import org.jboss.dna.graph.ExecutionContext; 033 import org.jboss.dna.graph.properties.NamespaceRegistry; 034 import org.jboss.dna.graph.properties.PropertyFactory; 035 import org.jboss.dna.graph.properties.ValueFactories; 036 import org.jboss.dna.graph.properties.basic.BasicNamespaceRegistry; 037 import org.jboss.dna.graph.properties.basic.BasicPropertyFactory; 038 import org.jboss.dna.graph.properties.basic.StandardValueFactories; 039 040 /** 041 * @author Randall Hauch 042 * @author John Verhaeg 043 */ 044 public class BasicExecutionContext implements ExecutionContext { 045 046 private final ClassLoaderFactory classLoaderFactory; 047 private final LoginContext loginContext; 048 private final AccessControlContext accessControlContext; 049 private final Subject subject; 050 private final PropertyFactory propertyFactory; 051 private final ValueFactories valueFactories; 052 private final NamespaceRegistry namespaceRegistry; 053 054 public BasicExecutionContext() { 055 this(new BasicNamespaceRegistry()); 056 } 057 058 public BasicExecutionContext( NamespaceRegistry namespaceRegistry ) { 059 this(namespaceRegistry, null, null); 060 } 061 062 public BasicExecutionContext( LoginContext loginContext ) { 063 this(loginContext, new BasicNamespaceRegistry()); 064 } 065 066 public BasicExecutionContext( AccessControlContext accessControlContext ) { 067 this(accessControlContext, new BasicNamespaceRegistry()); 068 } 069 070 public BasicExecutionContext( LoginContext loginContext, 071 NamespaceRegistry namespaceRegistry ) { 072 this(loginContext, namespaceRegistry, null, null); 073 } 074 075 public BasicExecutionContext( AccessControlContext accessControlContext, 076 NamespaceRegistry namespaceRegistry ) { 077 this(accessControlContext, namespaceRegistry, null, null); 078 } 079 080 public BasicExecutionContext( NamespaceRegistry namespaceRegistry, 081 ValueFactories valueFactories, 082 PropertyFactory propertyFactory ) { 083 this(null, null, namespaceRegistry, valueFactories, propertyFactory); 084 } 085 086 public BasicExecutionContext( LoginContext loginContext, 087 NamespaceRegistry namespaceRegistry, 088 ValueFactories valueFactories, 089 PropertyFactory propertyFactory ) { 090 this(loginContext, null, namespaceRegistry, valueFactories, propertyFactory); 091 } 092 093 public BasicExecutionContext( AccessControlContext accessControlContext, 094 NamespaceRegistry namespaceRegistry, 095 ValueFactories valueFactories, 096 PropertyFactory propertyFactory ) { 097 this(null, accessControlContext, namespaceRegistry, valueFactories, propertyFactory); 098 } 099 100 private BasicExecutionContext( LoginContext loginContext, 101 AccessControlContext accessControlContext, 102 NamespaceRegistry namespaceRegistry, 103 ValueFactories valueFactories, 104 PropertyFactory propertyFactory ) { 105 CheckArg.isNotNull(namespaceRegistry, "namespaceRegistry"); 106 this.loginContext = loginContext; 107 this.accessControlContext = accessControlContext; 108 if (loginContext == null) { 109 this.subject = Subject.getSubject(accessControlContext == null ? AccessController.getContext() : accessControlContext); 110 } else { 111 this.subject = loginContext.getSubject(); 112 } 113 this.namespaceRegistry = namespaceRegistry; 114 this.valueFactories = valueFactories != null ? valueFactories : new StandardValueFactories(this.namespaceRegistry); 115 this.propertyFactory = propertyFactory != null ? propertyFactory : new BasicPropertyFactory(this.valueFactories); 116 this.classLoaderFactory = new StandardClassLoaderFactory(); 117 } 118 119 /** 120 * {@inheritDoc} 121 * 122 * @see org.jboss.dna.common.component.ClassLoaderFactory#getClassLoader(java.lang.String[]) 123 */ 124 public ClassLoader getClassLoader( String... classpath ) { 125 return this.classLoaderFactory.getClassLoader(classpath); 126 } 127 128 /** 129 * {@inheritDoc} 130 * 131 * @see org.jboss.dna.graph.ExecutionContext#getAccessControlContext() 132 */ 133 public AccessControlContext getAccessControlContext() { 134 return accessControlContext; 135 } 136 137 /** 138 * {@inheritDoc} 139 * 140 * @see org.jboss.dna.graph.ExecutionContext#getLoginContext() 141 */ 142 public LoginContext getLoginContext() { 143 return loginContext; 144 } 145 146 /** 147 * {@inheritDoc} 148 */ 149 public NamespaceRegistry getNamespaceRegistry() { 150 return namespaceRegistry; 151 } 152 153 /** 154 * {@inheritDoc} 155 */ 156 public PropertyFactory getPropertyFactory() { 157 return propertyFactory; 158 } 159 160 /** 161 * {@inheritDoc} 162 * 163 * @see org.jboss.dna.graph.ExecutionContext#getSubject() 164 */ 165 public Subject getSubject() { 166 return subject; 167 } 168 169 /** 170 * {@inheritDoc} 171 */ 172 public ValueFactories getValueFactories() { 173 return valueFactories; 174 } 175 176 /** 177 * {@inheritDoc} 178 * 179 * @see org.jboss.dna.graph.ExecutionContext#getLogger(java.lang.Class) 180 */ 181 public Logger getLogger( Class<?> clazz ) { 182 return Logger.getLogger(clazz); 183 } 184 185 /** 186 * {@inheritDoc} 187 * 188 * @see org.jboss.dna.graph.ExecutionContext#getLogger(java.lang.String) 189 */ 190 public Logger getLogger( String name ) { 191 return Logger.getLogger(name); 192 } 193 }