001/** 002 * Copyright 2015 DuraSpace, Inc. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.fcrepo.camel; 017 018import static org.slf4j.LoggerFactory.getLogger; 019 020import java.util.Map; 021 022import org.apache.camel.CamelContext; 023import org.apache.camel.Endpoint; 024import org.apache.camel.impl.UriEndpointComponent; 025import org.slf4j.Logger; 026import org.springframework.transaction.PlatformTransactionManager; 027 028/** 029 * Represents the component that manages {@link FcrepoEndpoint}. 030 * @author Aaron Coburn 031 * @since October 20, 2014 032 */ 033public class FcrepoComponent extends UriEndpointComponent { 034 035 private FcrepoConfiguration configuration; 036 037 private PlatformTransactionManager transactionManager; 038 039 private static final Logger LOGGER = getLogger(FcrepoComponent.class); 040 041 /** 042 * Create a FcrepoComponent independent of a CamelContext. 043 */ 044 public FcrepoComponent() { 045 super(FcrepoEndpoint.class); 046 } 047 048 /** 049 * Given a CamelContext, create a FcrepoComponent instance. 050 * @param context the camel context for the component. 051 */ 052 public FcrepoComponent(final CamelContext context) { 053 super(context, FcrepoEndpoint.class); 054 } 055 056 /** 057 * Given a FcrepoConfiguration, create a FcrepoComponent instance. 058 * @param config the component-wide configuration. 059 */ 060 public FcrepoComponent(final FcrepoConfiguration config) { 061 super(FcrepoEndpoint.class); 062 this.configuration = config; 063 } 064 065 /** 066 * Get the component's configuration. 067 * @return the configuration for the component. 068 */ 069 public FcrepoConfiguration getConfiguration() { 070 if (configuration == null) { 071 configuration = new FcrepoConfiguration(); 072 } 073 return configuration; 074 } 075 076 /** 077 * Set the component's configuration. 078 * @param config the configuration settings for the component. 079 */ 080 public void setConfiguration(final FcrepoConfiguration config) { 081 this.configuration = config; 082 } 083 084 /** 085 * Set the transaction manager for the component 086 * 087 * @param transactionManager the transaction manager for this component 088 */ 089 public void setTransactionManager(final PlatformTransactionManager transactionManager) { 090 this.transactionManager = transactionManager; 091 } 092 093 /** 094 * Get the transaction manager for the component 095 * 096 * @return the transaction manager for this component 097 */ 098 public PlatformTransactionManager getTransactionManager() { 099 return transactionManager; 100 } 101 102 /** 103 * set the authUsername value component-wide. 104 * @param username the authentication username. 105 */ 106 public void setAuthUsername(final String username) { 107 getConfiguration().setAuthUsername(username); 108 } 109 110 /** 111 * set the authPassword value component-wide. 112 * @param password the authentication password. 113 */ 114 public void setAuthPassword(final String password) { 115 getConfiguration().setAuthPassword(password); 116 } 117 118 /** 119 * set the authHost value component-wide. 120 * @param host the authentication host realm. 121 */ 122 public void setAuthHost(final String host) { 123 getConfiguration().setAuthHost(host); 124 } 125 126 /** 127 * set the baseUrl component-wide 128 * @param baseUrl the repository root 129 */ 130 public void setBaseUrl(final String baseUrl) { 131 getConfiguration().setBaseUrl(baseUrl); 132 } 133 134 /** 135 * Create an Endpoint from a fcrepo uri along with an optional path value and attributes. 136 * @param uri the fcrepo uri identifying the repository hostname and port 137 * @param remaining the string identifying the repository path 138 * @param parameters any optional attributes added to the endpoint 139 * @return the camel endpoint 140 */ 141 @Override 142 protected Endpoint createEndpoint(final String uri, final String remaining, final Map<String, Object> parameters) { 143 144 FcrepoConfiguration newConfig; 145 if (configuration == null) { 146 newConfig = new FcrepoConfiguration(); 147 } else { 148 newConfig = configuration.clone(); 149 } 150 151 final Endpoint endpoint = new FcrepoEndpoint(uri, remaining, this, newConfig); 152 endpoint.configureProperties(parameters); 153 LOGGER.debug("Created Fcrepo Endpoint [{}]", endpoint); 154 return endpoint; 155 } 156}