org.nakedobjects.nos.remote.CommandClientConnectionInstaller Maven / Gradle / Ivy
package org.nakedobjects.nos.remote;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.nakedobjects.noa.persist.NakedObjectPersistor;
import org.nakedobjects.noa.reflect.NakedObjectReflector;
import org.nakedobjects.noa.security.SessionManager;
import org.nakedobjects.nof.core.conf.Configuration;
import org.nakedobjects.nof.core.persist.OidGenerator;
import org.nakedobjects.nof.core.persist.SimpleOidGenerator;
import org.nakedobjects.nof.core.persist.TimeBasedOidGenerator;
import org.nakedobjects.nof.core.system.ClientConnectionInstaller;
import org.nakedobjects.nof.core.system.InstanceFactory;
import org.nakedobjects.nof.core.system.ObjectLoaderInstaller;
import org.nakedobjects.nof.core.util.NakedObjectConfiguration;
import org.nakedobjects.nof.reflect.peer.ReflectionPeerFactory;
import org.nakedobjects.nof.reflect.peer.ReflectionPeerFactoryInstaller;
import org.nakedobjects.nof.reflect.remote.ProxyPeerFactory;
import org.nakedobjects.nof.reflect.remote.ProxyPersistor;
import org.nakedobjects.nof.reflect.remote.data.Distribution;
import org.nakedobjects.nof.reflect.security.AuthorisationManager;
import org.nakedobjects.nof.reflect.security.SecurityPeerFactory;
import org.nakedobjects.nos.remote.command.java.JavaDataFactory;
import org.nakedobjects.nos.remote.command.marshal.CriteriaEncoding;
import org.nakedobjects.nos.remote.command.marshal.Marshaller;
public abstract class CommandClientConnectionInstaller implements ClientConnectionInstaller, ReflectionPeerFactoryInstaller {
private static final Logger LOG = Logger.getLogger(CommandClientConnectionInstaller.class);
private Distribution connection;
private Marshaller encoder;
public Properties getRemoteProperties() {
return getConnection().getProperties();
}
private Distribution getConnection() {
if (connection == null) {
connection = createConnection();
connection.init();
}
return connection;
}
protected abstract Distribution createConnection();
public SessionManager createAuthenticationManager() {
return new ProxyAuthenticationManager(connection);
}
public void installStrategies(final NakedObjectConfiguration configuration) {
String[] encoders = configuration.getList(Configuration.ROOT + "criteria.encoders");
if (encoders == null) {
encoders = new String[0];
}
Marshaller encoder = getEncoder();
for (int i = 0; i < encoders.length; i++) {
CriteriaEncoding encoding = (CriteriaEncoding) InstanceFactory.createInstance(encoders[i], CriteriaEncoding.class);
encoder.addCriteriaStrategy(encoding);
}
}
private Marshaller getEncoder() {
if (encoder == null) {
encoder = new Marshaller();
encoder.setDataFactory(new JavaDataFactory());
}
return encoder;
}
public NakedObjectPersistor createObjectPersistor(final NakedObjectConfiguration configuration) {
LOG.info("installing " + this.getClass().getName());
installStrategies(configuration);
ProxyPersistor persistor = new ProxyPersistor();
Distribution connection = getConnection();
persistor.setConnection(connection);
Marshaller encoder = getEncoder();
persistor.setEncoder(encoder);
String className = configuration.getString(Configuration.ROOT + "persistor.oid-generator", SimpleOidGenerator.class
.getName());
OidGenerator oidGenerator = (OidGenerator) InstanceFactory.createInstance(className, TimeBasedOidGenerator.class,
OidGenerator.class);
persistor.setOidGenerator(oidGenerator);
return persistor;
}
public ReflectionPeerFactory[] createFactories() {
// REVIEW changed to install multiple factories and setup connection for
// proxy - need to be reviwed.
final ProxyPeerFactory peerFactory = new ProxyPeerFactory();
final Distribution connection = getConnection();
peerFactory.setConnection(connection);
final Marshaller encoder = getEncoder();
peerFactory.setEncoder(encoder);
final SecurityPeerFactory securityFactory = new SecurityPeerFactory();
final AuthorisationManager authManager = new ProxyAuthorisationManager(connection);
securityFactory.setAuthorisationManager(authManager);
return new ReflectionPeerFactory[] { peerFactory, securityFactory };
}
/**
* Returns null to indicate that the default object loader should be used, i.e. a specific loader is not
* required.
*/
public ObjectLoaderInstaller getPreferredObjectLoaderInstaller() {
return null;
}
/**
* Empty implementation - do nothing to the reflector.
*/
public void setUpReflector(NakedObjectReflector reflector) {}
}
// Copyright (c) Naked Objects Group Ltd.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy