Skip to main content
summaryrefslogtreecommitdiffstats
blob: e2d08406401fdaf2f4b0a77d17bc9ff015776f95 (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
/*******************************************************************************
 * Copyright (c) 2007 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
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20071024   196997 pmoogk@ca.ibm.com - Peter Moogk
 *******************************************************************************/
package org.eclipse.wst.ws.service.internal.policy;

import java.util.List;

import org.eclipse.wst.ws.service.policy.IPolicyState;
import org.eclipse.wst.ws.service.policy.IPolicyStateEnum;
import org.eclipse.wst.ws.service.policy.IStateEnumerationItem;
import org.eclipse.wst.ws.service.policy.ServicePolicyPlatform;

public class EnumerationStateImpl implements IPolicyStateEnum
{
  private final String VALUE = IPolicyState.DefaultValueKey;  //$NON-NLS-1$
  
  private String                      enumId;
  private List<IStateEnumerationItem> enumList;
  private IPolicyState                state;
  private String                      defaultId;
  
  public EnumerationStateImpl( String enumId, String defaultId, IPolicyState state )
  {
    ServicePolicyPlatform platform = ServicePolicyPlatform.getInstance();
    
    this.enumId    = enumId;
    this.enumList  = platform.getStateEnumeration( enumId );
    this.state     = state;
    this.defaultId = enumList.get(0).getId();
   
    if( defaultId != null )
    {
      this.defaultId = defaultId;
      state.putDefaultValue( VALUE, defaultId, false ); 
    }
    else
    {
      for( IStateEnumerationItem enumItem : enumList )
      {
        if( enumItem.isDefault() )
        {
          this.defaultId = enumItem.getId();
          state.putDefaultValue( VALUE,  this.defaultId, false );
          break;
        }
      }
    }
  }

  public String getEnumId()
  {
    return enumId;
  }

  public String getDefaultId()
  {
    return defaultId;
  }
  
  public void setCurrentItem( String itemId )
  {
    for( IStateEnumerationItem enumItem : enumList )
    {
      String enumItemId = enumItem.getId();
      
      if( enumItemId.equals( itemId ) )
      {
        state.putValue( VALUE, enumItemId ); 
        break;
      }
    }
  }
  
  public IStateEnumerationItem getCurrentItem()
  {
    String                currentEnum = state.getValue( VALUE );
    IStateEnumerationItem currentItem = null;
    
    for( IStateEnumerationItem enumItem : enumList )
    {
      if( enumItem.getId().equals( currentEnum ) )
      {
        currentItem = enumItem;
        break;
      }
    }
    
    return currentItem;
  }
}

Back to the top