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
|
/*******************************************************************************
* Copyright (c) 2001, 2007 Oracle 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:
* Oracle Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.jsf.validation.internal.appconfig;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jst.jsf.common.util.JDTBeanIntrospector;
import org.eclipse.jst.jsf.common.util.JDTBeanProperty;
import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
import org.eclipse.jst.jsf.facesconfig.emf.FacesConfigPackage;
import org.eclipse.jst.jsf.facesconfig.emf.PropertyNameType;
/**
* Validates property's
*
*/
public class PropertyValidationVisitor extends EObjectValidationVisitor
{
private final EStructuralFeature _parentClassName;
/**
* @param feature
* @param parentClassName
* @param version
*/
public PropertyValidationVisitor(EStructuralFeature feature, EStructuralFeature parentClassName, String version) {
// this validator can be attached to numerous parents so it
// cannot hard-code its feature
super(feature,version);
_parentClassName = parentClassName;
}
protected void doValidate(EObject object, List messages, IFile file) {
// validate the class type here because we need knowledge
// of the property name to do it
//TODO:
// final PropertyType property = (PropertyType) object;
// final String propertyClass =
// property.getPropertyClass().getTextContent();
// final String propertySignature =
// validateProperty(property.getPropertyName()
// , file.getProject(), _parentClassType);
//
// if (propertySignature != null
// && Signature.)
// {
// Signature.create
// }
}
protected EObjectValidationVisitor[] getChildNodeValidators() {
return new EObjectValidationVisitor[]
{
new PropertyNameValidationVisitor(FacesConfigPackage.eINSTANCE.getPropertyType_PropertyName(),
_parentClassName, getVersion())
};
}
static String validateProperty(PropertyNameType object, IProject project, String parentClassType)
{
String signatureBeanProperty = null;
try
{
IJavaProject javaProject = JavaCore.create(project);
IType type = javaProject.findType(parentClassType);
if (type != null)
{
final JDTBeanIntrospector introspector =
new JDTBeanIntrospector(type);
final Map properties = introspector.getProperties();
final String propertyName = object.getTextContent();
if (properties.containsKey(propertyName))
{
final JDTBeanProperty beanProperty =
(JDTBeanProperty) properties.get(propertyName);
signatureBeanProperty =
beanProperty.getTypeSignature();
}
}
}
catch(JavaModelException jme)
{
JSFCorePlugin
.log(new Exception(jme),
"Problem validating on parent: "+parentClassType); //$NON-NLS-1$
}
return signatureBeanProperty;
}
}
|