Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8f4fcf20c709c3ed5c99be0965d4c2bb5fef4e69 (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
/*******************************************************************************
 * Copyright (c) 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
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20060303   128832 joan@ca.ibm.com - Joan Haggarty
 *******************************************************************************/
package org.eclipse.jst.ws.internal.common;

import java.util.Map;

import org.eclipse.jst.ws.internal.data.TypeRuntimeServer;
import org.eclipse.wst.command.internal.env.core.data.BeanModifier;

public class String2TypeRuntimeServerModifier implements BeanModifier {

	private String SERVICE_RT_ID_KEY = "Service.RuntimeId";  //$NON-NLS-N$
	private String RUNTIME_ID = "RuntimeId";  //$NON-NLS-N$
	private String SERVICE_SRV_ID_KEY = "Service.ServerId";  //$NON-NLS-N$
	private String SERVER_ID = "ServerId";  //$NON-NLS-N$
	private String TYPE_ID = "TypeId";  //$NON-NLS-N$
	private String TD_EJB = "TOP DOWN EJB";  //$NON-NLS-N$
	private String BU_EJB = "BOTTOM UP EJB";  //$NON-NLS-N$
	private String TD_EJB_TYPE_ID = "1/org.eclipse.jst.ws.wsImpl.ejb";
	private String BU_EJB_TYPE_ID = "0/org.eclipse.jst.ws.wsImpl.ejb";
	private String SERVICE_PREFIX = "Service.";  //$NON-NLS-N$
	private String CLIENT_PREFIX = "Client.";  //$NON-NLS-N$
	
	/**
	 * Modifies the supplied TypeRuntimeServer bean with properties in holder.
	 * If the bean is null, construct a new one and set its properties.
	 * @param bean TypeRuntimeServer bean to be modified
	 * @param holder Map containing values for TypeRuntimeServer properties 
	 * @return TypeRuntimeServer with properties set
	 */
	public void modify(Object bean, Object holder) {
		
		TypeRuntimeServer types = null;
		if (bean == null || !(bean instanceof TypeRuntimeServer))
		{
			types = new TypeRuntimeServer();			
		}
		else
		{
			types = (TypeRuntimeServer)bean;
		}
		
		if (holder instanceof Map)
		{	
			Map typesMap = (Map)holder;
			String prefix = "";
			
			
			if (typesMap.containsKey(SERVICE_RT_ID_KEY)||typesMap.containsKey(SERVICE_SRV_ID_KEY))
			{
				prefix = SERVICE_PREFIX;
			}			  	
			else
			{
				prefix = CLIENT_PREFIX;
			}
			
			String runtimeID = (String)typesMap.get(prefix+RUNTIME_ID);
			if (runtimeID != null)
				types.setRuntimeId(runtimeID);		
			
			String serverID = (String)typesMap.get(prefix+SERVER_ID);
			if (serverID  != null)				
				types.setServerId(serverID);	
			
			//check if web service type is EJB - if not, default for Java bean types
			String typeID = (String)typesMap.get(prefix+TYPE_ID);
			if (typeID != null)
			{
				if (typeID.toUpperCase().equals(TD_EJB))  //only setting typeID specifically for EJB case
				{
					types.setTypeId(TD_EJB_TYPE_ID);
				}	
				else if (typeID.toUpperCase().equals(BU_EJB))
				{
					types.setTypeId(BU_EJB_TYPE_ID);
				}	
			}			
		}
  }	
}

Back to the top