Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogblamecommitdiffstats
blob: 01c21903afa9227e01d7ea2ad7fb726ab1422f7c (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                                                







                                                                                

                                                       
                      
                                                     





                                                                                 

                                                                      




                                         







                                                                                     
                              

                                                                 
         








                                                                   
         






                                             
         



                                                     
                                                                                   















                                                                                                        
                 

                                                    
                 







                                                          
         
 
                                                      


                                                     
         





                                                                               
         






















                                                                        
                                                                                       
                                           
         
 
                                                        


                                                  
         
 
                                                          

                                                     
         
 
                                                            
                                                            

         

                                                                             
         






                                                                           
         


                                                             
         
 
                                                                              


                                                                                                          
         



                                           


                                                                           





                                                                  
         
 
/*******************************************************************************
 * Copyright (c) 2009, 2010 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 *
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.core.internal.jpa2.context.orm;

import java.util.List;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.core.internal.context.orm.AbstractOrmXmlContextNode;
import org.eclipse.jpt.core.jpa2.context.DerivedIdentityStrategy2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedIdentity2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmIdDerivedIdentityStrategy2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmMapsIdDerivedIdentityStrategy2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmSingleRelationshipMapping2_0;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;

public class GenericOrmDerivedIdentity2_0
	extends AbstractOrmXmlContextNode
	implements OrmDerivedIdentity2_0
{
	protected DerivedIdentityStrategy2_0 strategy;

	protected OrmIdDerivedIdentityStrategy2_0 idStrategy;

	protected OrmMapsIdDerivedIdentityStrategy2_0 mapsIdStrategy;


	public GenericOrmDerivedIdentity2_0(OrmSingleRelationshipMapping2_0 parent) {
		super(parent);
		this.idStrategy = this.buildIdStrategy();
		this.mapsIdStrategy = this.buildMapsIdStrategy();
	}


	// ********** synchronize/update **********

	@Override
	public void synchronizeWithResourceModel() {
		super.synchronizeWithResourceModel();
		this.idStrategy.synchronizeWithResourceModel();
		this.mapsIdStrategy.synchronizeWithResourceModel();
	}

	@Override
	public void update() {
		super.update();
		this.idStrategy.update();
		this.mapsIdStrategy.update();
		this.updateStrategy();
	}


	// ********** predominant strategy **********

	public DerivedIdentityStrategy2_0 getPredominantDerivedIdentityStrategy() {
		return this.strategy;
	}

	protected void setStrategy(DerivedIdentityStrategy2_0 strategy) {
		DerivedIdentityStrategy2_0 old = this.strategy;
		this.strategy = strategy;
		this.firePropertyChanged(PREDOMINANT_DERIVED_IDENTITY_STRATEGY_PROPERTY, old, strategy);
	}

	protected void updateStrategy() {
		this.setStrategy(this.buildStrategy());
	}

	protected DerivedIdentityStrategy2_0 buildStrategy() {
		if (this.mapsIdStrategy.isSpecified()) {
			return this.mapsIdStrategy;
		}
		if (this.idStrategy.isSpecified()) {
			return this.idStrategy;
		}
		return null;
	}


	// ********** null strategy **********

	public boolean usesNullDerivedIdentityStrategy() {
		return this.strategy == null;
	}

	public void setNullDerivedIdentityStrategy() {
		this.mapsIdStrategy.removeStrategy();
		this.idStrategy.removeStrategy();
		this.updateStrategy();
	}


	// ********** ID strategy **********

	public OrmIdDerivedIdentityStrategy2_0 getIdDerivedIdentityStrategy() {
		return this.idStrategy;
	}

	public void setIdDerivedIdentityStrategy() {
		this.idStrategy.addStrategy();
		this.mapsIdStrategy.removeStrategy();
		this.updateStrategy();
	}

	public void unsetIdDerivedIdentityStrategy() {
		this.idStrategy.removeStrategy();
		this.updateStrategy();
	}

	public boolean usesIdDerivedIdentityStrategy() {
		return this.strategy == this.idStrategy;
	}

	protected OrmIdDerivedIdentityStrategy2_0 buildIdStrategy() {
		return new GenericOrmIdDerivedIdentityStrategy2_0(this);
	}


	// ********** maps ID strategy **********

	public OrmMapsIdDerivedIdentityStrategy2_0 getMapsIdDerivedIdentityStrategy() {
		return this.mapsIdStrategy;
	}

	public void setMapsIdDerivedIdentityStrategy() {
		this.mapsIdStrategy.addStrategy();
		this.idStrategy.removeStrategy();
		this.updateStrategy();
	}

	public void unsetMapsIdDerivedIdentityStrategy() {
		this.mapsIdStrategy.removeStrategy();
		this.updateStrategy();
	}

	public boolean usesMapsIdDerivedIdentityStrategy() {
		return this.strategy == this.mapsIdStrategy;
	}

	protected OrmMapsIdDerivedIdentityStrategy2_0 buildMapsIdStrategy() {
		return new GenericOrmMapsIdDerivedIdentityStrategy2_0(this);
	}


	// ********** misc **********

	@Override
	public OrmSingleRelationshipMapping2_0 getParent() {
		return (OrmSingleRelationshipMapping2_0) super.getParent();
	}

	public OrmSingleRelationshipMapping2_0 getMapping() {
		return this.getParent();
	}

	public void initializeFrom(OrmDerivedIdentity2_0 oldDerivedIdentity) {
		this.idStrategy.initializeFrom(oldDerivedIdentity.getIdDerivedIdentityStrategy());
		this.mapsIdStrategy.initializeFrom(oldDerivedIdentity.getMapsIdDerivedIdentityStrategy());
		this.updateStrategy();
	}


	// ********** validation **********

	@Override
	public void validate(List<IMessage> messages, IReporter reporter) {
		super.validate(messages, reporter);
		this.idStrategy.validate(messages, reporter);
		this.mapsIdStrategy.validate(messages, reporter);
	}

	public TextRange getValidationTextRange() {
		return this.getMapping().getValidationTextRange();
	}
}

Back to the top