You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ni...@apache.org on 2008/06/07 13:19:56 UTC
svn commit: r664321 -
/mina/trunk/statemachine/src/main/java/org/apache/mina/statemachine/StateMachineProxyBuilder.java
Author: niklas
Date: Sat Jun 7 04:19:55 2008
New Revision: 664321
URL: http://svn.apache.org/viewvc?rev=664321&view=rev
Log:
Added javadoc for setters.
Added name property which will be used by the dynamic proxy's toString() method.
Modified:
mina/trunk/statemachine/src/main/java/org/apache/mina/statemachine/StateMachineProxyBuilder.java
Modified: mina/trunk/statemachine/src/main/java/org/apache/mina/statemachine/StateMachineProxyBuilder.java
URL: http://svn.apache.org/viewvc/mina/trunk/statemachine/src/main/java/org/apache/mina/statemachine/StateMachineProxyBuilder.java?rev=664321&r1=664320&r2=664321&view=diff
==============================================================================
--- mina/trunk/statemachine/src/main/java/org/apache/mina/statemachine/StateMachineProxyBuilder.java (original)
+++ mina/trunk/statemachine/src/main/java/org/apache/mina/statemachine/StateMachineProxyBuilder.java Sat Jun 7 04:19:55 2008
@@ -56,55 +56,131 @@
private boolean ignoreUnhandledEvents = false;
private boolean ignoreStateContextLookupFailure = false;
+
+ private String name = null;
- // the classloader to use, if null, then will use the class local one
+ /*
+ * The classloader to use. Iif null we will use the current thread's
+ * context classloader.
+ */
private ClassLoader defaultCl = null;
public StateMachineProxyBuilder() {
}
+ /**
+ * Sets the name of the proxy created by this builder. This will be used
+ * by the proxies <code>toString()</code> method. If not specified a default
+ * auto generated name will be used.
+ *
+ * @param name the name.
+ * @return this {@link StateMachineProxyBuilder} for method chaining.
+ */
+ public StateMachineProxyBuilder setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ /**
+ * Sets the {@link StateContextLookup} to be used. The default is to use
+ * a {@link SingletonStateContextLookup}.
+ *
+ * @param contextLookup the {@link StateContextLookup} to use.
+ * @return this {@link StateMachineProxyBuilder} for method chaining.
+ */
public StateMachineProxyBuilder setStateContextLookup(
StateContextLookup contextLookup) {
this.contextLookup = contextLookup;
return this;
}
+ /**
+ * Sets the {@link EventFactory} to be used. The default is to use a
+ * {@link DefaultEventFactory}.
+ *
+ * @param eventFactory the {@link EventFactory} to use.
+ * @return this {@link StateMachineProxyBuilder} for method chaining.
+ */
public StateMachineProxyBuilder setEventFactory(EventFactory eventFactory) {
this.eventFactory = eventFactory;
return this;
}
+ /**
+ * Sets the {@link EventArgumentsInterceptor} to be used. By default no
+ * {@link EventArgumentsInterceptor} will be used.
+ *
+ * @param interceptor the {@link EventArgumentsInterceptor} to use.
+ * @return this {@link StateMachineProxyBuilder} for method chaining.
+ */
public StateMachineProxyBuilder setEventArgumentsInterceptor(
EventArgumentsInterceptor interceptor) {
this.interceptor = interceptor;
return this;
}
+ /**
+ * Sets whether events which have no handler in the current state will raise
+ * an exception or be silently ignored. The default is to raise an
+ * exception.
+ *
+ * @param b <code>true</code> to ignore context lookup failures.
+ * @return this {@link StateMachineProxyBuilder} for method chaining.
+ */
public StateMachineProxyBuilder setIgnoreUnhandledEvents(boolean b) {
this.ignoreUnhandledEvents = b;
return this;
}
+ /**
+ * Sets whether the failure to lookup a {@link StateContext} corresponding
+ * to a method call on the proxy produced by this builder will raise an
+ * exception or be silently ignored. The default is to raise an exception.
+ *
+ * @param b <code>true</code> to ignore context lookup failures.
+ * @return this {@link StateMachineProxyBuilder} for method chaining.
+ */
public StateMachineProxyBuilder setIgnoreStateContextLookupFailure(boolean b) {
this.ignoreStateContextLookupFailure = b;
return this;
}
/**
- * Set the class loader to use for instanciate proxies.
- * @params cl the class loader
- * @return StateMachineProxyBuilder this for chaining
+ * Sets the class loader to use for instantiating proxies. The default is
+ * to use the current threads context {@link ClassLoader} as returned by
+ * {@link Thread#getContextClassLoader()}.
+ *
+ * @param cl the class loader
+ * @return this {@link StateMachineProxyBuilder} for method chaining.
*/
public StateMachineProxyBuilder setClassLoader(ClassLoader cl) {
this.defaultCl = cl;
return this;
}
+ /**
+ * Creates a proxy for the specified interface and which uses the specified
+ * {@link StateMachine}.
+ *
+ * @param iface the interface the proxy will implement.
+ * @param sm the {@link StateMachine} which will receive the events
+ * generated by the method calls on the proxy.
+ * @return the proxy object.
+ */
@SuppressWarnings("unchecked")
public <T> T create(Class<T> iface, StateMachine sm) {
return (T) create(new Class[] { iface }, sm);
}
+ /**
+ * Creates a proxy for the specified interfaces and which uses the specified
+ * {@link StateMachine}.
+ *
+ * @param ifaces the interfaces the proxy will implement.
+ * @param sm the {@link StateMachine} which will receive the events
+ * generated by the method calls on the proxy.
+ * @return the proxy object.
+ */
public Object create(Class<?>[] ifaces, StateMachine sm) {
ClassLoader cl = defaultCl;
if (cl == null) {
@@ -113,7 +189,7 @@
InvocationHandler handler = new MethodInvocationHandler(sm,
contextLookup, interceptor, eventFactory,
- ignoreUnhandledEvents, ignoreStateContextLookupFailure);
+ ignoreUnhandledEvents, ignoreStateContextLookupFailure, name);
return Proxy.newProxyInstance(cl, ifaces, handler);
}
@@ -125,10 +201,12 @@
private final EventFactory eventFactory;
private final boolean ignoreUnhandledEvents;
private final boolean ignoreStateContextLookupFailure;
+ private final String name;
public MethodInvocationHandler(StateMachine sm, StateContextLookup contextLookup,
EventArgumentsInterceptor interceptor, EventFactory eventFactory,
- boolean ignoreUnhandledEvents, boolean ignoreStateContextLookupFailure) {
+ boolean ignoreUnhandledEvents, boolean ignoreStateContextLookupFailure,
+ String name) {
this.contextLookup = contextLookup;
this.sm = sm;
@@ -136,6 +214,7 @@
this.eventFactory = eventFactory;
this.ignoreUnhandledEvents = ignoreUnhandledEvents;
this.ignoreStateContextLookupFailure = ignoreStateContextLookupFailure;
+ this.name = name;
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
@@ -146,7 +225,7 @@
return Boolean.valueOf(proxy == args[0]);
}
if ("toString".equals(method.getName()) && args == null) {
- return proxy.getClass().getName() + "@"
+ return (name != null ? name : proxy.getClass().getName()) + "@"
+ Integer.toHexString(System.identityHashCode(proxy));
}