-
Notifications
You must be signed in to change notification settings - Fork 138
/
WebBundleDescriptor.java
1556 lines (1244 loc) · 48.5 KB
/
WebBundleDescriptor.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.enterprise.deployment;
import com.sun.enterprise.deployment.runtime.web.SunWebApp;
import com.sun.enterprise.deployment.types.EjbReferenceContainer;
import com.sun.enterprise.deployment.types.MessageDestinationReferenceContainer;
import com.sun.enterprise.deployment.types.ResourceEnvReferenceContainer;
import com.sun.enterprise.deployment.types.ResourceReferenceContainer;
import com.sun.enterprise.deployment.types.ServiceReferenceContainer;
import com.sun.enterprise.deployment.util.DOLUtils;
import com.sun.enterprise.deployment.web.AppListenerDescriptor;
import com.sun.enterprise.deployment.web.ContextParameter;
import com.sun.enterprise.deployment.web.LoginConfiguration;
import com.sun.enterprise.deployment.web.MimeMapping;
import com.sun.enterprise.deployment.web.ResourceReference;
import com.sun.enterprise.deployment.web.SecurityConstraint;
import com.sun.enterprise.deployment.web.SecurityRole;
import com.sun.enterprise.deployment.web.SecurityRoleReference;
import com.sun.enterprise.deployment.web.ServletFilter;
import com.sun.enterprise.deployment.web.ServletFilterMapping;
import com.sun.enterprise.deployment.web.SessionConfig;
import com.sun.enterprise.deployment.web.WebResourceCollection;
import jakarta.servlet.ServletContextListener;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.glassfish.api.deployment.archive.ArchiveType;
import org.glassfish.api.event.EventTypes;
import org.glassfish.deployment.common.Descriptor;
import org.glassfish.grizzly.http.util.MimeType;
import org.glassfish.security.common.Role;
/**
* I am an object that represents all the deployment information about a web application.
*
* @author Danny Coward
*/
public abstract class WebBundleDescriptor extends CommonResourceBundleDescriptor
implements WritableJndiNameEnvironment, ResourceReferenceContainer, ResourceEnvReferenceContainer,
EjbReferenceContainer, MessageDestinationReferenceContainer, ServiceReferenceContainer {
private static final long serialVersionUID = 5599255661969873669L;
private static final String DEPLOYMENT_DESCRIPTOR_DIR = "WEB-INF";
/** Used by the deployer and the web container */
public static final EventTypes<WebBundleDescriptor> AFTER_SERVLET_CONTEXT_INITIALIZED_EVENT = EventTypes
.create("After_Servlet_Context_Initialized", WebBundleDescriptor.class);
private String contextRoot;
private boolean denyUncoveredHttpMethods;
private boolean distributable;
private LocaleEncodingMappingListDescriptor localeEncodingMappingListDesc;
private LoginConfiguration loginConfiguration;
private String requestCharacterEncoding;
private String responseCharacterEncoding;
private SessionConfig sessionConfig;
private boolean showArchivedRealPathEnabled = true;
private JspConfigDefinitionDescriptor jspConfigDescriptor = new JspConfigDefinitionDescriptor();
/**
* An entry here, may be set to indicate additional processing.
* This entry may be set, for example, by a Deployer.
*/
private final Map<String, String> extensionProperty = new HashMap<>(4);
private final List<AppListenerDescriptor> appListenerDescriptors = new ArrayList<>();
private final Set<ContextParameter> contextParameters = new OrderedSet<>();
private final Set<EjbReferenceDescriptor> ejbReferences = new OrderedSet<>();
private final Set<EntityManagerFactoryReferenceDescriptor> entityManagerFactoryReferences = new HashSet<>();
private final Set<EntityManagerReferenceDescriptor> entityManagerReferences = new HashSet<>();
private final Set<EnvironmentProperty> environmentEntries = new OrderedSet<>();
private final Set<ErrorPageDescriptor> errorPageDescriptors = new HashSet<>();
private final Map<String, String> jarName2WebFragNameMap = new HashMap<>();
private final Set<MessageDestinationReferenceDescriptor> messageDestReferences = new OrderedSet<>();
private final Set<MimeMapping> mimeMappings = new OrderedSet<>();
private final List<String> orderedLibs = new ArrayList<>();
private final Set<LifecycleCallbackDescriptor> postConstructDescs = new HashSet<>();
private final Set<LifecycleCallbackDescriptor> preDestroyDescs = new HashSet<>();
private final Set<ResourceEnvReferenceDescriptor> resourceEnvRefReferences = new OrderedSet<>();
private final Set<ResourceReferenceDescriptor> resourceReferences = new OrderedSet<>();
private final Set<SecurityConstraint> securityConstraints = new HashSet<>();
private final Set<ServiceReferenceDescriptor> serviceReferences = new OrderedSet<>();
private final List<ServletFilter> servletFilters = new ArrayList<>();
private final List<ServletFilterMapping> servletFilterMappings = new ArrayList<>();
private final Set<WebComponentDescriptor> webComponentDescriptors = new OrderedSet<>();
private final Set<String> welcomeFiles = new OrderedSet<>();
/** this is for checking whether there are more than one servlets for a given url-pattern */
private Map<String, String> urlPattern2ServletName;
/**
* Add JNDI entries of the provided {@link JndiNameEnvironment} to this descriptor.
* The implementation decides what entries are relevant and how to process them.
* <p>
* This method can be used ie by an EJB descriptor.
*
* @param env
*/
public abstract void addJndiNameEnvironment(JndiNameEnvironment env);
/**
* Combine all except welcome file set for two webBundleDescriptors.
*
* @param descriptor full default descriptor or a fragment
* @param descriptorFragment true if the descriptor is just a fragment
*/
protected abstract void addCommonWebBundleDescriptor(WebBundleDescriptor descriptor, boolean descriptorFragment);
/**
* Merge the contents of this and given descriptor.
*
* @param webBundleDescriptor
*/
public void addWebBundleDescriptor(WebBundleDescriptor webBundleDescriptor) {
addWelcomeFiles(webBundleDescriptor.getWelcomeFilesSet());
addCommonWebBundleDescriptor(webBundleDescriptor, true);
}
/**
* Merge the contents of this and given descriptor.
*
* @param descriptor
*/
public void addDefaultWebBundleDescriptor(WebBundleDescriptor descriptor) {
if (getWelcomeFilesSet().isEmpty()) {
addWelcomeFiles(descriptor.getWelcomeFilesSet());
}
if (this.requestCharacterEncoding == null) {
this.requestCharacterEncoding = descriptor.getRequestCharacterEncoding();
}
if (this.responseCharacterEncoding == null) {
this.responseCharacterEncoding = descriptor.getResponseCharacterEncoding();
}
addCommonWebBundleDescriptor(descriptor, false);
}
@Override
public String getDeploymentDescriptorDir() {
return DEPLOYMENT_DESCRIPTOR_DIR;
}
@Override
public final ArchiveType getModuleType() {
return DOLUtils.warType();
}
@Override
public boolean isEmpty() {
return webComponentDescriptors == null || webComponentDescriptors.isEmpty();
}
/**
* @return relative context of the web application
*/
public String getContextRoot() {
if (getModuleDescriptor() != null && getModuleDescriptor().getContextRoot() != null) {
return getModuleDescriptor().getContextRoot();
}
if (contextRoot == null) {
contextRoot = "";
}
return contextRoot;
}
/**
* @param contextRoot relative context of the web application
*/
public void setContextRoot(String contextRoot) {
if (getModuleDescriptor() != null) {
getModuleDescriptor().setContextRoot(contextRoot);
}
this.contextRoot = contextRoot;
}
/**
* @return true to deny access to methods not covered by authorization rules.
*/
public boolean isDenyUncoveredHttpMethods() {
return denyUncoveredHttpMethods;
}
/**
* @param denyUncoveredHttpMethods true to deny access to methods not covered by authorization rules.
*/
public void setDenyUncoveredHttpMethods(boolean denyUncoveredHttpMethods) {
this.denyUncoveredHttpMethods = denyUncoveredHttpMethods;
}
/**
* @return true if this web app [{0}] can be distributed across different processes.
*/
public boolean isDistributable() {
return distributable;
}
/**
* Sets whether this web app [{0}] can be distributed across different processes.
*
* @param distributable true if allowed
*/
public void setDistributable(boolean distributable) {
this.distributable = distributable;
}
/**
* @return Mapping of locales and encoding charsets
*/
public LocaleEncodingMappingListDescriptor getLocaleEncodingMappingListDescriptor() {
return localeEncodingMappingListDesc;
}
/**
* @param lemListDesc Mapping of locales and encoding charsets
*/
public void setLocaleEncodingMappingListDescriptor(LocaleEncodingMappingListDescriptor lemListDesc) {
localeEncodingMappingListDesc = lemListDesc;
}
/**
* @param lemDesc Mapping of locale and encoding charset
*/
public void addLocaleEncodingMappingDescriptor(LocaleEncodingMappingDescriptor lemDesc) {
if (localeEncodingMappingListDesc == null) {
localeEncodingMappingListDesc = new LocaleEncodingMappingListDescriptor();
}
localeEncodingMappingListDesc.addLocaleEncodingMapping(lemDesc);
}
/**
* @return {@link LoginConfiguration}
*/
public LoginConfiguration getLoginConfiguration() {
return loginConfiguration;
}
/**
* @param loginConfiguration Specifies the information about authentication.
*/
public void setLoginConfiguration(LoginConfiguration loginConfiguration) {
this.loginConfiguration = loginConfiguration;
}
/**
* @return the request encoding (charset)
*/
public String getRequestCharacterEncoding() {
return this.requestCharacterEncoding;
}
/**
* @param requestCharacterEncoding request encoding (charset)
*/
public void setRequestCharacterEncoding(String requestCharacterEncoding) {
this.requestCharacterEncoding = requestCharacterEncoding;
}
/**
* @return the response encoding (charset)
*/
public String getResponseCharacterEncoding() {
return this.responseCharacterEncoding;
}
/**
* @param responseCharacterEncoding response encoding (charset)
*/
public void setResponseCharacterEncoding(String responseCharacterEncoding) {
this.responseCharacterEncoding = responseCharacterEncoding;
}
/**
* @return configuration related to sessions
*/
public SessionConfig getSessionConfig() {
return sessionConfig;
}
/**
* @param sessionConfig configuration related to sessions
*/
public void setSessionConfig(SessionConfig sessionConfig) {
this.sessionConfig = sessionConfig;
}
/**
* @return false to return null instead of real paths in cookies etc. Default is true.
*/
public boolean isShowArchivedRealPathEnabled() {
return showArchivedRealPathEnabled;
}
/**
* @param enabled false to return null instead of real paths in cookies etc. Default is true.
*/
public void setShowArchivedRealPathEnabled(boolean enabled) {
showArchivedRealPathEnabled = enabled;
}
/**
* @param descriptor JSP related configuration
*/
public void addJspDescriptor(JspConfigDefinitionDescriptor descriptor) {
jspConfigDescriptor.add(descriptor);
}
/**
* @return {@link Set} of jsps.
*/
public Set<WebComponentDescriptor> getJspDescriptors() {
Set<WebComponentDescriptor> jspDescriptors = new HashSet<>();
for (WebComponentDescriptor webComponent : getWebComponentDescriptors()) {
if (!webComponent.isServlet()) {
jspDescriptors.add(webComponent);
}
}
return jspDescriptors;
}
/**
* @return JSP related configuration
*/
public JspConfigDefinitionDescriptor getJspConfigDescriptor() {
return jspConfigDescriptor;
}
/**
* @param descriptor JSP related configuration
*/
public void setJspConfigDescriptor(JspConfigDefinitionDescriptor descriptor) {
jspConfigDescriptor = descriptor;
}
/**
* This property can be used to indicate a special processing to an extension.
* For example, a Deployer may set this property.
*
* @param key non-null key, see extension's documentation.
* @param value
*/
public void setExtensionProperty(String key, String value) {
extensionProperty.put(key, value);
}
/**
* Determine if an extension property has been set. Case sensitive.
*
* @param key can be null, but then returns false.
* @return true if the key is present.
*/
public boolean hasExtensionProperty(String key) {
return extensionProperty != null && extensionProperty.containsKey(key);
}
/**
* @return unmodifiable copy of the list of {@link AppListenerDescriptor}s to use
* {@link ServletContextListener}s
*/
public List<AppListenerDescriptor> getAppListenersCopy() {
return List.copyOf(getAppListeners());
}
/**
* @return list of {@link AppListenerDescriptor}s to use {@link ServletContextListener}s
*/
public List<AppListenerDescriptor> getAppListeners() {
return appListenerDescriptors;
}
/**
* Clears the current list and adds all from the provided parameter.
*
* @param listeners list of {@link AppListenerDescriptor}s to use {@link ServletContextListener}s
*/
public void setAppListeners(Collection<? extends AppListenerDescriptor> listeners) {
this.appListenerDescriptors.clear();
addAppListeners(listeners);
}
/**
* @param listeners list of {@link AppListenerDescriptor}s to use {@link ServletContextListener}s
*/
public void addAppListeners(Collection<? extends AppListenerDescriptor> listeners) {
this.appListenerDescriptors.addAll(listeners);
}
/**
* Adds the listener as the last one if it is not already present.
*
* @param descriptor descriptor for a {@link ServletContextListener}.
*/
public void addAppListenerDescriptor(AppListenerDescriptor descriptor) {
if (!this.appListenerDescriptors.contains(descriptor)) {
this.appListenerDescriptors.add(descriptor);
}
}
/**
* Adds the listener as the first one if it is not already present.
*
* @param descriptor descriptor for a {@link ServletContextListener}.
*/
public void addAppListenerDescriptorToFirst(AppListenerDescriptor descriptor) {
if (!this.appListenerDescriptors.contains(descriptor)) {
this.appListenerDescriptors.add(0, descriptor);
}
}
/**
* @return the Set of my Context Parameters.
*/
public Set<ContextParameter> getContextParametersSet() {
return contextParameters;
}
/**
* Adds all context parameters to my list.
*/
public void addContextParameters(Collection<ContextParameter> contextParameters) {
this.contextParameters.addAll(contextParameters);
}
/**
* Adds a new context parameter to my list.
*/
public void addContextParameter(ContextParameter contextParameter) {
contextParameters.add(contextParameter);
}
/**
* Removes the given context parameter from my list.
*/
public void removeContextParameter(ContextParameter contextParameter) {
contextParameters.remove(contextParameter);
}
/**
* @return the enumeration of my references to Enterprise Beans.
*/
public final Enumeration<EjbReferenceDescriptor> getEjbReferences() {
return Collections.enumeration(getEjbReferenceDescriptors());
}
@Override
public Set<EjbReferenceDescriptor> getEjbReferenceDescriptors() {
return ejbReferences;
}
/**
* @return {@link EjbReferenceDescriptor} with the matching name or throw.
*/
public EjbReferenceDescriptor getEjbReferenceByName(String name) {
return getEjbReference(name);
}
@Override
public EjbReferenceDescriptor getEjbReference(String name) {
EjbReferenceDescriptor er = findEjbReference(name);
if (er != null) {
return er;
}
throw new IllegalArgumentException(
MessageFormat.format("This web app [{0}] has no ejb reference by the name of [{1}] ", getName(), name));
}
/**
* @param name
* @return null or {@link EjbReferenceDescriptor} found by the name. Case sensitive.
*/
protected EjbReferenceDescriptor findEjbReference(String name) {
for (EjbReferenceDescriptor er : ejbReferences) {
if (er.getName().equals(name)) {
return er;
}
}
return null;
}
@Override
public void addEjbReferenceDescriptor(EjbReferenceDescriptor ejbReference) {
if (ejbReferences.add(ejbReference)) {
ejbReference.setReferringBundleDescriptor(this);
}
}
@Override
public void removeEjbReferenceDescriptor(EjbReferenceDescriptor ejbReferenceDescriptor) {
if (ejbReferences.remove(ejbReferenceDescriptor)) {
ejbReferenceDescriptor.setReferringBundleDescriptor(null);
}
}
@Override
public Set<EntityManagerFactoryReferenceDescriptor> getEntityManagerFactoryReferenceDescriptors() {
return entityManagerFactoryReferences;
}
@Override
public EntityManagerFactoryReferenceDescriptor getEntityManagerFactoryReferenceByName(String name) {
EntityManagerFactoryReferenceDescriptor emfr = findEntityManagerFactoryReferenceByName(name);
if (emfr != null) {
return emfr;
}
throw new IllegalArgumentException(MessageFormat.format(
"This web app [{0}] has no entity manager factory reference by the name of [{1}]", getName(), name));
}
/**
* Case sensitive search.
*
* @param name
* @return null or {@link EntityManagerFactoryReferenceDescriptor} found by the name.
*/
protected EntityManagerFactoryReferenceDescriptor findEntityManagerFactoryReferenceByName(String name) {
for (EntityManagerFactoryReferenceDescriptor next : entityManagerFactoryReferences) {
if (next.getName().equals(name)) {
return next;
}
}
return null;
}
@Override
public void addEntityManagerFactoryReferenceDescriptor(EntityManagerFactoryReferenceDescriptor reference) {
reference.setReferringBundleDescriptor(this);
this.entityManagerFactoryReferences.add(reference);
}
@Override
public Set<EntityManagerReferenceDescriptor> getEntityManagerReferenceDescriptors() {
return entityManagerReferences;
}
@Override
public EntityManagerReferenceDescriptor getEntityManagerReferenceByName(String name) {
EntityManagerReferenceDescriptor emr = findEntityManagerReferenceByName(name);
if (emr != null) {
return emr;
}
throw new IllegalArgumentException(MessageFormat
.format("This web app [{0}] has no entity manager reference by the name of [{1}]", getName(), name));
}
protected EntityManagerReferenceDescriptor findEntityManagerReferenceByName(String name) {
for (EntityManagerReferenceDescriptor next : entityManagerReferences) {
if (next.getName().equals(name)) {
return next;
}
}
return null;
}
@Override
public void addEntityManagerReferenceDescriptor(EntityManagerReferenceDescriptor reference) {
reference.setReferringBundleDescriptor(this);
entityManagerReferences.add(reference);
}
/**
* @return enumeration of {@link EnvironmentProperty}, must not be null but may be empty.
*/
public final Enumeration<EnvironmentProperty> getEnvironmentEntries() {
return Collections.enumeration(getEnvironmentEntrySet());
}
@Override
public Set<EnvironmentProperty> getEnvironmentProperties() {
return getEnvironmentEntrySet();
}
/**
* @return {@link Set} of {@link EnvironmentProperty}, must not be null but may be empty.
*/
public Set<EnvironmentProperty> getEnvironmentEntrySet() {
return environmentEntries;
}
@Override
public EnvironmentProperty getEnvironmentPropertyByName(String name) {
EnvironmentProperty entry = findEnvironmentEntryByName(name);
if (entry != null) {
return entry;
}
throw new IllegalArgumentException(MessageFormat
.format("This web app [{0}] has no environment property by the name of [{1}]", getName(), name));
}
/**
* @param name
* @return null or {@link EnvironmentProperty} found by the name. Case sensitive.
*/
protected EnvironmentProperty findEnvironmentEntryByName(String name) {
for (EnvironmentProperty ev : getEnvironmentEntrySet()) {
if (ev.getName().equals(name)) {
return ev;
}
}
return null;
}
@Override
public void addEnvironmentProperty(EnvironmentProperty environmentProperty) {
addEnvironmentEntry(environmentProperty);
}
/**
* Adds this given environment property to my list.
*/
public void addEnvironmentEntry(EnvironmentProperty environmentEntry) {
environmentEntries.add(environmentEntry);
}
@Override
public void removeEnvironmentProperty(EnvironmentProperty environmentProperty) {
removeEnvironmentEntry(environmentProperty);
}
/**
* Removes this given environment property from my list.
*/
public void removeEnvironmentEntry(EnvironmentProperty environmentEntry) {
environmentEntries.remove(environmentEntry);
}
/**
* @return an enumeration of the error pages I have.
*/
public Enumeration<ErrorPageDescriptor> getErrorPageDescriptors() {
return Collections.enumeration(getErrorPageDescriptorsSet());
}
public Set<ErrorPageDescriptor> getErrorPageDescriptorsSet() {
return errorPageDescriptors;
}
/**
* Adds a new error page to my list.
*/
public void addErrorPageDescriptor(ErrorPageDescriptor errorPageDescriptor) {
String errorSignifier = errorPageDescriptor.getErrorSignifierAsString();
ErrorPageDescriptor errPageDesc = getErrorPageDescriptorBySignifier(errorSignifier);
if (errPageDesc == null) {
errorPageDescriptors.add(errorPageDescriptor);
}
}
/**
* Search my error pages for one with thei given signifier or null if there isn't one.
* Case sensitive.
*
* @return {@link ErrorPageDescriptor} or null
*/
private ErrorPageDescriptor getErrorPageDescriptorBySignifier(String signifier) {
for (ErrorPageDescriptor next : getErrorPageDescriptorsSet()) {
if (next.getErrorSignifierAsString().equals(signifier)) {
return next;
}
}
return null;
}
/**
* Removes the given error page from my list.
*/
public void removeErrorPageDescriptor(ErrorPageDescriptor errorPageDescriptor) {
errorPageDescriptors.remove(errorPageDescriptor);
}
/**
* This method return an unmodifiable map of jarName2WebFragNameMap.
*
* @return unmodifiable {@link Map}
*/
public Map<String, String> getJarNameToWebFragmentNameMap() {
return Collections.unmodifiableMap(jarName2WebFragNameMap);
}
public void putJarNameWebFragmentNamePair(String jarName, String webFragName) {
jarName2WebFragNameMap.put(jarName, webFragName);
}
@Override
public Set<MessageDestinationReferenceDescriptor> getMessageDestinationReferenceDescriptors() {
return messageDestReferences;
}
@Override
public MessageDestinationReferenceDescriptor getMessageDestinationReferenceByName(String name) {
MessageDestinationReferenceDescriptor mdr = findMessageDestinationReferenceByName(name);
if (mdr != null) {
return mdr;
}
throw new IllegalArgumentException(MessageFormat
.format("This web app [{0}] has no message destination reference by the name of [{1}]", getName(), name));
}
protected MessageDestinationReferenceDescriptor findMessageDestinationReferenceByName(String name) {
for (MessageDestinationReferenceDescriptor mdr : messageDestReferences) {
if (mdr.getName().equals(name)) {
return mdr;
}
}
return null;
}
@Override
public void addMessageDestinationReferenceDescriptor(MessageDestinationReferenceDescriptor messageDestRef) {
messageDestRef.setReferringBundleDescriptor(this);
messageDestReferences.add(messageDestRef);
}
@Override
public void removeMessageDestinationReferenceDescriptor(MessageDestinationReferenceDescriptor msgDestRef) {
messageDestReferences.remove(msgDestRef);
}
/**
* @return an enumeration of my mime mappings.
*/
public Enumeration<MimeMapping> getMimeMappings() {
return Collections.enumeration(getMimeMappingsSet());
}
public Set<MimeMapping> getMimeMappingsSet() {
return mimeMappings;
}
/**
* Add the given mime mapping to my list if the given MimeType is not added
*
* @return the result {@link MimeType} of the {@link MimeMapping} in the resulting
* set of MimeMapping
*/
public String addMimeMapping(MimeMapping mimeMapping) {
// there should be at most one mapping per extension
MimeMapping resultMimeMapping = null;
for (MimeMapping mm : mimeMappings) {
if (mm.getExtension().equals(mimeMapping.getExtension())) {
resultMimeMapping = mm;
break;
}
}
if (resultMimeMapping == null) {
resultMimeMapping = mimeMapping;
this.mimeMappings.add(mimeMapping);
}
return resultMimeMapping.getMimeType();
}
/**
* Removes the given mime mapping from my list.
*/
public void removeMimeMapping(MimeMapping mimeMapping) {
mimeMappings.remove(mimeMapping);
}
public List<String> getOrderedLibs() {
return orderedLibs;
}
public void addOrderedLib(String libName) {
orderedLibs.add(libName);
}
@Override
public Set<LifecycleCallbackDescriptor> getPostConstructDescriptors() {
return postConstructDescs;
}
@Override
public LifecycleCallbackDescriptor getPostConstructDescriptorByClass(String className) {
return getPostConstructDescriptorByClass(className, this);
}
@Override
public void addPostConstructDescriptor(LifecycleCallbackDescriptor postConstructDesc) {
String className = postConstructDesc.getLifecycleCallbackClass();
boolean found = false;
for (LifecycleCallbackDescriptor next : postConstructDescs) {
if (next.getLifecycleCallbackClass().equals(className)) {
found = true;
break;
}
}
if (!found) {
postConstructDescs.add(postConstructDesc);
}
}
@Override
public Set<LifecycleCallbackDescriptor> getPreDestroyDescriptors() {
return preDestroyDescs;
}
@Override
public LifecycleCallbackDescriptor getPreDestroyDescriptorByClass(String className) {
return getPreDestroyDescriptorByClass(className, this);
}
@Override
public void addPreDestroyDescriptor(LifecycleCallbackDescriptor preDestroyDesc) {
String className = preDestroyDesc.getLifecycleCallbackClass();
boolean found = false;
for (LifecycleCallbackDescriptor next : preDestroyDescs) {
if (next.getLifecycleCallbackClass().equals(className)) {
found = true;
break;
}
}
if (!found) {
preDestroyDescs.add(preDestroyDesc);
}
}
@Override
public Set<ResourceEnvReferenceDescriptor> getResourceEnvReferenceDescriptors() {
return resourceEnvRefReferences;
}
@Override
public ResourceEnvReferenceDescriptor getResourceEnvReferenceByName(String name) {
ResourceEnvReferenceDescriptor jrd = findResourceEnvReferenceByName(name);
if (jrd != null) {
return jrd;
}
throw new IllegalArgumentException(MessageFormat
.format("This web app [{0}] has no resource environment reference by the name of [{1}]", getName(), name));
}
protected ResourceEnvReferenceDescriptor findResourceEnvReferenceByName(String name) {
for (ResourceEnvReferenceDescriptor jdr : resourceEnvRefReferences) {
if (jdr.getName().equals(name)) {
return jdr;
}
}
return null;
}
@Override
public void addResourceEnvReferenceDescriptor(ResourceEnvReferenceDescriptor resourceEnvRefReference) {
resourceEnvRefReferences.add(resourceEnvRefReference);
}
@Override
public void removeResourceEnvReferenceDescriptor(ResourceEnvReferenceDescriptor resourceEnvRefReference) {
resourceEnvRefReferences.remove(resourceEnvRefReference);
}
public Enumeration<ResourceReferenceDescriptor> getResourceReferences() {
return Collections.enumeration(getResourceReferenceDescriptors());
}
@Override
public Set<ResourceReferenceDescriptor> getResourceReferenceDescriptors() {
return resourceReferences;
}
@Override
public ResourceReferenceDescriptor getResourceReferenceByName(String name) {
ResourceReferenceDescriptor rrd = findResourceReferenceByName(name);
if (rrd != null) {
return rrd;
}
throw new IllegalArgumentException(
MessageFormat.format("This web app [{0}] has no resource reference by the name of [{1}]", getName(), name));
}
protected ResourceReferenceDescriptor findResourceReferenceByName(String name) {
for (ResourceReference next : resourceReferences) {
if (next.getName().equals(name)) {
return (ResourceReferenceDescriptor) next;
}
}