*
* @param aResource
* Resource.
- * @param anOperation
+ * @param aOperation
* Operation.
* @param aUser
* Current user.
*
* @return Authorization result.
*/
- AuthorizationResult isAllowed(Object aResource, Operation anOperation,
+ AuthorizationResult isAllowed(Object aResource, Operation aOperation,
User aUser);
}
* .Object, org.wamblee.security.authorization.Operation)
*/
public AuthorizationResult isAllowed(Object aResource,
- Operation anOperation, User aUser) {
+ Operation aOperation, User aUser) {
if (!resourceClass.isInstance(aResource)) {
return UNSUPPORTED_RESOURCE;
}
String path = getResourcePath(aResource);
- return isAllowed(path, anOperation, aUser);
+ return isAllowed(path, aOperation, aUser);
}
/**
/**
* Gets the user principal from the subject.
*
- * @param subject
+ * @param aSubject
* Subject.
*
* @return User principal.
* In case there is a duplicate principal or the principal was
* not found.
*/
- private Principal getUserPrincipal(Subject subject) {
- Set<Principal> principals = subject.getPrincipals();
+ private Principal getUserPrincipal(Subject aSubject) {
+ Set<Principal> principals = aSubject.getPrincipals();
Principal userPrincipal = null;
for (Principal principal : principals) {
if (userPrincipal != null) {
throw new IllegalArgumentException(
"Multiple principals for class '" + userPrincipalClass +
- "', subject: " + subject);
+ "', subject: " + aSubject);
}
userPrincipal = principal;
if (userPrincipal == null) {
throw new IllegalArgumentException(
"No user principal found for class '" + userPrincipalClass +
- "', subject: " + subject);
+ "', subject: " + aSubject);
}
return userPrincipal;
*/
package org.wamblee.usermgt.hibernate;
-import org.springframework.orm.hibernate3.HibernateTemplate;
-
-import org.springframework.transaction.PlatformTransactionManager;
+import java.io.IOException;
-import org.wamblee.cache.EhCache;
+import javax.sql.DataSource;
+import org.springframework.orm.hibernate3.HibernateTemplate;
+import org.springframework.transaction.PlatformTransactionManager;
import org.wamblee.security.authorization.AuthorizationService;
import org.wamblee.security.authorization.hibernate.AuthorizationMappingFiles;
-
import org.wamblee.system.adapters.DefaultContainer;
import org.wamblee.system.adapters.ObjectConfiguration;
import org.wamblee.system.components.ORMappingConfig;
import org.wamblee.system.core.DefaultProvidedInterface;
import org.wamblee.system.core.DefaultRequiredInterface;
import org.wamblee.system.core.ProvidedInterface;
-import org.wamblee.system.core.Scope;
import org.wamblee.system.spring.component.HibernateComponent;
-
import org.wamblee.usermgt.UserAccessor;
-import org.wamblee.usermgt.UserAdministration;
-import org.wamblee.usermgt.UserGroupRepositoryComponent;
-
-import java.io.IOException;
-
-import javax.sql.DataSource;
/**
*
* @version $Revision$
*/
public class AuthorizationComponent extends DefaultContainer {
- private ProvidedInterface TRANSACTION_MGR = new DefaultProvidedInterface(
+ private ProvidedInterface transactionMgr = new DefaultProvidedInterface(
"transactionManager", PlatformTransactionManager.class);
- private ProvidedInterface HIBERNATE_TEMPLATE = new DefaultProvidedInterface(
+ private ProvidedInterface hibernateTemplate = new DefaultProvidedInterface(
"hibernateTemplate", HibernateTemplate.class);
- private ProvidedInterface AUTHORIZATION_SERVICE = new DefaultProvidedInterface(
+ private ProvidedInterface authorizationService = new DefaultProvidedInterface(
"authorizationService", AuthorizationService.class);
/**
ORMappingConfig.class));
if (aExposeInternals) {
- addProvidedInterface(TRANSACTION_MGR);
- addProvidedInterface(HIBERNATE_TEMPLATE);
+ addProvidedInterface(transactionMgr);
+ addProvidedInterface(hibernateTemplate);
}
- addProvidedInterface(AUTHORIZATION_SERVICE);
+ addProvidedInterface(authorizationService);
}
}
*/
package org.wamblee.usermgt.hibernate;
-import org.springframework.orm.hibernate3.HibernateTemplate;
+import java.util.HashMap;
+import java.util.Map;
+import org.springframework.orm.hibernate3.HibernateTemplate;
import org.wamblee.security.authorization.AuthorizationService;
-
import org.wamblee.system.core.DefaultProvidedInterface;
import org.wamblee.system.core.DefaultRequiredInterface;
import org.wamblee.system.core.ProvidedInterface;
import org.wamblee.system.core.RequiredInterface;
import org.wamblee.system.spring.SpringComponent;
-
-import org.wamblee.usermgt.GroupSet;
import org.wamblee.usermgt.UserAccessor;
-import org.wamblee.usermgt.UserAdministration;
-import org.wamblee.usermgt.UserSet;
-
-import java.util.HashMap;
-import java.util.Map;
/**
* Light version of the user administration component that requires external
* @version $Revision$
*/
public class UserAdministrationComponent extends DefaultContainer {
- private ProvidedInterface TRANSACTION_MGR = new DefaultProvidedInterface(
+ private ProvidedInterface transactionMgr = new DefaultProvidedInterface(
"transactionManager", PlatformTransactionManager.class);
- private ProvidedInterface USER_CACHE = new DefaultProvidedInterface(
+ private ProvidedInterface userCache = new DefaultProvidedInterface(
"userCache", EhCache.class);
- private ProvidedInterface HIBERNATE_TEMPLATE = new DefaultProvidedInterface(
+ private ProvidedInterface hibernateTemplate = new DefaultProvidedInterface(
"hibernateTemplate", HibernateTemplate.class);
- private ProvidedInterface USER_MGT = new DefaultProvidedInterface(
+ private ProvidedInterface userMgt = new DefaultProvidedInterface(
"usermgt", UserAdministration.class);
/**
ORMappingConfig.class));
if (aExposeInternals) {
- addProvidedInterface(TRANSACTION_MGR);
- addProvidedInterface(USER_CACHE);
- addProvidedInterface(HIBERNATE_TEMPLATE);
+ addProvidedInterface(transactionMgr);
+ addProvidedInterface(userCache);
+ addProvidedInterface(hibernateTemplate);
}
- addProvidedInterface(USER_MGT);
+ addProvidedInterface(userMgt);
}
}
*/
@Override
public AuthorizationResult isAllowed(Object aResource,
- Operation anOperation, User aUser) {
- AuthorizationResult result = super.isAllowed(aResource, anOperation,
+ Operation aOperation, User aUser) {
+ AuthorizationResult result = super.isAllowed(aResource, aOperation,
aUser);
if (result.equals(GRANTED) || result.equals(DENIED)) {
* implementations of group set.
*/
public class InMemoryGroupSetTest extends TestCase {
- protected GroupSet groups;
+ private GroupSet groups;
/**
* This method must be overriden in subclasses.
notifier.update(observer, observable, aEvent);
}
}
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#finalize()
- */
- @Override
- protected void finalize() throws Throwable {
- if (observers.size() > 0) {
- LOGGER
- .error("Still observers registered at finalization of observer!");
-
- for (Observer observer : observers.values()) {
- LOGGER.error(" observer: " + observer);
- }
- }
-
- super.finalize();
- }
}
* @author Erik Brakkee
*/
public class ClassAdapter extends AbstractComponent<Object> {
- private ClassConfiguration _classConfig;
+ private ClassConfiguration classConfig;
/**
* Creates a new ClassAdapter object.
super(aName, aClassConfig.getProvidedInterfaces().toArray(
new ProvidedInterface[0]), aClassConfig.getRequiredInterfaces()
.toArray(new RequiredInterface[0]));
- _classConfig = aClassConfig;
+ classConfig = aClassConfig;
}
@Override
protected Object doStart(Scope aScope) {
- Object obj = _classConfig.create(aScope);
- _classConfig.inject(aScope, obj);
+ Object obj = classConfig.create(aScope);
+ classConfig.inject(aScope, obj);
for (ProvidedInterface provided : getProvidedInterfaces()) {
addInterface(provided, obj, aScope);
* @author Erik Brakkee
*/
public class ClassConfiguration {
- private Class _class;
+ private Class clazz;
private ConstructorConfiguration constructorConfig;
* Class to construct.
*/
public ClassConfiguration(Class aClass) {
- _class = aClass;
+ clazz = aClass;
constructorConfig = new ConstructorConfiguration(aClass);
objectConfig = new ObjectConfiguration(aClass);
}
public List<ProvidedInterface> getProvidedInterfaces() {
List<ProvidedInterface> result = new ArrayList<ProvidedInterface>();
- result.add(new DefaultProvidedInterface("provided", _class));
+ result.add(new DefaultProvidedInterface("provided", clazz));
return result;
}
* @author Erik Brakkee
*/
class FixedValueProvider implements ValueProvider {
- private Object _value;
+ private Object value;
/**
* Constructs the value.
* Value to construct.
*/
public FixedValueProvider(Object aValue) {
- _value = aValue;
+ value = aValue;
}
@Override
public Object getValue(Scope aScope) {
- return _value;
+ return value;
}
}
* @author Erik Brakkee
*/
public class ObjectConfiguration {
- private Class _class;
+ private Class clazz;
private SetterConfiguration setterConfig;
*
*/
public ObjectConfiguration(Class aClass) {
- _class = aClass;
+ clazz = aClass;
setterConfig = new SetterConfiguration(aClass);
}
}
public boolean appliesTo(Object aObject) {
- return _class.isInstance(aObject);
+ return clazz.isInstance(aObject);
}
}
* @author Erik Brakkee
*/
public class SetterConfiguration {
- private Class _class;
+ private Class clazz;
private boolean publicOnly;
* Class which is being configured.
*/
public SetterConfiguration(Class aClass) {
- _class = aClass;
+ clazz = aClass;
publicOnly = true;
setters = new HashMap<Method, ParameterValues>();
}
public SetterConfiguration initAllSetters() {
setters.clear();
- for (Method method : getAllSetters(_class, publicOnly)) {
+ for (Method method : getAllSetters(clazz, publicOnly)) {
setters.put(method, createParameterValues(method));
}
*
*/
public SetterConfiguration remove(Method aMethod) {
- if (!aMethod.getDeclaringClass().isAssignableFrom(_class)) {
+ if (!aMethod.getDeclaringClass().isAssignableFrom(clazz)) {
throw new RuntimeException("Method " + aMethod +
- " not found in class " + _class + " or its superclasses");
+ " not found in class " + clazz + " or its superclasses");
}
for (Method method : setters.keySet()) {
public SetterConfiguration add(final String aName) {
int oldlen = setters.size();
List<Method> methods = new ArrayList<Method>();
- CollectionFilter.filter(getAllSetters(_class, publicOnly), methods,
+ CollectionFilter.filter(getAllSetters(clazz, publicOnly), methods,
new Condition<Method>() {
@Override
public boolean matches(Method aObject) {
if (methods.size() == 0) {
throw new IllegalArgumentException("Method '" + aName +
- "' not found in " + _class.getName());
+ "' not found in " + clazz.getName());
}
// TODO is it possible to get more than one setter here in case the
*/
public SetterConfiguration addSetter(final Class aType) {
List<Method> result = new ArrayList<Method>();
- CollectionFilter.filter(getAllSetters(_class, publicOnly), result,
+ CollectionFilter.filter(getAllSetters(clazz, publicOnly), result,
new Condition<Method>() {
@Override
public boolean matches(Method aObject) {
if (result.size() == 0) {
throw new IllegalArgumentException("No setter found in class '" +
- _class.getName() + "' that has a setter with argument type '" +
+ clazz.getName() + "' that has a setter with argument type '" +
aType.getName() + "'");
}
}
throw new IllegalArgumentException(
- "Multiple setters found in class '" + _class.getName() +
+ "Multiple setters found in class '" + clazz.getName() +
" that accept type '" + aType.getName() + "': " + setters);
}
*
*/
public void inject(Scope aScope, Object aObject) {
- if (!_class.isInstance(aObject)) {
+ if (!clazz.isInstance(aObject)) {
throw new IllegalArgumentException("Object '" + aObject +
- "' is not an instance of " + _class.getName());
+ "' is not an instance of " + clazz.getName());
}
for (Method method : setters.keySet()) {
}
@Override
- public boolean equals(Object obj) {
- return this == obj;
+ public boolean equals(Object aObject) {
+ return this == aObject;
}
@Override
- public boolean covers(RequiredInterface obj) {
+ public boolean covers(RequiredInterface aObject) {
// TODO do more than equals.
- if (!(obj instanceof DefaultRequiredInterface)) {
+ if (!(aObject instanceof DefaultRequiredInterface)) {
return false;
}
- DefaultRequiredInterface descr = (DefaultRequiredInterface) obj;
+ DefaultRequiredInterface descr = (DefaultRequiredInterface) aObject;
if (required.length != descr.required.length) {
return false;
* @author Erik Brakkee
*/
class ProvidedInterfaceImplementation {
- private ProvidedInterface _provided;
+ private ProvidedInterface provided;
- private Object _implementation;
+ private Object implementation;
/**
* Constructs the object.
*/
public ProvidedInterfaceImplementation(ProvidedInterface aProvided,
Object aImplementation) {
- _provided = aProvided;
- _implementation = aImplementation;
+ provided = aProvided;
+ implementation = aImplementation;
}
/**
* @return The provided interface.
*/
public ProvidedInterface getProvided() {
- return _provided;
+ return provided;
}
/**
* @return Implementation.
*/
public <T> T getImplementation(Class<T> aType) {
- return (T) _implementation;
+ return (T) implementation;
}
}
}
private void createDuplicateException(String aMsg, Node aNode,
- List<Edge> edges) {
+ List<Edge> aEdges) {
StringBuffer buf = new StringBuffer();
buf.append(aNode + ": " + aMsg + ": ");
- for (Edge edge : edges) {
+ for (Edge edge : aEdges) {
buf.append(edge.getTo() + "/ ");
}
* @author Erik Brakkee
*/
public class CheckExternallyRequiredVisitor implements Visitor {
- private Log LOG = LogFactory.getLog(CheckExternallyRequiredVisitor.class);
+ private static final Log LOG = LogFactory.getLog(CheckExternallyRequiredVisitor.class);
private Graph graph;
}
private void createDuplicateException(String aMsg, Node aNode,
- List<Edge> edges) {
+ List<Edge> aEdges) {
StringBuffer buf = new StringBuffer();
buf.append(aNode + ": " + aMsg + ": ");
- for (Edge edge : edges) {
+ for (Edge edge : aEdges) {
buf.append(edge.getTo() + "/ ");
}
* @version $Revision$
*/
public class AdapterTestCase extends TestCase {
- static EventTracker<String> EVENT_TRACKER;
+ private static EventTracker<String> EVENT_TRACKER;
- protected Scope scope;
+ private Scope scope;
+ protected Scope getScope() {
+ return scope;
+ }
+
+ public static EventTracker<String> getEventTracker() {
+ return EVENT_TRACKER;
+ }
+
@Override
protected void setUp() throws Exception {
super.setUp();
Scope scope = container.start();
AssertionUtils.assertEquals(new String[] { "x1(hello)", "x4(x1)" },
- EVENT_TRACKER.getEvents(Thread.currentThread()).toArray());
+ getEventTracker().getEvents(Thread.currentThread()).toArray());
Object obj1 = scope.getRuntime(x1Adapter);
assertTrue(obj1 instanceof X1);
Scope scope = container.start();
AssertionUtils.assertEquals(new String[] { "x1(hello)", "x4(x1)",
- "x8(x1)", "x8.setX4(x4)" }, EVENT_TRACKER.getEvents(
+ "x8(x1)", "x8.setX4(x4)" }, getEventTracker().getEvents(
Thread.currentThread()).toArray());
Object obj1 = scope.getRuntime(x1Adapter);
*/
package org.wamblee.system.adapters;
+import java.util.Collections;
+import java.util.List;
+
import org.wamblee.system.core.DefaultProvidedInterface;
import org.wamblee.system.core.ProvidedInterface;
import org.wamblee.system.core.RequiredInterface;
import org.wamblee.system.core.RequiredInterfaceComparator;
-
+import org.wamblee.system.core.Scope;
import org.wamblee.test.AssertionUtils;
-import java.util.Collections;
-import java.util.List;
-
/**
*
* @author $author$
required.get(0).setProvider(provided);
- scope.publishInterface(provided, "hello");
- classConfig.create(scope);
+ getScope().publishInterface(provided, "hello");
+ classConfig.create(getScope());
AssertionUtils.assertEquals(new String[] { "x1(hello)" },
- AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
+ AdapterTestCase.getEventTracker().getEvents(Thread.currentThread())
.toArray());
}
required.get(0).setProvider(providedBoolean);
required.get(1).setProvider(providedHost);
+ Scope scope = getScope();
scope.publishInterface(providedBoolean, true);
scope.publishInterface(providedHost, "host.name.org");
*/
package org.wamblee.system.adapters;
+import java.util.List;
+
import org.wamblee.system.core.DefaultProvidedInterface;
import org.wamblee.system.core.ProvidedInterface;
import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.core.Scope;
import org.wamblee.system.core.SystemAssemblyException;
-
import org.wamblee.test.AssertionUtils;
-import java.util.List;
-
/**
*
* @author $author$
required.get(0).setProvider(provided);
+ Scope scope = getScope();
scope.publishInterface(provided, "hello");
config.create(scope);
AssertionUtils.assertEquals(new String[] { "x1(hello)" },
- AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
+ AdapterTestCase.getEventTracker().getEvents(Thread.currentThread())
.toArray());
}
assertEquals(1, required.size());
required.get(0).setProvider(provided);
+ Scope scope = getScope();
scope.publishInterface(provided, "hello");
config.create(scope);
AssertionUtils.assertEquals(new String[] { "x2(hello)" },
- AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
+ AdapterTestCase.getEventTracker().getEvents(Thread.currentThread())
.toArray());
}
.greedy();
config.getParameters().setValue(0, "bla");
+ Scope scope = getScope();
config.create(scope);
AssertionUtils.assertEquals(new String[] { "x1(bla)" },
- AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
+ AdapterTestCase.getEventTracker().getEvents(Thread.currentThread())
.toArray());
}
assertEquals(1, required.size());
required.get(0).setProvider(provided);
+ Scope scope = getScope();
scope.publishInterface(provided, "hello");
config.create(scope);
AssertionUtils.assertEquals(new String[] { "x1(hello)" },
- AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
+ AdapterTestCase.getEventTracker().getEvents(Thread.currentThread())
.toArray());
}
config.getParameters().setOptional(0);
assertTrue(config.getRequiredInterfaces().get(0).isOptional());
+ Scope scope = getScope();
config.create(scope);
AssertionUtils.assertEquals(new String[] { "x1(null)" },
- AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
+ AdapterTestCase.getEventTracker().getEvents(Thread.currentThread())
.toArray());
}
required.get(0).setProvider(provided);
+ Scope scope = getScope();
scope.publishInterface(provided, "hello");
config.create(scope);
AssertionUtils.assertEquals(new String[] { "x3(hello)" },
- AdapterTestCase.EVENT_TRACKER.getEvents(Thread.currentThread())
+ AdapterTestCase.getEventTracker().getEvents(Thread.currentThread())
.toArray());
}
}
Scope scope = container.start();
AssertionUtils.assertEquals(new String[] { "x1(hello)", "x4(x1)" },
- EVENT_TRACKER.getEvents(Thread.currentThread()).toArray());
+ getEventTracker().getEvents(Thread.currentThread()).toArray());
Object obj = scope.getRuntime("x1");
assertTrue(obj instanceof X1);
x1Config.getObjectConfig().getSetterConfig().initAllSetters();
X8 x8 = new X8(null);
- EVENT_TRACKER.clear();
+ getEventTracker().clear();
ClassConfiguration x4Config = new ClassConfiguration(X4.class);
x4Config.getObjectConfig().getSetterConfig().initAllSetters();
Scope scope = container.start();
AssertionUtils.assertEquals(new String[] { "x1(hello)", "x4(x1)",
- "x8.setX4(x4)" }, EVENT_TRACKER.getEvents(Thread.currentThread())
+ "x8.setX4(x4)" }, getEventTracker().getEvents(Thread.currentThread())
.toArray());
Object obj1 = scope.getRuntime("x1");
x4Adapter, x8Adapter }, new ProvidedInterface[0],
new RequiredInterface[0]);
- EVENT_TRACKER.clear();
+ getEventTracker().clear();
Scope scope = container.start();
AssertionUtils.assertEquals(new String[] { "x1(hello)", "x4(x1)",
- "x8.setX4(x4)" }, EVENT_TRACKER.getEvents(Thread.currentThread())
+ "x8.setX4(x4)" }, getEventTracker().getEvents(Thread.currentThread())
.toArray());
Object obj1 = scope.getRuntime(x1Adapter);
*/
package org.wamblee.system.adapters;
-import org.wamblee.system.core.DefaultProvidedInterface;
-import org.wamblee.system.core.ProvidedInterface;
-import org.wamblee.system.core.RequiredInterface;
-import org.wamblee.system.core.RequiredInterfaceComparator;
-
-import org.wamblee.test.AssertionUtils;
-
import java.lang.reflect.Method;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import javax.sql.DataSource;
+import org.wamblee.system.core.DefaultProvidedInterface;
+import org.wamblee.system.core.ProvidedInterface;
+import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.core.RequiredInterfaceComparator;
+import org.wamblee.system.core.Scope;
+import org.wamblee.test.AssertionUtils;
+
/**
*
* @author $author$
ProvidedInterface provided = new DefaultProvidedInterface("janse",
String.class);
required.get(0).setProvider(provided);
+ Scope scope = getScope();
scope.publishInterface(provided, "hello");
X5 obj = new X5();
"janse", String.class);
assertTrue(required.get(0).implementedBy(providedString));
required.get(0).setProvider(providedString);
+ Scope scope = getScope();
scope.publishInterface(providedString, "hello");
ProvidedInterface providedInt = new DefaultProvidedInterface("xxx",
"janse", Boolean.class);
assertTrue(required.get(0).implementedBy(providedBoolean));
required.get(0).setProvider(providedBoolean);
+ Scope scope = getScope();
scope.publishInterface(providedBoolean, true);
ProvidedInterface providedString = new DefaultProvidedInterface(
ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
String.class);
required.get(0).setProvider(provided0);
+ Scope scope = getScope();
scope.publishInterface(provided0, "hello");
ProvidedInterface provided1 = new DefaultProvidedInterface("port",
ProvidedInterface provided = new DefaultProvidedInterface("janse",
String.class);
required.get(0).setProvider(provided);
+ final Scope scope = getScope();
scope.publishInterface(provided, "hello");
final X6 obj = new X6();
X5 obj = new X5();
assertNull(obj.getValue());
+ Scope scope = getScope();
config.inject(scope, obj);
assertEquals("bladibla", obj.getValue());
}
assertNull(obj.getHost());
assertNull(obj.getPort());
+ Scope scope = getScope();
config.inject(scope, obj);
assertNull(obj.getHost());
ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
String.class);
required.get(0).setProvider(provided0);
+ Scope scope = getScope();
scope.publishInterface(provided0, "hello");
X6 obj = new X6();
ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
String.class);
required.get(0).setProvider(provided0);
+ Scope scope = getScope();
scope.publishInterface(provided0, "hello");
X6 obj = new X6();
ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
String.class);
required.get(0).setProvider(provided0);
+ Scope scope = getScope();
scope.publishInterface(provided0, "hello");
X6 obj = new X6();
ProvidedInterface provided0 = new DefaultProvidedInterface("janse",
String.class);
required.get(0).setProvider(provided0);
+ Scope scope = getScope();
scope.publishInterface(provided0, "hello");
X6 obj = new X6();
* Creates a new X1 object.
*/
public X1() {
- AdapterTestCase.EVENT_TRACKER.eventOccurred("x1()");
+ AdapterTestCase.getEventTracker().eventOccurred("x1()");
}
/**
*
*/
public X1(String aValue) {
- AdapterTestCase.EVENT_TRACKER.eventOccurred("x1(" + aValue + ")");
+ AdapterTestCase.getEventTracker().eventOccurred("x1(" + aValue + ")");
}
}
*
*/
public X2(Integer aInteger) {
- AdapterTestCase.EVENT_TRACKER.eventOccurred("x2(" + aInteger + ")");
+ AdapterTestCase.getEventTracker().eventOccurred("x2(" + aInteger + ")");
}
/**
*
*/
public X2(String aValue) {
- AdapterTestCase.EVENT_TRACKER.eventOccurred("x2(" + aValue + ")");
+ AdapterTestCase.getEventTracker().eventOccurred("x2(" + aValue + ")");
}
}
* Creates a new X3 object.
*/
public X3() {
- AdapterTestCase.EVENT_TRACKER.eventOccurred("x3()");
+ AdapterTestCase.getEventTracker().eventOccurred("x3()");
}
/**
*
*/
protected X3(String aValue) {
- AdapterTestCase.EVENT_TRACKER.eventOccurred("x3(" + aValue + ")");
+ AdapterTestCase.getEventTracker().eventOccurred("x3(" + aValue + ")");
}
}
*
*/
public X4(X1 aX1) {
- AdapterTestCase.EVENT_TRACKER.eventOccurred("x4(x1)");
+ AdapterTestCase.getEventTracker().eventOccurred("x4(x1)");
x1 = aX1;
}
}
public void setValue(String aValue) {
- AdapterTestCase.EVENT_TRACKER.eventOccurred("x5.setValue(" + aValue +
+ AdapterTestCase.getEventTracker().eventOccurred("x5.setValue(" + aValue +
")");
value = aValue;
}
*
*/
public X8(X1 aX1) {
- AdapterTestCase.EVENT_TRACKER.eventOccurred("x8(x1)");
+ AdapterTestCase.getEventTracker().eventOccurred("x8(x1)");
x1 = aX1;
}
public void setX4(X4 aX4) {
- AdapterTestCase.EVENT_TRACKER.eventOccurred("x8.setX4(x4)");
+ AdapterTestCase.getEventTracker().eventOccurred("x8.setX4(x4)");
x4 = aX4;
}
.get(0))));
}
- private void configureRestriction(EdgeFilter base, boolean aResult) {
- stub(base.isViolated((Edge) anyObject())).toReturn(aResult);
+ private void configureRestriction(EdgeFilter aBase, boolean aResult) {
+ stub(aBase.isViolated((Edge) anyObject())).toReturn(aResult);
}
public void testOneRestriction() {
* @author Erik Brakkee
*/
class RequiredServiceBean implements FactoryBean {
- private RequiredInterface _required;
+ private RequiredInterface required;
/**
* Constructs the bean.
* Id of the bean in the service registry.
*/
public RequiredServiceBean(String aId) {
- List<RequiredInterface> required = SpringComponent.THIS.get()
+ List<RequiredInterface> requiredInterfaces = SpringComponent.THIS.get()
.getRequiredInterfaces();
- for (RequiredInterface intf : required) {
+ for (RequiredInterface intf : requiredInterfaces) {
if (intf.getName().equals(aId)) {
- _required = intf;
+ required = intf;
return;
}
@Override
public Object getObject() throws Exception {
return SpringComponent.SCOPE.get().getInterfaceImplementation(
- _required.getProvider(), Object.class);
+ required.getProvider(), Object.class);
}
@Override
* @version $Revision$
*/
class StringResource implements Resource {
- private String _value;
+ private String value;
/**
* Creates a new StringResource object.
*
*/
public StringResource(String aValue) {
- _value = aValue;
+ value = aValue;
}
@Override
@Override
public InputStream getInputStream() throws IOException {
- return new ByteArrayInputStream(_value.getBytes());
+ return new ByteArrayInputStream(value.getBytes());
}
}
private static final String HIBERNATE_SPRING_CONFIG = "spring/org.wamblee.system.spring.component.hibernate.xml";
- private final RequiredInterface CONFIG = new DefaultRequiredInterface(
+ private final RequiredInterface config = new DefaultRequiredInterface(
"config", ORMappingConfig.class);
/**
Properties props = new Properties();
addProperties(HIBERNATE_PROPS_KEY, props);
- addRequiredInterface(CONFIG);
+ addRequiredInterface(config);
}
@Override
protected Scope doStart(Scope aExternalScope) {
- ORMappingConfig config = aExternalScope.getInterfaceImplementation(
- CONFIG.getProvider(), ORMappingConfig.class);
- setProperty(HIBERNATE_SCHEMAUPDATE_PROP, "" + config.isSchemaUpdate());
+ ORMappingConfig orMappingConfig = aExternalScope.getInterfaceImplementation(
+ config.getProvider(), ORMappingConfig.class);
+ setProperty(HIBERNATE_SCHEMAUPDATE_PROP, "" + orMappingConfig.isSchemaUpdate());
- DatabaseType db = config.getType();
+ DatabaseType db = orMappingConfig.getType();
String dialect = db.handleCases(new DatabaseType.Switch<String>() {
@Override
public String handleMySqlInnoDb() {
*
*/
public HelloService(String aMsg) {
- SpringComponentTest.EVENT_TRACKER.eventOccurred(aMsg);
+ SpringComponentTest.getEventTracker().eventOccurred(aMsg);
msg = aMsg;
}
private static final String PROPERTY_FILE = "test.org.wamblee.system.spring.properties";
- public static EventTracker<String> EVENT_TRACKER;
+ private static EventTracker<String> EVENT_TRACKER;
private Scope externalScope;
+ public static EventTracker<String> getEventTracker() {
+ return EVENT_TRACKER;
+ }
+
@Override
protected void setUp() throws Exception {
super.setUp();
*
*
*/
- public void customize(Session session) throws Exception {
+ public void customize(Session aSession) throws Exception {
JNDIConnector connector = null;
Context context = null;
context = new InitialContext();
if (null != context) {
- connector = (JNDIConnector) session.getLogin().getConnector(); // possible
+ connector = (JNDIConnector) aSession.getLogin().getConnector(); // possible
// CCE
// Change from COMPOSITE_NAME_LOOKUP to STRING_LOOKUP
// Note: if both jta and non-jta elements exist this will only
// Or, if you are specifying both JTA and non-JTA in your
// persistence.xml then set both connectors to be safe
- JNDIConnector writeConnector = (JNDIConnector) session
+ JNDIConnector writeConnector = (JNDIConnector) aSession
.getLogin().getConnector();
writeConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
- JNDIConnector readConnector = (JNDIConnector) ((DatabaseLogin) ((ServerSession) session)
+ JNDIConnector readConnector = (JNDIConnector) ((DatabaseLogin) ((ServerSession) aSession)
.getReadConnectionPool().getLogin()).getConnector();
readConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
}
@Override
- public void bind(String name, Object obj) throws NamingException {
- bindings.put(name, obj);
+ public void bind(String aName, Object aObj) throws NamingException {
+ bindings.put(aName, aObj);
}
@Override
- public Object lookup(String name) throws NamingException {
- return bindings.get(name);
+ public Object lookup(String aName) throws NamingException {
+ return bindings.get(aName);
}
@Override
- public Object lookup(Name name) throws NamingException {
- return super.lookup(name.toString());
+ public Object lookup(Name aName) throws NamingException {
+ return super.lookup(aName.toString());
}
}
*/
public class StubInitialContextFactory implements InitialContextFactory {
- private static Context context;
+ private static Context CONTEXT;
private static void initialize() {
try {
- context = new StubInitialContext();
+ CONTEXT = new StubInitialContext();
} catch (NamingException e) { // can't happen.
throw new RuntimeException(e);
}
// sets up the InitialContextFactoryForTest as default factory.
System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
StubInitialContextFactory.class.getName());
- if (context == null) {
+ if (CONTEXT == null) {
initialize();
}
}
*/
public static void unregister() {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "");
- context = null;
+ CONTEXT = null;
}
- public Context getInitialContext(Hashtable<?, ?> environment)
+ public Context getInitialContext(Hashtable<?, ?> aEnvironment)
throws NamingException {
- return context;
+ return CONTEXT;
}
}
// constructed object at the connection pool.
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
connectionFactory, connectionPool, null, null, false, true);
+ ingoredVariable(poolableConnectionFactory);
itsDataSource = new PoolingDataSource(connectionPool);
}
+
+ private static void ingoredVariable(PoolableConnectionFactory aFactory) {
+ // Empty
+ }
// / BELOW THIS LINE IS NOT OF INTEREST TO SUBCLASSES.
*/
private static final String DB_CAPABILITIES_PROP = "TEST_DB_CAPABILITIES";
- private static ServiceLoader<DatabaseProvider> LOADER = null;
+ private static ServiceLoader<DatabaseProvider> LOADER =
+ ServiceLoader.load(DatabaseProvider.class);
private DatabaseBuilder() {
// Empty.
aCapabilities = new String[] { DatabaseProvider.CAPABILITY_IN_MEMORY };
}
}
- LOGGER.info("Using capabilities: " + aCapabilities);
+ LOGGER.info("Using capabilities: " + Arrays.asList(aCapabilities));
}
synchronized (DatabaseBuilder.class) {
- initLoader();
for (DatabaseProvider db : LOADER) {
if (db.supportsCapabilities(aCapabilities)) {
return db.create();
* @return List of databases.
*/
public static List<DatabaseDescription> getSupportedDatabases() {
- initLoader();
List<DatabaseDescription> descriptions = new ArrayList<DatabaseDescription>();
for (DatabaseProvider db : LOADER) {
descriptions.add(db.getDescription());
return descriptions;
}
- private static void initLoader() {
- if (LOADER == null) {
- LOADER = ServiceLoader.load(DatabaseProvider.class);
- }
- }
-
}
}
private String printCapabilities() {
- String res = "";
+ StringBuffer res = new StringBuffer();
for (int i = 0; i < itsCapabilities.length; i++) {
- res += "" + itsCapabilities[i];
+ res.append(itsCapabilities[i]);
if (i < itsCapabilities.length - 1) {
- res += ", ";
+ res.append(", ");
}
}
- return res;
+ return res.toString();
}
}
* where the database class name must be the name of a concrete subclass of
* {@link Database}.
*
- * @param args
+ * @param aArgs
*/
- public static void main(String[] args) throws Exception {
- String clazz = args[0];
+ public static void main(String[] aArgs) throws Exception {
+ String clazz = aArgs[0];
try {
new DatabaseStarter(Class.forName(clazz)).start();
} catch (Exception e) {
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.support.persistence;
import java.sql.Connection;
LOG.fine("Getting database table names to clean (schema: '" +
SCHEMA_PATTERN + "'");
- ResultSet tables = dataSource.getConnection().getMetaData().getTables(
- null, SCHEMA_PATTERN, "%", new String[] { "TABLE" });
- while (tables.next()) {
- String table = tables.getString("TABLE_NAME");
- if (aSelection.accept(table)) {
- result.add(table);
+ Connection connection = dataSource.getConnection();
+ try {
+ ResultSet tables = connection.getMetaData().getTables(null,
+ SCHEMA_PATTERN, "%", new String[] { "TABLE" });
+ while (tables.next()) {
+ String table = tables.getString("TABLE_NAME");
+ if (aSelection.accept(table)) {
+ result.add(table);
+ }
}
+ return (String[]) result.toArray(new String[0]);
+ } finally {
+ connection.close();
}
- return (String[]) result.toArray(new String[0]);
}
public void emptyTables() throws Exception {
if (aObject instanceof Integer) {
aStatement.setInt(aIndex, ((Integer) aObject).intValue());
} else if (aObject instanceof Long) {
- aStatement.setLong(aIndex, ((Integer) aObject).longValue());
+ aStatement.setLong(aIndex, ((Long) aObject).longValue());
} else if (aObject instanceof String) {
aStatement.setString(aIndex, (String) aObject);
} else {
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.support.persistence;
import java.io.File;
private void shutdownDerby() {
try {
DriverManager.getConnection("jdbc:derby:;shutdown=true");
- throw new RuntimeException("Derby did not shutdown, "
- + " should always throw exception at shutdown");
+ throw new RuntimeException(
+ "Derby did not shutdown, should always throw exception at shutdown");
} catch (Exception e) {
LOGGER.info("Derby has been shut down.");
}
/**
* Executes the unit of work. A transaction has been started.
*
- * @param em
+ * @param aEm
* Entity manager.
* @return Result of the execute method. If you don't want to return
* anything use <code>Void</code> for the return type and return
* null from the implementation.
*/
- T execute(EntityManager em);
+ T execute(EntityManager aEm) throws Exception;
}
private PersistenceUnitDescription persistenceUnit;
}
factory = createFactory();
execute(new JpaUnitOfWork<Void>() {
- public Void execute(EntityManager em) {
+ public Void execute(EntityManager aEm) {
// Empty, just to trigger database schema creation.
return null;
}
// Put some data in the database.
builder.execute(new JpaUnitOfWork<Void>() {
- public Void execute(EntityManager em) {
+ public Void execute(EntityManager aEm) {
MyEntity entity = new MyEntity("a", "b");
- em.persist(entity);
+ aEm.persist(entity);
return null;
}
});
// as and execute the
// unit of work.
builder.execute(new JpaUnitOfWork<Void>() {
- public Void execute(EntityManager em) {
+ public Void execute(EntityManager aEm) {
MyEntity entity = new MyEntity("a", "b");
- em.persist(entity);
+ aEm.persist(entity);
return null;
}
});
// Empty.
}
- public boolean accept(String tableName) throws DataSetException {
- return tableName.startsWith("XYZ_");
+ public boolean accept(String aTableName) throws DataSetException {
+ return aTableName.startsWith("XYZ_");
}
}
*
*
*/
- public void customize(Session session) throws Exception {
+ public void customize(Session aSession) throws Exception {
JNDIConnector connector = null;
Context context = null;
context = new InitialContext();
if (null != context) {
- connector = (JNDIConnector) session.getLogin().getConnector(); // possible
+ connector = (JNDIConnector) aSession.getLogin().getConnector(); // possible
// CCE
// Change from COMPOSITE_NAME_LOOKUP to STRING_LOOKUP
// Note: if both jta and non-jta elements exist this will only
// Or, if you are specifying both JTA and non-JTA in your
// persistence.xml then set both connectors to be safe
- JNDIConnector writeConnector = (JNDIConnector) session
+ JNDIConnector writeConnector = (JNDIConnector) aSession
.getLogin().getConnector();
writeConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
- JNDIConnector readConnector = (JNDIConnector) ((DatabaseLogin) ((ServerSession) session)
+ JNDIConnector readConnector = (JNDIConnector) ((DatabaseLogin) ((ServerSession) aSession)
.getReadConnectionPool().getLogin()).getConnector();
readConnector.setLookupType(JNDIConnector.STRING_LOOKUP);