001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.truezip;
018
019 // import java.io.File;
020 import java.net.URI;
021 import java.util.List;
022 import java.util.Map;
023
024 import javax.jbi.servicedesc.ServiceEndpoint;
025
026 import de.schlichtherle.io.File;
027
028 import org.apache.servicemix.common.DefaultComponent;
029 import org.apache.servicemix.common.Endpoint;
030 import org.apache.servicemix.jbi.util.IntrospectionSupport;
031 import org.apache.servicemix.jbi.util.URISupport;
032
033
034 /**
035 * A file based component
036 *
037 * @version $Revision: 219 $
038 * @org.apache.xbean.XBean element="component" description="File Component"
039 */
040 public class TrueZipComponent extends DefaultComponent {
041
042 private TrueZipEndpointType[] endpoints;
043
044 public TrueZipEndpointType[] getEndpoints() {
045 return endpoints;
046 }
047
048 public void setEndpoints(TrueZipEndpointType[] endpoints) {
049 this.endpoints = endpoints;
050 }
051
052 protected List getConfiguredEndpoints() {
053 return asList(getEndpoints());
054 }
055
056 protected Class[] getEndpointClasses() {
057 return new Class[] {TrueZipPollerEndpoint.class, TrueZipSenderEndpoint.class};
058 }
059
060 protected Endpoint getResolvedEPR(ServiceEndpoint ep) throws Exception {
061 // We receive an exchange for an EPR that has not been used yet.
062 // Register a provider endpoint and restart processing.
063 TrueZipSenderEndpoint fileEp = new TrueZipSenderEndpoint(this, ep);
064 URI uri = new URI(ep.getEndpointName());
065 String file = null;
066 String host = uri.getHost();
067 String path = uri.getPath();
068 if (host != null) {
069 if (path != null) {
070 // lets assume host really is a relative directory
071 file = host + File.separator + path;
072 } else {
073 file = host;
074 }
075 } else {
076 if (path != null) {
077 file = path;
078 } else {
079 // must be an absolute URI
080 file = uri.getSchemeSpecificPart();
081 }
082 }
083 Map map = URISupport.parseQuery(uri.getQuery());
084 if (IntrospectionSupport.setProperties(fileEp, map, "truezip.")) {
085 uri = URISupport.createRemainingURI(uri, map);
086 }
087 if (file != null) {
088 fileEp.setDirectory(new File(file));
089 } else {
090 throw new IllegalArgumentException("No file defined for URL: " + uri);
091 }
092 fileEp.activate();
093 return fileEp;
094 }
095
096 }