| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| FileEndpoint |
|
| 0.0;0 |
| 1 | /** |
|
| 2 | * |
|
| 3 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
| 4 | * contributor license agreements. See the NOTICE file distributed with |
|
| 5 | * this work for additional information regarding copyright ownership. |
|
| 6 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
| 7 | * (the "License"); you may not use this file except in compliance with |
|
| 8 | * the License. You may obtain a copy of the License at |
|
| 9 | * |
|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 11 | * |
|
| 12 | * Unless required by applicable law or agreed to in writing, software |
|
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 15 | * See the License for the specific language governing permissions and |
|
| 16 | * limitations under the License. |
|
| 17 | */ |
|
| 18 | package org.apache.camel.component.file; |
|
| 19 | ||
| 20 | import org.apache.camel.Consumer; |
|
| 21 | import org.apache.camel.Processor; |
|
| 22 | import org.apache.camel.Producer; |
|
| 23 | import org.apache.camel.impl.ScheduledPollEndpoint; |
|
| 24 | ||
| 25 | import java.io.File; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * A <a href="http://activemq.apache.org/camel/file.html">File Endpoint</a> for working with file systems |
|
| 29 | * |
|
| 30 | * @version $Revision: 523016 $ |
|
| 31 | */ |
|
| 32 | 1 | public class FileEndpoint extends ScheduledPollEndpoint<FileExchange> { |
| 33 | private File file; |
|
| 34 | 1 | private boolean autoCreate=true; |
| 35 | ||
| 36 | protected FileEndpoint(File file, String endpointUri, FileComponent component) { |
|
| 37 | 1 | super(endpointUri, component); |
| 38 | 1 | this.file = file; |
| 39 | 1 | } |
| 40 | ||
| 41 | /** |
|
| 42 | * @return a Producer |
|
| 43 | * @throws Exception |
|
| 44 | * @see org.apache.camel.Endpoint#createProducer() |
|
| 45 | */ |
|
| 46 | public Producer<FileExchange> createProducer() throws Exception { |
|
| 47 | 1 | Producer<FileExchange> result = new FileProducer(this); |
| 48 | 1 | return result; |
| 49 | } |
|
| 50 | ||
| 51 | /** |
|
| 52 | * @param file |
|
| 53 | * @return a Consumer |
|
| 54 | * @throws Exception |
|
| 55 | * @see org.apache.camel.Endpoint#createConsumer(org.apache.camel.Processor) |
|
| 56 | */ |
|
| 57 | public Consumer<FileExchange> createConsumer(Processor file) throws Exception { |
|
| 58 | 1 | Consumer<FileExchange> result = new FileConsumer(this, file); |
| 59 | 1 | configureConsumer(result); |
| 60 | 1 | return result; |
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * @param file |
|
| 65 | * @return a FileExchange |
|
| 66 | * @see org.apache.camel.Endpoint#createExchange() |
|
| 67 | */ |
|
| 68 | public FileExchange createExchange(File file) { |
|
| 69 | 711 | return new FileExchange(getContext(), file); |
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * @return an Exchange |
|
| 74 | * @see org.apache.camel.Endpoint#createExchange() |
|
| 75 | */ |
|
| 76 | public FileExchange createExchange() { |
|
| 77 | 1 | return createExchange(getFile()); |
| 78 | } |
|
| 79 | ||
| 80 | public File getFile() { |
|
| 81 | 5 | if (autoCreate && !file.exists()) { |
| 82 | 0 | file.mkdirs(); |
| 83 | } |
|
| 84 | 5 | return file; |
| 85 | } |
|
| 86 | ||
| 87 | public boolean isSingleton() { |
|
| 88 | 1 | return true; |
| 89 | } |
|
| 90 | ||
| 91 | ||
| 92 | /** |
|
| 93 | * @return the autoCreate |
|
| 94 | */ |
|
| 95 | public boolean isAutoCreate(){ |
|
| 96 | 0 | return this.autoCreate; |
| 97 | } |
|
| 98 | ||
| 99 | ||
| 100 | /** |
|
| 101 | * @param autoCreate the autoCreate to set |
|
| 102 | */ |
|
| 103 | public void setAutoCreate(boolean autoCreate){ |
|
| 104 | 0 | this.autoCreate=autoCreate; |
| 105 | 0 | } |
| 106 | } |