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.camel.component.jpa;
018    
019    import java.util.Map;
020    import javax.persistence.EntityManagerFactory;
021    
022    import org.apache.camel.Endpoint;
023    import org.apache.camel.impl.DefaultComponent;
024    import org.springframework.transaction.PlatformTransactionManager;
025    
026    /**
027     * A JPA Component
028     *
029     * @version $Revision: 835186 $
030     */
031    public class JpaComponent extends DefaultComponent {
032        private EntityManagerFactory entityManagerFactory;
033        private PlatformTransactionManager transactionManager;
034    
035        // Properties
036        //-------------------------------------------------------------------------
037        public EntityManagerFactory getEntityManagerFactory() {
038            return entityManagerFactory;
039        }
040    
041        public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
042            this.entityManagerFactory = entityManagerFactory;
043        }
044    
045        public PlatformTransactionManager getTransactionManager() {
046            return transactionManager;
047        }
048    
049        public void setTransactionManager(PlatformTransactionManager transactionManager) {
050            this.transactionManager = transactionManager;
051        }
052    
053        // Implementation methods
054        //-------------------------------------------------------------------------
055    
056        @Override
057        protected Endpoint createEndpoint(String uri, String path, Map<String, Object> options) throws Exception {
058            JpaEndpoint endpoint = new JpaEndpoint(uri, this);
059    
060            // lets interpret the next string as a class
061            if (path != null) {
062                // provide the class loader of this component to work in OSGi environments as camel-jpa must be able
063                // to resolve the entity classes
064                Class<?> type = getCamelContext().getClassResolver().resolveClass(path, JpaComponent.class.getClassLoader());
065                if (type != null) {
066                    endpoint.setEntityType(type);
067                }
068            }
069    
070            return endpoint;
071        }
072    }