Skip to main content
summaryrefslogtreecommitdiffstats
blob: a9624f10a60b5a14651a93e9ad0471b238dd0cbe (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*******************************************************************************
 * Copyright (c) 2000, 2008 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
 * -------- -------- -----------------------------------------------------------
 * 20071108   209267 pmoogk@ca.ibm.com - Peter Moogk
 * 20080318   223118 ericdp@ca.ibm.com - Eric D. Peters, metadata required in WS-I profiles to support editors & validators
 *******************************************************************************/

package org.eclipse.wst.ws.internal.preferences;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.wst.command.internal.env.context.PersistentContext;
import org.eclipse.wst.common.environment.EnvironmentService;
import org.eclipse.wst.common.environment.ILog;
import org.eclipse.wst.ws.internal.WstWSPluginMessages;
import org.eclipse.wst.ws.internal.plugin.WSPlugin;
import org.eclipse.wst.ws.service.policy.IServicePolicy;
import org.eclipse.wst.ws.service.policy.ServicePolicyPlatform;



public class PersistentWSIContext extends PersistentContext
{
	public static final String STOP_NON_WSI = "0";
	public static final String WARN_NON_WSI = "1";
	public static final String IGNORE_NON_WSI = "2";
	public static final String FOLLOW_WSI_PREFERENCE = "3";
	
	private static final String[] ENUM_ID_VALUES = { "org.eclipse.wst.sug.require", "org.eclipse.wst.sug.suggest", "org.eclipse.wst.sug.ignore"};
  private static final String[] CONTEXT_IDS    = { STOP_NON_WSI, WARN_NON_WSI, IGNORE_NON_WSI };
	
	protected QualifiedName name = null; // set in subclass
	protected String non_wsi_compliance;
	private static final String NON_WSI_SSBP_COMPLIANCE = "nonWSISSBPCompliance";
	protected String wsiWarning_; // set in subclass
	protected String wsiError_; // set in subclass

public PersistentWSIContext () 
{
	super(  WSPlugin.getInstance());
	
//  NOTE:  name, wsiWarning_ and wsiError_ should be set in the subclasses.  This is providing defaulting only.
	non_wsi_compliance = NON_WSI_SSBP_COMPLIANCE;
	name = new QualifiedName(WSPlugin.ID , non_wsi_compliance);
	wsiWarning_ = WstWSPluginMessages.WSI_SSBP_WARNING;
	wsiError_ = WstWSPluginMessages.WSI_SSBP_ERROR;
}

public void load() 
{
	// let the default be read from plugin_costomization.ini file
	// setDefault(non_wsi_compliance, WARN_NON_WSI);
}

// to be used only by the preference page
public void updateWSICompliances ( String value)
{
 		setValue( non_wsi_compliance, value);
}

public String getPersistentWSICompliance ()
{
	String property = getValueAsString(non_wsi_compliance);
//	 default to Warning if no init has been done from ini file
	if (property == null || property.equals("")) {
		setValue( non_wsi_compliance, WARN_NON_WSI);
		return WARN_NON_WSI;
	}
	else
		return property;
}

public boolean StopNonWSICompliances()
{
	 return STOP_NON_WSI.equals(getPersistentWSICompliance());
}

public boolean WarnNonWSICompliances()
{
	 return WARN_NON_WSI.equals(getPersistentWSICompliance());
}

public boolean IgnoreNonWSICompliances()
{
	 return IGNORE_NON_WSI.equals(getPersistentWSICompliance());
}

// to be used only by the property page
public void updateProjectWSICompliances ( IProject project, String value)
{
    try {
		project.setPersistentProperty(name, value);
    }
    catch (CoreException e) { 
    	System.out.println("No such Project");
    	ILog log = EnvironmentService.getEclipseLog();
    	log.log(ILog.INFO, 5084, this, "updateProjectWSICompliances", "No such Project "+project);
    }
}

public boolean projectStopNonWSICompliances(IProject project)
{
 	return STOP_NON_WSI.equals(getProjectPersistentProperty(project));    
}

public boolean projectWarnNonWSICompliances(IProject project)
{
 	return WARN_NON_WSI.equals(getProjectPersistentProperty(project));    
}

public boolean projectIgnoreNonWSICompliances(IProject project)
{
 	return IGNORE_NON_WSI.equals(getProjectPersistentProperty(project));    
}


// to be used only by the property page
public boolean projectFollowWSIPreferance(IProject project)
{
    try {
 	String property = project.getPersistentProperty(name);
    return (property == null || property.equals("") || property.equals(FOLLOW_WSI_PREFERENCE));
    	}
    catch (CoreException e)     {
    	return true;
     }     
}

private String getProjectPersistentProperty(IProject project)
{
	String property = getProjectWSICompliance(project);
	if (property.equals(FOLLOW_WSI_PREFERENCE)) {
		property = getPersistentWSICompliance();
	}
	return property;
 }

  public String getProjectWSICompliance(IProject project)
  {

    ServicePolicyPlatform platform       = ServicePolicyPlatform.getInstance();
    IServicePolicy        servicePolicy  = platform.getServicePolicy( getServicePolicyId() );
    String                currentStateID = servicePolicy.getPolicyStateEnum(project).getCurrentItem().getId();
		String                property       = FOLLOW_WSI_PREFERENCE;
		
		for( int index = 0; index < ENUM_ID_VALUES.length; index++ )
		{
		  if( ENUM_ID_VALUES[index].equals( currentStateID ) )
		  {
		    property = CONTEXT_IDS[index];
		    break;
		  }
		}
		
		return property;
  }

  protected String getServicePolicyId()
  {
    return WSIServicePoliciesConstants.ServicePolicyID_SSBP10;
  }
  
  public QualifiedName getName()
  {
    return name;  
  }
  
  public String getWarning()
  {
	  return wsiWarning_;
  }

  public String getError()
  {
	  return wsiError_;
  }
}

Back to the top