001 package org.granite.client.messaging.channel;
002
003 import java.net.URI;
004
005 import org.granite.client.configuration.Configuration;
006 import org.granite.client.messaging.channel.amf.AMFMessagingChannel;
007 import org.granite.client.messaging.channel.amf.AMFRemotingChannel;
008 import org.granite.client.messaging.channel.amf.JMFAMFMessagingChannel;
009 import org.granite.client.messaging.channel.amf.JMFAMFRemotingChannel;
010 import org.granite.client.messaging.transport.Transport;
011 import org.granite.util.ContentType;
012
013 public class ChannelFactory {
014
015 private final ContentType contentType;
016
017 public ChannelFactory(ContentType contentType) {
018 this.contentType = contentType;
019 }
020
021 public ContentType getContentType() {
022 return contentType;
023 }
024
025 public RemotingChannel newRemotingChannel(Transport transport, String id, URI uri) {
026 switch (contentType) {
027 case AMF:
028 return new AMFRemotingChannel(transport, id, uri);
029 case JMF_AMF:
030 return new JMFAMFRemotingChannel(transport, id, uri);
031 default:
032 throw new UnsupportedOperationException("Unsupported content-type: " + contentType);
033 }
034 }
035
036 public RemotingChannel newRemotingChannel(Transport transport, String id, URI uri, int maxConcurrentRequests) {
037 switch (contentType) {
038 case AMF:
039 return new AMFRemotingChannel(transport, id, uri, maxConcurrentRequests);
040
041 case JMF_AMF:
042 return new JMFAMFRemotingChannel(transport, id, uri, maxConcurrentRequests);
043 default:
044 throw new UnsupportedOperationException("Unsupported content-type: " + contentType);
045 }
046 }
047
048 public RemotingChannel newRemotingChannel(Transport transport, Configuration configuration, String id, URI uri, int maxConcurrentRequests) {
049 switch (contentType) {
050 case AMF:
051 return new AMFRemotingChannel(transport, configuration, id, uri, maxConcurrentRequests);
052
053 case JMF_AMF:
054 return new JMFAMFRemotingChannel(transport, configuration, id, uri, maxConcurrentRequests);
055 default:
056 throw new UnsupportedOperationException("Unsupported content-type: " + contentType);
057 }
058 }
059
060 public MessagingChannel newMessagingChannel(Transport transport, String id, URI uri) {
061 switch (contentType) {
062 case AMF:
063 return new AMFMessagingChannel(transport, id, uri);
064 case JMF_AMF:
065 return new JMFAMFMessagingChannel(transport, id, uri);
066 default:
067 throw new UnsupportedOperationException("Unsupported content-type: " + contentType);
068 }
069 }
070
071 public MessagingChannel newMessagingChannel(Transport transport, Configuration configuration, String id, URI uri) {
072 switch (contentType) {
073 case AMF:
074 return new AMFMessagingChannel(transport, configuration, id, uri);
075 case JMF_AMF:
076 return new JMFAMFMessagingChannel(transport, configuration, id, uri);
077 default:
078 throw new UnsupportedOperationException("Unsupported content-type: " + contentType);
079 }
080 }
081 }