-
Notifications
You must be signed in to change notification settings - Fork 604
/
Copy pathWebAppEntryAdapter.java
68 lines (58 loc) · 2.73 KB
/
WebAppEntryAdapter.java
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
/*******************************************************************************
* Copyright (c) 2011, 2015 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 com.ibm.ws.javaee.ddmodel.web;
import org.osgi.framework.ServiceReference;
import com.ibm.ws.ffdc.annotation.FFDCIgnore;
import com.ibm.ws.javaee.dd.web.WebApp;
import com.ibm.ws.javaee.ddmodel.DDParser.ParseException;
import com.ibm.ws.javaee.version.ServletVersion;
import com.ibm.wsspi.adaptable.module.Container;
import com.ibm.wsspi.adaptable.module.Entry;
import com.ibm.wsspi.adaptable.module.UnableToAdaptException;
import com.ibm.wsspi.adaptable.module.adapters.EntryAdapter;
import com.ibm.wsspi.artifact.ArtifactEntry;
import com.ibm.wsspi.artifact.overlay.OverlayContainer;
public final class WebAppEntryAdapter implements EntryAdapter<WebApp> {
private static final int DEFAULT_MAX_VERSION = WebApp.VERSION_3_0;
private ServiceReference<ServletVersion> versionRef;
private volatile int maxVersion = DEFAULT_MAX_VERSION;
public synchronized void setVersion(ServiceReference<ServletVersion> versionRef) {
this.versionRef = versionRef;
Integer maxVersionValue = (Integer) versionRef.getProperty("version");
maxVersion = maxVersionValue.intValue();
}
public synchronized void unsetVersion(ServiceReference<ServletVersion> versionRef) {
if ( versionRef == this.versionRef ) {
this.versionRef = null;
this.maxVersion = DEFAULT_MAX_VERSION;
}
}
@FFDCIgnore(ParseException.class)
@Override
public WebApp adapt(
Container rawContainer,
OverlayContainer container,
ArtifactEntry rawWebAppEntry,
Entry webAppEntry) throws UnableToAdaptException {
String webAppPath = rawWebAppEntry.getPath();
WebApp webAppDD = (WebApp) container.getFromNonPersistentCache(webAppPath, WebApp.class);
if ( webAppDD == null ) {
try {
WebAppDDParser webAppDDParser = new WebAppDDParser(rawContainer, webAppEntry, maxVersion); // throws ParseException
webAppDD = webAppDDParser.parse(); // throws ParseException
} catch ( ParseException e ) {
throw new UnableToAdaptException(e);
}
container.addToNonPersistentCache(webAppPath, WebApp.class, webAppDD);
}
return webAppDD;
}
}