Skip to main content
summaryrefslogtreecommitdiffstats
blob: e1a5f2e7d8a9833541d2bd9a0d47a6f6eb2d0895 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*******************************************************************************
 * Copyright (c) 2004, 2005 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.command.internal.env.core.data;

import java.util.Hashtable;
import java.util.Vector;


public class DataMappingRegistryImpl implements DataMappingRegistry
{  
  private Hashtable rulesTable_ = new Hashtable();

  public Vector getRuleEntries( String targetType )
  {
    return (Vector)rulesTable_.get( targetType );
  }
  
  /* (non-Javadoc)
   * @see org.eclipse.wst.command.internal.env.core.data.DataMappingRegistry#addMapping(java.lang.Class, java.lang.String, java.lang.Class, java.lang.String, org.eclipse.wst.command.internal.env.core.data.Transformer)
   */
  public void addMapping( Class sourceType, String sourceProperty,
                          Class targetType, String targetProperty, 
                          Transformer transformer) 
  {
    Vector    ruleEntries = (Vector)rulesTable_.get( targetType.getName() );
    RuleEntry ruleEntry   = null;
    
    if( ruleEntries == null )
    {
      ruleEntries = new Vector();
      rulesTable_.put( targetType.getName(), ruleEntries );
    }
    
    // Find the rule entry
    for( int index = 0; index < ruleEntries.size(); index++ )
    {
      RuleEntry newEntry = (RuleEntry)ruleEntries.elementAt( index );
    
      if( sourceProperty.equals( newEntry.sourceProperty_ ) &&
          sourceType.equals( newEntry.sourceType_ ) &&
          targetProperty.equals( newEntry.targetProperty_ ) )
      {
        // The entry already exists
        ruleEntry = newEntry;
        break;
      }
    }
    
    if( ruleEntry == null )
    {
      // The rule didn't exist already so we will create a new one.
      ruleEntry = new RuleEntry(sourceType.getName(), sourceProperty, targetProperty, transformer );
      ruleEntries.add( ruleEntry );
    }
    else
    {
      // Just update the transformer.
      ruleEntry.transformer_ = transformer;  
    }
  }
    
    //ruleEntries_.
//    String    sourceClass = sourceType.getName();
//    String    targetClass = targetType.getName();
//    Vector    entries     = (Vector)ruleEntries_.get( sourceClass ); 
//    RuleEntry ruleEntry   = null;
//    
//    if( entries != null )
//    {
//      // Check to see if this mapping already exists.
//      for( int index = 0; index < entries.size(); index++ )
//      {
//        RuleEntry foundEntry = (RuleEntry)entries.elementAt( index );
//        
//        if( sourceProperty.equals( foundEntry.sourceProperty_ ) &&
//            targetType.equals( foundEntry.targetType_ ) &&
//            targetProperty.equals( foundEntry.targetProperty_ ) )
//        {
//          ruleEntry = foundEntry;
//          ruleEntry.transformer_ = transformer;
//        }
//      }
//      
//      // There is an existing vector for this sourceClass, but it didn't
//      // contain this new rule so we will add it in.
//      if( ruleEntry == null )
//      {
//        ruleEntry = new RuleEntry( sourceProperty, targetClass, targetProperty, transformer );
//        entries.add( ruleEntry );
//      }
//    }
//    else
//    {
//      // We need to create a new vector for this sourceClass.
//      entries = new Vector();
//      ruleEntry = new RuleEntry( sourceProperty, targetClass, targetProperty, transformer );
//      entries.add( ruleEntry );
//      ruleEntries_.put( sourceClass, entries );  
//    }    
//  }
  
  /* (non-Javadoc)
   * @see org.eclipse.wst.command.internal.env.core.data.DataMappingRegistry#addMapping(java.lang.Class, java.lang.String, java.lang.Class)
   */
  public void addMapping(Class sourceType, String sourceProperty, Class targetType) 
  {
    addMapping( sourceType, sourceProperty, targetType, sourceProperty, null );
  }
}

Back to the top