|
Lines 11-24
Link Here
|
| 11 |
***********************************************************************/ |
11 |
***********************************************************************/ |
| 12 |
package org.eclipse.jpt.ui.internal.wizards.entity.data.model; |
12 |
package org.eclipse.jpt.ui.internal.wizards.entity.data.model; |
| 13 |
|
13 |
|
|
|
14 |
import java.text.MessageFormat; |
| 14 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
|
|
16 |
import java.util.List; |
| 15 |
import java.util.Set; |
17 |
import java.util.Set; |
| 16 |
|
18 |
|
|
|
19 |
import org.eclipse.core.resources.IProject; |
| 17 |
import org.eclipse.core.runtime.IStatus; |
20 |
import org.eclipse.core.runtime.IStatus; |
|
|
21 |
import org.eclipse.core.runtime.Status; |
| 22 |
import org.eclipse.jdt.core.IJavaProject; |
| 23 |
import org.eclipse.jdt.core.IType; |
| 18 |
import org.eclipse.jdt.core.JavaConventions; |
24 |
import org.eclipse.jdt.core.JavaConventions; |
|
|
25 |
import org.eclipse.jdt.core.JavaCore; |
| 26 |
import org.eclipse.jdt.core.JavaModelException; |
| 27 |
import org.eclipse.jdt.core.Signature; |
| 28 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
| 29 |
import org.eclipse.jpt.ui.JptUiPlugin; |
| 19 |
import org.eclipse.jpt.ui.internal.wizards.entity.EntityWizardMsg; |
30 |
import org.eclipse.jpt.ui.internal.wizards.entity.EntityWizardMsg; |
| 20 |
import org.eclipse.jpt.ui.internal.wizards.entity.data.operation.NewEntityClassOperation; |
31 |
import org.eclipse.jpt.ui.internal.wizards.entity.data.operation.NewEntityClassOperation; |
| 21 |
import org.eclipse.jst.j2ee.internal.common.J2EECommonMessages; |
32 |
import org.eclipse.jst.j2ee.internal.common.J2EECommonMessages; |
|
|
33 |
import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties; |
| 22 |
import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider; |
34 |
import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider; |
| 23 |
import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; |
35 |
import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; |
| 24 |
import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; |
36 |
import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; |
|
Lines 170-180
Link Here
|
| 170 |
String msg = EntityWizardMsg.DUPLICATED_ENTITY_NAMES_MESSAGE; |
182 |
String msg = EntityWizardMsg.DUPLICATED_ENTITY_NAMES_MESSAGE; |
| 171 |
return WTPCommonPlugin.createErrorStatus(msg); |
183 |
return WTPCommonPlugin.createErrorStatus(msg); |
| 172 |
} |
184 |
} |
|
|
185 |
// Ensure that the entries in the list are valid |
| 186 |
String errorMsg = checkInputElementsTypeValidation(entities); |
| 187 |
if(errorMsg != null) |
| 188 |
return WTPCommonPlugin.createErrorStatus(errorMsg); |
| 189 |
String warningMsg = checkInputElementsTypeExistence(entities); |
| 190 |
if(warningMsg != null) |
| 191 |
return WTPCommonPlugin.createWarningStatus(warningMsg); |
| 192 |
|
| 173 |
} |
193 |
} |
| 174 |
// Return OK |
194 |
// Return OK |
| 175 |
return WTPCommonPlugin.OK_STATUS; |
195 |
return WTPCommonPlugin.OK_STATUS; |
| 176 |
} |
196 |
} |
| 177 |
|
197 |
|
|
|
198 |
private String checkInputElementsTypeValidation(List<EntityRow> inputElements){ |
| 199 |
IStatus validateFieldTypeStatus=Status.OK_STATUS; |
| 200 |
for(EntityRow entityRow: inputElements) { |
| 201 |
if (entityRow.getFqnTypeName().equals("")){ |
| 202 |
validateFieldTypeStatus = JavaConventions.validateFieldName(entityRow.getFqnTypeName(), CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5); |
| 203 |
break; |
| 204 |
} |
| 205 |
String sig = null; |
| 206 |
try { |
| 207 |
sig = Signature.createTypeSignature(entityRow.getFqnTypeName(),true); |
| 208 |
} catch (IllegalArgumentException e) { |
| 209 |
String message = MessageFormat.format(EntityWizardMsg.EntityDataModelProvider_invalidArgument, e.getLocalizedMessage()); |
| 210 |
validateFieldTypeStatus = new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, message); |
| 211 |
break; |
| 212 |
} |
| 213 |
if(sig == null){ |
| 214 |
validateFieldTypeStatus = JavaConventions.validateFieldName(entityRow.getType(), CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5); |
| 215 |
break; |
| 216 |
|
| 217 |
} |
| 218 |
Integer sigType = Signature.getTypeSignatureKind(sig); |
| 219 |
if(sigType == Signature.BASE_TYPE_SIGNATURE){ |
| 220 |
continue; |
| 221 |
} |
| 222 |
else if(sigType == Signature.ARRAY_TYPE_SIGNATURE) { |
| 223 |
String elementSignature = Signature.getElementType(sig); |
| 224 |
if(Signature.getTypeSignatureKind(elementSignature) == Signature.BASE_TYPE_SIGNATURE){ |
| 225 |
continue; |
| 226 |
} |
| 227 |
else { |
| 228 |
String elFullSignature = Signature.createTypeSignature(entityRow.getFqnTypeName(),true); |
| 229 |
String elSignatureType = Signature.getElementType(elFullSignature); |
| 230 |
String elSignatureTypeString = Signature.toString(elSignatureType); |
| 231 |
String elTypeSimpleName = Signature.getSimpleName(elSignatureTypeString); |
| 232 |
|
| 233 |
validateFieldTypeStatus = JavaConventions.validateFieldName(elTypeSimpleName, CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5); |
| 234 |
if(!validateFieldTypeStatus.isOK()) { |
| 235 |
break; |
| 236 |
} |
| 237 |
} |
| 238 |
} |
| 239 |
else { |
| 240 |
validateFieldTypeStatus = JavaConventions.validateFieldName(entityRow.getType(), CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5); |
| 241 |
if(!validateFieldTypeStatus.isOK()) { |
| 242 |
break; |
| 243 |
} |
| 244 |
} |
| 245 |
} |
| 246 |
if(!validateFieldTypeStatus.isOK()){ |
| 247 |
return validateFieldTypeStatus.getMessage(); |
| 248 |
} |
| 249 |
return null; |
| 250 |
} |
| 251 |
|
| 252 |
private String checkInputElementsTypeExistence(List<EntityRow> inputElements){ |
| 253 |
IStatus validateFieldTypeStatus=Status.OK_STATUS; |
| 254 |
for(EntityRow entityRow: inputElements) { |
| 255 |
|
| 256 |
String sig = Signature.createTypeSignature(entityRow.getFqnTypeName(),true); |
| 257 |
if(sig == null){ |
| 258 |
String message = MessageFormat.format( |
| 259 |
EntityWizardMsg.EntityDataModelProvider_entityNotInProjectClasspath, entityRow.getFqnTypeName()); |
| 260 |
validateFieldTypeStatus = new Status(IStatus.ERROR, |
| 261 |
JptUiPlugin.PLUGIN_ID, message); |
| 262 |
break; |
| 263 |
} |
| 264 |
Integer sigType = Signature.getTypeSignatureKind(sig); |
| 265 |
if(sigType == Signature.BASE_TYPE_SIGNATURE){ |
| 266 |
continue; |
| 267 |
} |
| 268 |
else if(sigType == Signature.ARRAY_TYPE_SIGNATURE) { |
| 269 |
String elementSignature = Signature.getElementType(sig); |
| 270 |
if(Signature.getTypeSignatureKind(elementSignature) == Signature.BASE_TYPE_SIGNATURE){ |
| 271 |
continue; |
| 272 |
} |
| 273 |
else { |
| 274 |
String qualifiedName = Signature.toString(elementSignature); |
| 275 |
IProject project = (IProject) getProperty(INewJavaClassDataModelProperties.PROJECT); |
| 276 |
IJavaProject javaProject = JavaCore.create(project); |
| 277 |
IType type=null; |
| 278 |
try { |
| 279 |
type = javaProject.findType(qualifiedName); |
| 280 |
} catch (JavaModelException e) { |
| 281 |
validateFieldTypeStatus = e.getStatus(); |
| 282 |
break; |
| 283 |
} |
| 284 |
if (type == null) { |
| 285 |
String message = MessageFormat.format( |
| 286 |
EntityWizardMsg.EntityDataModelProvider_entityNotInProjectClasspath, entityRow.getFqnTypeName()); |
| 287 |
validateFieldTypeStatus = new Status(IStatus.ERROR, |
| 288 |
JptUiPlugin.PLUGIN_ID, message); |
| 289 |
break; |
| 290 |
} |
| 291 |
} |
| 292 |
} |
| 293 |
else { |
| 294 |
IProject project = (IProject) getProperty(INewJavaClassDataModelProperties.PROJECT); |
| 295 |
IJavaProject javaProject = JavaCore.create(project); |
| 296 |
IType type=null; |
| 297 |
try { |
| 298 |
type = javaProject.findType(entityRow.getFqnTypeName()); |
| 299 |
} catch (JavaModelException e) { |
| 300 |
validateFieldTypeStatus = e.getStatus(); |
| 301 |
break; |
| 302 |
} |
| 303 |
if (type == null) { |
| 304 |
String message = MessageFormat.format( |
| 305 |
EntityWizardMsg.EntityDataModelProvider_entityNotInProjectClasspath, entityRow.getFqnTypeName()); |
| 306 |
validateFieldTypeStatus = new Status(IStatus.ERROR, |
| 307 |
JptUiPlugin.PLUGIN_ID, message); |
| 308 |
break; |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
} |
| 313 |
if(!validateFieldTypeStatus.isOK()){ |
| 314 |
return validateFieldTypeStatus.getMessage(); |
| 315 |
} |
| 316 |
return null; |
| 317 |
} |
| 318 |
|
| 319 |
|
| 178 |
/** |
320 |
/** |
| 179 |
* This method is intended for internal use only. It provides a simple algorithm for detecting |
321 |
* This method is intended for internal use only. It provides a simple algorithm for detecting |
| 180 |
* if there are duplicate entries in a list. It will accept a null parameter. It will return |
322 |
* if there are duplicate entries in a list. It will accept a null parameter. It will return |