blob: 337fe22d7e8c88393d947ea6d4ac24dab8452a97 (
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
|
/*******************************************************************************
* Copyright (c) 2004, 2006 Sybase, Inc. 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:
* Sybase, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.jsf.facesconfig.ui.util;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.jst.jsf.core.jsfappconfig.internal.IJSFAppConfigManager;
import org.eclipse.jst.jsf.core.jsfappconfig.internal.JSFAppConfigManagerFactory;
import org.eclipse.jst.jsf.facesconfig.emf.ManagedBeanType;
/**
*
* @author sfshi
*
*/
public class ManagedBeanUtil {
/**
* Determines if the new bean to be added is already a member of the
* configuration set.
* @param project
*
* @param beanName -
* The name of the bean being added
* @return int - 0 if bean doesn't exist, otherwise the choice from the
* Duplicate Bean dialog
*/
public static boolean isBeanDuplicate(final IProject project, final String beanName)
{
final IJSFAppConfigManager appCfgMgr = JSFAppConfigManagerFactory.getJSFAppConfigManagerInstance(project);
if (appCfgMgr != null)
{
final List<ManagedBeanType> beans = appCfgMgr.getManagedBeans();
// Iterate through the bean list
for (final ManagedBeanType mbti : beans) {
if (mbti.getManagedBeanName() != null) {
final String name = mbti.getManagedBeanName()
.getTextContent();
if (name != null && name.equals(beanName)) {
return true;
}
}
}
}
return false;
}
/**
* get the default managed bean name in the current project according to
* reference name
*
* @param project -
* current project
* @param refName -
* seed reference name
* @return String - default managed bean name
*/
public static String getDefaultManagedBeanName(final IProject project,
final String refName) {
String defaultName = refName;
int newRefNameIndex = 1;
while (isBeanDuplicate(project, defaultName)) {
defaultName = refName + newRefNameIndex;
newRefNameIndex++;
}
return defaultName;
}
}
|