|
| 1 | +/* |
| 2 | + * Copyright 2022 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.integration.smb.dsl; |
| 18 | + |
| 19 | +import java.io.File; |
| 20 | +import java.util.Comparator; |
| 21 | + |
| 22 | +import org.springframework.integration.file.remote.MessageSessionCallback; |
| 23 | +import org.springframework.integration.file.remote.RemoteFileTemplate; |
| 24 | +import org.springframework.integration.file.remote.session.SessionFactory; |
| 25 | +import org.springframework.integration.file.support.FileExistsMode; |
| 26 | +import org.springframework.integration.smb.outbound.SmbOutboundGateway; |
| 27 | +import org.springframework.integration.smb.session.SmbRemoteFileTemplate; |
| 28 | + |
| 29 | +import jcifs.smb.SmbFile; |
| 30 | + |
| 31 | +/** |
| 32 | + * The factory for SMB components. |
| 33 | + * |
| 34 | + * @author Gregory Bragg |
| 35 | + * |
| 36 | + * @since 6.0 |
| 37 | + */ |
| 38 | +public final class Smb { |
| 39 | + |
| 40 | + /** |
| 41 | + * A {@link SmbInboundChannelAdapterSpec} factory for an inbound channel adapter spec. |
| 42 | + * @param sessionFactory the session factory. |
| 43 | + * @return the spec. |
| 44 | + */ |
| 45 | + public static SmbInboundChannelAdapterSpec inboundAdapter(SessionFactory<SmbFile> sessionFactory) { |
| 46 | + return inboundAdapter(sessionFactory, null); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * A {@link SmbInboundChannelAdapterSpec} factory for an inbound channel adapter spec. |
| 51 | + * @param sessionFactory the session factory. |
| 52 | + * @param receptionOrderComparator the comparator. |
| 53 | + * @return the spec. |
| 54 | + */ |
| 55 | + public static SmbInboundChannelAdapterSpec inboundAdapter(SessionFactory<SmbFile> sessionFactory, |
| 56 | + Comparator<File> receptionOrderComparator) { |
| 57 | + |
| 58 | + return new SmbInboundChannelAdapterSpec(sessionFactory, receptionOrderComparator); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * A {@link SmbStreamingInboundChannelAdapterSpec} factory for an inbound channel |
| 63 | + * adapter spec. |
| 64 | + * @param remoteFileTemplate the remote file template. |
| 65 | + * @return the spec. |
| 66 | + */ |
| 67 | + public static SmbStreamingInboundChannelAdapterSpec inboundStreamingAdapter( |
| 68 | + RemoteFileTemplate<SmbFile> remoteFileTemplate) { |
| 69 | + |
| 70 | + return inboundStreamingAdapter(remoteFileTemplate, null); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * A {@link SmbStreamingInboundChannelAdapterSpec} factory for an inbound channel |
| 75 | + * adapter spec. |
| 76 | + * @param remoteFileTemplate the remote file template. |
| 77 | + * @param receptionOrderComparator the comparator. |
| 78 | + * @return the spec. |
| 79 | + */ |
| 80 | + public static SmbStreamingInboundChannelAdapterSpec inboundStreamingAdapter( |
| 81 | + RemoteFileTemplate<SmbFile> remoteFileTemplate, |
| 82 | + Comparator<SmbFile> receptionOrderComparator) { |
| 83 | + |
| 84 | + return new SmbStreamingInboundChannelAdapterSpec(remoteFileTemplate, receptionOrderComparator); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * A {@link SmbMessageHandlerSpec} factory for an outbound channel adapter spec. |
| 89 | + * @param sessionFactory the session factory. |
| 90 | + * @return the spec. |
| 91 | + */ |
| 92 | + public static SmbMessageHandlerSpec outboundAdapter(SessionFactory<SmbFile> sessionFactory) { |
| 93 | + return new SmbMessageHandlerSpec(sessionFactory); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * A {@link SmbMessageHandlerSpec} factory for an outbound channel adapter spec. |
| 98 | + * @param sessionFactory the session factory. |
| 99 | + * @param fileExistsMode the file exists mode. |
| 100 | + * @return the spec. |
| 101 | + */ |
| 102 | + public static SmbMessageHandlerSpec outboundAdapter(SessionFactory<SmbFile> sessionFactory, |
| 103 | + FileExistsMode fileExistsMode) { |
| 104 | + |
| 105 | + return outboundAdapter(new SmbRemoteFileTemplate(sessionFactory), fileExistsMode); |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * A {@link SmbMessageHandlerSpec} factory for an outbound channel adapter spec. |
| 110 | + * @param smbRemoteFileTemplate the remote file template. |
| 111 | + * @return the spec. |
| 112 | + */ |
| 113 | + public static SmbMessageHandlerSpec outboundAdapter(SmbRemoteFileTemplate smbRemoteFileTemplate) { |
| 114 | + return new SmbMessageHandlerSpec(smbRemoteFileTemplate); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * A {@link SmbMessageHandlerSpec} factory for an outbound channel adapter spec. |
| 119 | + * @param smbRemoteFileTemplate the remote file template. |
| 120 | + * @param fileExistsMode the file exists mode. |
| 121 | + * @return the spec. |
| 122 | + */ |
| 123 | + public static SmbMessageHandlerSpec outboundAdapter(SmbRemoteFileTemplate smbRemoteFileTemplate, |
| 124 | + FileExistsMode fileExistsMode) { |
| 125 | + |
| 126 | + return new SmbMessageHandlerSpec(smbRemoteFileTemplate, fileExistsMode); |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * Produce a {@link SmbOutboundGatewaySpec} based on the |
| 131 | + * {@link MessageSessionCallback}. |
| 132 | + * @param sessionFactory the {@link SessionFactory} to connect to. |
| 133 | + * @param messageSessionCallback the {@link MessageSessionCallback} to perform SMB. |
| 134 | + * operation(s) with the {@code Message} context. |
| 135 | + * @return the {@link SmbOutboundGatewaySpec} |
| 136 | + * @see MessageSessionCallback |
| 137 | + */ |
| 138 | + public static SmbOutboundGatewaySpec outboundGateway(SessionFactory<SmbFile> sessionFactory, |
| 139 | + MessageSessionCallback<SmbFile, ?> messageSessionCallback) { |
| 140 | + |
| 141 | + return new SmbOutboundGatewaySpec(new SmbOutboundGateway(sessionFactory, messageSessionCallback)); |
| 142 | + } |
| 143 | + |
| 144 | + private Smb() { |
| 145 | + } |
| 146 | + |
| 147 | +} |
0 commit comments