Skip to main content
summaryrefslogtreecommitdiffstats
blob: 79c9c71d5caac1c7f63563eb15c90382756d8fc3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************************************
 * Copyright (c) 2007 Oracle Corporation.
 * 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.jst.jsf.common.metadata.internal;

import java.util.Iterator;

import org.eclipse.jst.jsf.common.metadata.Entity;
import org.eclipse.jst.jsf.common.metadata.EntityGroup;
import org.eclipse.jst.jsf.common.metadata.Model;
import org.eclipse.jst.jsf.common.metadata.Trait;


/**
 * A 'null' translation of a metadata file.  Entities and traits are not transformed.
 *
 */
public class StandardAnnotationFilesTranslator implements IMetaDataTranslator {

	public void translate(IMetaDataModelMergeAssistant assistant) {//TODO: throw proper errors
		//null translate - sourceModel object are already Entities and traits
		//traverse the tree and add to model
		
		//temp - throw proper errors 
		//assert assistant.getSourceModel() instanceof ModelKeyDescriptor;
		
		MetaDataModel mm = assistant.getMergedModel();
		if (mm.getRoot() == null)
			mm.setRoot(assistant.getSourceModelProvider().getSourceModel());
		
		else {
			//for each entity and trait call "add".   assistant will handle merge.
			Model mk = (Model)assistant.getSourceModelProvider().getSourceModel();
			if (mk != null)//possible that model was not loaded
				traverseAndAdd(assistant, mk);
		}			
	}
	
	/**
	 * Add entity and any children
	 * @param assistant
	 * @param entity
	 */
	protected void traverseAndAdd(IMetaDataModelMergeAssistant assistant, final Entity entity){
		assistant.addEntity(entity);
		
		if (entity instanceof Model){
			Model model = (Model)entity;
			for (final Iterator/*EntityGroup*/ it=model.getEntityGroups().iterator();it.hasNext();){
				assistant.addEntityGroup((EntityGroup)it.next());
			}
		}
		
		for (final Iterator/*<Trait>*/ it=entity.getTraits().iterator();it.hasNext();){
			Trait trait = (Trait)it.next();
			assistant.addTrait(entity, trait);
		}
		
		for (final Iterator/*<EntityKey>*/ it=entity.getChildEntities().iterator();it.hasNext();){
			Entity e = (Entity)it.next();
			traverseAndAdd(assistant, e);
		}
		
	}
}

Back to the top