blob: fca2cb44091b9d0abe710712d652cca568021963 (
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
|
/*******************************************************************************
* Copyright (c) 2003, 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
*******************************************************************************/
package org.eclipse.jst.j2ee.internal.validation;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jem.util.logger.proxy.Logger;
import org.eclipse.jst.j2ee.application.internal.impl.ApplicationImpl;
import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive;
import org.eclipse.jst.j2ee.commonarchivecore.internal.EARFile;
import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.OpenFailureException;
import org.eclipse.jst.j2ee.componentcore.util.EARArtifactEdit;
import org.eclipse.jst.j2ee.internal.J2EEConstants;
import org.eclipse.wst.common.componentcore.ArtifactEdit;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.validation.internal.operations.WorkbenchReporter;
public class EarHelper extends J2EEValidationHelper {
protected EARFile earFile;
protected ArtifactEdit edit = null;
/**
* WarHelper constructor comment.
*/
public EarHelper() {
super();
registerModel(J2EEConstants.EAR_MODEL_NAME, "loadEarFile"); //$NON-NLS-1$
}
public String getApplicationXMLFile() {
return J2EEConstants.APPL_ID;
}
/**
* Given a resource, return its non-eclipse-specific location. If this resource, or type of
* resource, isn't handled by this helper, return null.
*/
public String getPortableName(IResource resource) {
if (!(resource instanceof IFile)) {
return null;
}
return "application.xml"; //$NON-NLS-1$
}
public String getTargetObjectName(Object obj) {
super.getTargetObjectName(obj);
if (obj != null && obj instanceof EARFile) {
return getApplicationXMLFile();
}
if (obj != null && obj instanceof ApplicationImpl) {
return "application.xml"; //$NON-NLS-1$
}
return null;
}
/**
* Get the WAR file for validation
*/
public EObject loadEarFile() {
IVirtualComponent comp = ComponentCore.createComponent(getProject());
edit = ComponentUtilities.getArtifactEditForRead(comp);
try {
Archive archive = ((EARArtifactEdit) edit).asArchive(false);
return archive;
} catch (OpenFailureException e1) {
Logger.getLogger().log(e1);
}
return null;
}
public void closeEARFile() {
if (earFile != null) {
earFile.close();
earFile = null;
}
}
public void cleanup(WorkbenchReporter reporter) {
if (edit != null) {
edit.dispose();
}
}
}
|