/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */
package org.apache.openjpa.sdo;

import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
import org.apache.openjpa.conf.OpenJPAProductDerivation;
import org.apache.openjpa.lib.conf.AbstractProductDerivation;
import org.apache.openjpa.lib.conf.Configuration;
import org.apache.openjpa.lib.conf.ConfigurationProvider;
import org.apache.openjpa.lib.conf.Value;

/**
 * Configures SDO-enabled JPA Runtime.
 * To activate SDO-enabled JPA Runtime, configure 
 * <code>META-INF/persistence.xml</code> as:<br>
 * <pre>
 *  &lt;property name="openjpa.EntityManagerFactory" value="sdo"/&gt;
 * </pre>
 * 
 * 
 * @author Pinaki Poddar
 * @since 0.1.0
 */
public class SDOProductDerivation extends AbstractProductDerivation {
	
	private static final String SDO = "sdo";
	
	public int getType() {
		return OpenJPAProductDerivation.TYPE_FEATURE;
	}
	
    @Override
    public boolean beforeConfigurationConstruct(ConfigurationProvider c) {
    	return true;
    }
    
    @Override
    public boolean beforeConfigurationLoad(Configuration c) {
        if (!(c instanceof OpenJPAConfigurationImpl))
            return false;
        
        OpenJPAConfigurationImpl conf = (OpenJPAConfigurationImpl) c;
        
        Value value = conf.getValue("EntityManagerFactory");
        value.setAlias(SDO, SDOEntityManagerFactory.class.getName());
        conf.metaFactoryPlugin.setAlias(SDO, SDOMetaDataFactory.class.getName());
        return true;
    }	
    
}
