-
Notifications
You must be signed in to change notification settings - Fork 138
/
Application.java
1598 lines (1339 loc) · 52.1 KB
/
Application.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, 2020 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.node.ApplicationNode;
import com.sun.enterprise.deployment.runtime.application.wls.ApplicationParam;
import com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping;
import com.sun.enterprise.deployment.runtime.common.wls.SecurityRoleAssignment;
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.RoleMappingContainer;
import com.sun.enterprise.deployment.types.ServiceReferenceContainer;
import com.sun.enterprise.deployment.util.ApplicationVisitor;
import com.sun.enterprise.deployment.util.ComponentVisitor;
import com.sun.enterprise.deployment.util.DOLUtils;
import com.sun.enterprise.util.LocalStringManagerImpl;
import jakarta.inject.Inject;
import jakarta.persistence.EntityManagerFactory;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.glassfish.api.deployment.archive.ArchiveType;
import org.glassfish.deployment.common.DescriptorVisitor;
import org.glassfish.deployment.common.ModuleDescriptor;
import org.glassfish.deployment.common.RootDeploymentDescriptor;
import org.glassfish.deployment.common.SecurityRoleMapper;
import org.glassfish.deployment.common.SecurityRoleMapperFactory;
import org.glassfish.deployment.versioning.VersioningUtils;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.internal.api.Globals;
import org.glassfish.security.common.Role;
import org.jvnet.hk2.annotations.Optional;
/**
* Objects of this type encapsulate the data and behaviour of a JEE application.
*
* @author Danny Coward
*/
public class Application extends CommonResourceBundleDescriptor
implements RoleMappingContainer, WritableJndiNameEnvironment,
EjbReferenceContainer, ResourceEnvReferenceContainer,
ResourceReferenceContainer, ServiceReferenceContainer,
MessageDestinationReferenceContainer {
private static final long serialVersionUID = 1L;
private static final Logger LOG = DOLUtils.getDefaultLogger();
private static final LocalStringManagerImpl I18N = new LocalStringManagerImpl(Application.class);
/**
* default value for the library-directory element
*/
private static final String LIBRARY_DIRECTORY_DEFAULT_VALUE = "lib";
private static final String PERSISTENCE_UNIT_NAME_SEPARATOR = "#";
/**
* Store generated XML dir to be able to get the generated WSDL
*/
private String generatedXMLDir;
// Set of modules in this application
private final Set<ModuleDescriptor<BundleDescriptor>> modules = new OrderedSet<>();
// True if unique id has been set. Allows callers to avoid
// applying unique ids to subcomponents multiple times.
private boolean uniqueIdSet;
// IASRI 4645310
/**
* unique id for this application
*/
private long uniqueId;
/**
* represents the virtual status of this application object
*/
private boolean virtual;
/**
* represents whether all ejb modules in an application will be pass by
* value or pass by reference
*/
private Boolean passByReference;
// flag to indicate that the memory representation of this application
// is not in sync with the disk representation
private boolean isDirty;
// data structure to map roles to users and groups
private transient SecurityRoleMapper roleMapper;
/**
* name used to register this application
*/
private String registrationName;
private String appName;
private String archiveName;
private String compatValue;
private boolean initializeInOrder;
// realm associated with this application
private String realm;
@Inject
@Optional
private transient SecurityRoleMapperFactory securityRoleMapperFactory;
/**
* A flag to store the resolved keepstate value for the current application.
* See org.glassfish.ejb.startup.EjbApplication for details. This value
* may be different from super.keepState.
*/
private boolean keepStateResolved;
// Physical entity manager factory corresponding to the unit name of
// each application-level persistence unit. Only available at runtime.
private transient Map<String, EntityManagerFactory> entityManagerFactories = new HashMap<>();
private final Set<String> entityManagerFactoryUnitNames = new HashSet<>();
// the jndi environment entries
private final Set<EnvironmentProperty> environmentProperties = new HashSet<>();
private final Set<EjbReferenceDescriptor> ejbReferences = new HashSet<>();
private final Set<ResourceEnvReferenceDescriptor> resourceEnvReferences = new HashSet<>();
private final Set<MessageDestinationReferenceDescriptor> messageDestReferences = new HashSet<>();
private final Set<ResourceReferenceDescriptor> resourceReferences = new HashSet<>();
private final Set<ServiceReferenceDescriptor> serviceReferences = new HashSet<>();
private final Set<EntityManagerFactoryReferenceDescriptor> entityManagerFactoryReferences = new HashSet<>();
private final Set<EntityManagerReferenceDescriptor> entityManagerReferences = new HashSet<>();
private Set<Role> appRoles;
private String libraryDirectory;
private final List<SecurityRoleMapping> roleMaps = new ArrayList<>();
private final List<SecurityRoleAssignment> wlRoleAssignments = new ArrayList<>();
private boolean loadedFromApplicationXml = true;
private final Set<String> resourceAdapters = new HashSet<>();
private final Set<ApplicationParam> applicationParams = new HashSet<>();
private Application() {
super("", I18N.getLocalString(
"enterprise.deployment.application.description",
"Application description"));
}
/**
* @return the default version of the deployment descriptor
* loaded by this descriptor
*/
@Override
public String getDefaultSpecVersion() {
return ApplicationNode.SPEC_VERSION;
}
@Override
public boolean isEmpty() {
return modules.isEmpty();
}
/**
* Creates a new application to hold a standalone module
*
* @param name the application name
* @param newModule the standalone module descriptor
* @return the application
*/
public static Application createVirtualApplication(String name, ModuleDescriptor<BundleDescriptor> newModule) {
// create a new empty application
Application application = createApplication();
application.setVirtual(true);
if (name == null && newModule != null && newModule.getDescriptor() != null) {
name = newModule.getDescriptor().getDisplayName();
}
String untaggedName = VersioningUtils.getUntaggedName(name);
if (name != null) {
application.setDisplayName(untaggedName);
application.setName(untaggedName);
application.setAppName(untaggedName);
}
// add the module to it
if (newModule != null) {
newModule.setStandalone(true);
newModule.setArchiveUri(untaggedName);
if (newModule.getDescriptor() != null) {
newModule.getDescriptor().setApplication(application);
}
application.addModule(newModule);
}
return application;
}
/**
* @return a new empty application
*/
public static Application createApplication() {
ServiceLocator locator = Globals.getStaticBaseServiceLocator();
Application application = locator.create(Application.class);
locator.inject(application);
locator.postConstruct(application);
return application;
}
/**
* Returns the generated XML directory feturn the set of ejb references this ejb declares.
*/
@Override
public Set<EjbReferenceDescriptor> getEjbReferenceDescriptors() {
return ejbReferences;
}
/**
* Adds a reference to another ejb to me.
*/
@Override
public void addEjbReferenceDescriptor(EjbReferenceDescriptor ejbReference) {
ejbReferences.add(ejbReference);
ejbReference.setReferringBundleDescriptor(this);
}
@Override
public void removeEjbReferenceDescriptor(EjbReferenceDescriptor ejbReference) {
ejbReferences.remove(ejbReference);
}
/**
* @return a reference to another ejb by the same name or throw an IllegalArgumentException.
*/
public EjbReferenceDescriptor getEjbReferenceByName(String name) {
return getEjbReference(name);
}
@Override
public EjbReferenceDescriptor getEjbReference(String name) {
for (EjbReferenceDescriptor er : getEjbReferenceDescriptors()) {
if (er.getName().equals(name)) {
return er;
}
}
throw new IllegalArgumentException(
MessageFormat.format("This app [{0}] has no ejb reference by the name of [{1}] ", getName(), name));
}
@Override
public Set<ServiceReferenceDescriptor> getServiceReferenceDescriptors() {
return serviceReferences;
}
@Override
public void addServiceReferenceDescriptor(ServiceReferenceDescriptor serviceRef) {
serviceRef.setBundleDescriptor(this);
serviceReferences.add(serviceRef);
}
@Override
public void removeServiceReferenceDescriptor(ServiceReferenceDescriptor serviceRef) {
serviceReferences.remove(serviceRef);
}
/**
* Looks up an service reference with the given name.
* Throws an IllegalArgumentException if it is not found.
*/
@Override
public ServiceReferenceDescriptor getServiceReferenceByName(String name) {
for (ServiceReferenceDescriptor srd : this.getServiceReferenceDescriptors()) {
if (srd.getName().equals(name)) {
return srd;
}
}
throw new IllegalArgumentException(
I18N.getLocalString("enterprise.deployment.exceptionapphasnoservicerefbyname",
"This app [{0}] has no service reference by the name of [{1}]",
new Object[] {getRegistrationName(), name}));
}
@Override
public Set<MessageDestinationReferenceDescriptor> getMessageDestinationReferenceDescriptors() {
return messageDestReferences;
}
@Override
public void addMessageDestinationReferenceDescriptor(MessageDestinationReferenceDescriptor messageDestRef) {
messageDestRef.setReferringBundleDescriptor(this);
messageDestReferences.add(messageDestRef);
}
@Override
public void removeMessageDestinationReferenceDescriptor(MessageDestinationReferenceDescriptor msgDestRef) {
messageDestReferences.remove(msgDestRef);
}
/**
* Looks up an message destination reference with the given name.
* Throws an IllegalArgumentException if it is not found.
*/
@Override
public MessageDestinationReferenceDescriptor getMessageDestinationReferenceByName(String name) {
for (MessageDestinationReferenceDescriptor mdr : messageDestReferences) {
if (mdr.getName().equals(name)) {
return mdr;
}
}
throw new IllegalArgumentException(I18N.getLocalString("exceptionapphasnomsgdestrefbyname",
"This app [{0}] has no message destination reference by the name of [{1}]",
new Object[] {getRegistrationName(), name}));
}
/**
* Return the set of resource environment references this application declares.
*/
@Override
public Set<ResourceEnvReferenceDescriptor> getResourceEnvReferenceDescriptors() {
return resourceEnvReferences;
}
@Override
public void addResourceEnvReferenceDescriptor(ResourceEnvReferenceDescriptor resourceEnvReference) {
resourceEnvReferences.add(resourceEnvReference);
}
@Override
public void removeResourceEnvReferenceDescriptor(ResourceEnvReferenceDescriptor resourceEnvReference) {
resourceEnvReferences.remove(resourceEnvReference);
}
/**
* Return a reference to another ejb by the same name or throw an IllegalArgumentException.
*/
@Override
public ResourceEnvReferenceDescriptor getResourceEnvReferenceByName(String name) {
for (ResourceEnvReferenceDescriptor jdr : this.getResourceEnvReferenceDescriptors()) {
if (jdr.getName().equals(name)) {
return jdr;
}
}
throw new IllegalArgumentException(I18N.getLocalString(
"enterprise.deployment.exceptionapphasnoresourceenvrefbyname",
"This app {0} has no resource environment reference by the name of {1}",
new Object[] {getRegistrationName(), name}));
}
/**
* Return the set of resource references this ejb declares.
*/
@Override
public Set<ResourceReferenceDescriptor> getResourceReferenceDescriptors() {
return resourceReferences;
}
/**
* Adds a resource reference to me.
*/
@Override
public void addResourceReferenceDescriptor(ResourceReferenceDescriptor resourceReference) {
resourceReferences.add(resourceReference);
}
/**
* Removes the given resource reference from me.
*/
@Override
public void removeResourceReferenceDescriptor(ResourceReferenceDescriptor resourceReference) {
resourceReferences.remove(resourceReference);
}
/**
* Return the resource object corresponding to the supplied name or throw an illegal argument exception.
*/
@Override
public ResourceReferenceDescriptor getResourceReferenceByName(String name) {
for (Object element : this.getResourceReferenceDescriptors()) {
ResourceReferenceDescriptor next = (ResourceReferenceDescriptor) element;
if (next.getName().equals(name)) {
return next;
}
}
throw new IllegalArgumentException(I18N.getLocalString(
"enterprise.deployment.exceptionapphasnoresourcerefbyname",
"This app {0} has no resource reference by the name of {1}",
new Object[]{getRegistrationName(), name}));
}
/**
* Returns the environment property object searching on the supplied key.
* throws an illegal argument exception if no such environment property exists.
*/
@Override
public EnvironmentProperty getEnvironmentPropertyByName(String name) {
for (EnvironmentProperty ev : this.getEnvironmentProperties()) {
if (ev.getName().equals(name)) {
return ev;
}
}
throw new IllegalArgumentException(I18N.getLocalString(
"enterprise.deployment.exceptionapphasnoenvpropertybyname",
"This app {0} has no environment property by the name of {1}",
new Object[]{getRegistrationName(), name}));
}
/**
* Return a copy of the structure holding the environment properties.
*/
@Override
public Set<EnvironmentProperty> getEnvironmentProperties() {
return environmentProperties;
}
@Override
public void addEnvironmentProperty(EnvironmentProperty environmentProperty) {
this.environmentProperties.add(environmentProperty);
}
/**
* Removes the given environment property from me.
*/
@Override
public void removeEnvironmentProperty(EnvironmentProperty environmentProperty) {
this.getEnvironmentProperties().remove(environmentProperty);
}
@Override
public Set<EntityManagerFactoryReferenceDescriptor> getEntityManagerFactoryReferenceDescriptors() {
return entityManagerFactoryReferences;
}
/**
* Return the entity manager factory reference descriptor corresponding to
* the given name.
*/
@Override
public EntityManagerFactoryReferenceDescriptor getEntityManagerFactoryReferenceByName(String name) {
for (EntityManagerFactoryReferenceDescriptor next : getEntityManagerFactoryReferenceDescriptors()) {
if (next.getName().equals(name)) {
return next;
}
}
throw new IllegalArgumentException(
I18N.getLocalString("enterprise.deployment.exceptionapphasnoentitymgrfactoryrefbyname",
"This app {0} has no entity manager factory reference by the name of {1}",
new Object[] {getRegistrationName(), name}));
}
@Override
public void addEntityManagerFactoryReferenceDescriptor(EntityManagerFactoryReferenceDescriptor reference) {
reference.setReferringBundleDescriptor(this);
this.entityManagerFactoryReferences.add(reference);
}
@Override
public Set<EntityManagerReferenceDescriptor> getEntityManagerReferenceDescriptors() {
return entityManagerReferences;
}
/**
* Return the entity manager factory reference descriptor corresponding to
* the given name.
*/
@Override
public EntityManagerReferenceDescriptor getEntityManagerReferenceByName(String name) {
for (EntityManagerReferenceDescriptor next : getEntityManagerReferenceDescriptors()) {
if (next.getName().equals(name)) {
return next;
}
}
throw new IllegalArgumentException(
I18N.getLocalString("enterprise.deployment.exceptionapphasnoentitymgrrefbyname",
"This app {0} has no entity manager reference by the name of {1}",
new Object[] {getRegistrationName(), name}));
}
@Override
public void addEntityManagerReferenceDescriptor(EntityManagerReferenceDescriptor reference) {
reference.setReferringBundleDescriptor(this);
this.getEntityManagerReferenceDescriptors().add(reference);
}
@Override
public Set<LifecycleCallbackDescriptor> getPostConstructDescriptors() {
throw new UnsupportedOperationException();
}
@Override
public void addPostConstructDescriptor(LifecycleCallbackDescriptor postConstructDesc) {
throw new UnsupportedOperationException();
}
@Override
public LifecycleCallbackDescriptor getPostConstructDescriptorByClass(String className) {
throw new UnsupportedOperationException();
}
@Override
public Set<LifecycleCallbackDescriptor> getPreDestroyDescriptors() {
throw new UnsupportedOperationException();
}
@Override
public void addPreDestroyDescriptor(LifecycleCallbackDescriptor preDestroyDesc) {
throw new UnsupportedOperationException();
}
@Override
public LifecycleCallbackDescriptor getPreDestroyDescriptorByClass(String className) {
throw new UnsupportedOperationException();
}
@Override
public List<InjectionCapable> getInjectableResourcesByClass(String className) {
return getInjectableResourcesByClass(className, this);
}
@Override
public InjectionInfo getInjectionInfoByClass(Class<?> clazz) {
return getInjectionInfoByClass(clazz, this);
}
public void setGeneratedXMLDirectory(String xmlDir) {
generatedXMLDir = xmlDir;
}
public String getGeneratedXMLDirectory() {
return generatedXMLDir;
}
// START OF IASRI 4648645 - application registration name
/**
* Sets the registration name for this application. This name is used
* while deploying the application. The deployment process gurantees
* that this name is unique.
*
* @param appId the registration name used for this application
*/
public void setRegistrationName(String appId) {
// at his point we need to swap our RoleMapper, if we have one...
SecurityRoleMapper roleMapper;
try {
roleMapper = getRoleMapper();
} catch (IllegalArgumentException ignore) {
roleMapper = null;
}
if (roleMapper != null) {
if (securityRoleMapperFactory == null) {
throw new IllegalArgumentException(I18N.getLocalString(
"enterprise.deployment.norolemapperfactorydefine",
"This application has no role mapper factory defined"));
}
securityRoleMapperFactory.removeRoleMapper(getName());
roleMapper.setName(appId);
securityRoleMapperFactory.setRoleMapper(appId, roleMapper);
}
this.registrationName = appId;
}
/**
* Returns the registration name of this application.
*
* @return the registration name of this application
*/
public String getRegistrationName() {
if (registrationName == null) {
return getName();
}
return registrationName;
}
// END OF IASRI 4648645
/**
* Returns the value of the app-name element in the application.xml if
* it's defined. The default EE app name is the unqualified name of
* the .ear or stand-alone module, minus the file extension.
*
* @return the EE app name of this application
*/
public String getAppName() {
return VersioningUtils.getUntaggedName(appName);
}
/**
* Sets the EE app name
* @param appName the EE app name of this application
*/
public void setAppName(String appName) {
this.appName = VersioningUtils.getUntaggedName(appName);
}
/**
* Returns the value of the archive-name element in the sun-application.xml
* When the app-name is not present in application.xml and archive-name is
* present in sun-application.xml, the value of archive-name minus file
* extension will be used as the default name of the app-name.
*
* @return the EE app name of this application
*/
public String getArchiveName() {
return archiveName;
}
/**
* Sets the archive name using the archive-name element defined
* in sun-application.xml
* @param archiveName archiveName to calculate default EE6 app-name
*/
public void setArchiveName(String archiveName) {
this.archiveName = archiveName;
}
@Override
public String getCompatibility() {
return compatValue;
}
@Override
public void setCompatibility(String compatValue) {
this.compatValue = compatValue;
}
/**
* @return the initializeInOrder flag
* when the return value is true, the modules inside ear will be loaded
* by their declaration order in application.xml
*/
public boolean isInitializeInOrder() {
return initializeInOrder;
}
/**
* Sets the initializeInOrder flag
* @param initializeInOrder
*/
public void setInitializeInOrder(boolean initializeInOrder) {
this.initializeInOrder = initializeInOrder;
}
/**
* Set the physical entity manager factory for a persistence unit
* within this application.
* This method takes a parameter called persistenceRootUri to support for
* fully-qualified persistence-unit-name syntax within
* persistence-unit-refs and persistence-context-refs. The syntax is similar
* to ejb-link and messge-destination-link. See (EJB 3 core spec: 15.10.2)
*
* @param unitName Name of the persistence-unit
* @param persistenceRootUri uri of the root of the persistence.xml
* (excluding META-INF) in which the persistence unit was defined.
* This uri is relative to the top of the .ear.
* @param emf an entity manager factory.
*/
public void addEntityManagerFactory(
String unitName,
String persistenceRootUri,
EntityManagerFactory emf) {
String fullyQualifiedUnitName = persistenceRootUri + PERSISTENCE_UNIT_NAME_SEPARATOR + unitName;
// Always allow fully qualified lookup.
entityManagerFactories.put(fullyQualifiedUnitName, emf);
// Allow unqualified lookup, unless there are multiple .ear level
// persistence units declaring the same persistence unit name. In that
// case, only a fully-qualified lookup will work. Note that even
// though the entity manager factory map might contain more than one
// key pointing to the same entity manager factory, the behavior
// of getEntityManagerFactories() is not affected since it returns a Set.
if (entityManagerFactoryUnitNames.contains(unitName)) {
entityManagerFactories.remove(unitName);
} else {
entityManagerFactories.put(unitName, emf);
entityManagerFactoryUnitNames.add(unitName);
}
}
/**
* Retrieve the physical entity manager factory associated with the
* unitName of an application-level persistence unit. Returns null if
* no matching entry is found.
*/
public EntityManagerFactory getEntityManagerFactory(String unitName, BundleDescriptor declaringModule) {
String lookupString = unitName;
int separatorIndex = unitName.lastIndexOf(PERSISTENCE_UNIT_NAME_SEPARATOR);
if (separatorIndex != -1) {
String unqualifiedUnitName = unitName.substring(separatorIndex + 1);
String path = unitName.substring(0, separatorIndex);
String persistenceRootUri = getTargetUri(declaringModule, path);
lookupString = persistenceRootUri + PERSISTENCE_UNIT_NAME_SEPARATOR + unqualifiedUnitName;
}
return entityManagerFactories.get(lookupString);
}
/**
* Returns the set of physical entity manager factories associated with
* persistence units in this application.
*/
@Override
public Set<EntityManagerFactory> getEntityManagerFactories() {
return new HashSet<>(entityManagerFactories.values());
}
/**
* Return the set of roles used in this application. Currently, for release 1.0, it is an
* * aggregation of all the roles in the sub-modules of the application.
*
* @return the Set of roles in the application.
*/
@Override
public Set<Role> getRoles() {
Set<Role> roles = new HashSet<>();
for (BundleDescriptor bd : getBundleDescriptors()) {
if (bd != null) {
roles.addAll(bd.getRoles());
}
}
return roles;
}
/**
* Return the set of org.glassfish.security.common.Role objects
* I have (the ones defined in application xml).
*/
public Set<Role> getAppRoles() {
if (this.appRoles == null) {
this.appRoles = new HashSet<>();
}
return this.appRoles;
}
// used by reflection, see ApplicationNode
public void addAppRole(SecurityRoleDescriptor descriptor) {
Role role = new Role(descriptor.getName(), descriptor.getDescription());
getAppRoles().add(role);
}
/**
* Adds a new abstract role
*/
@Override
public void addRole(Role role) {
for (BundleDescriptor bd : getBundleDescriptors()) {
bd.addRole(role);
}
}
/**
* Removes the given role.
*/
@Override
public void removeRole(Role role) {
getAppRoles().remove(role);
for (BundleDescriptor bd : getBundleDescriptors()) {
bd.removeRole(role);
}
}
/**
* Reset the display name of this application.
*
* @param name the display name of the application.
*/
@Override
public void setName(String name) {
// for deploying from NT to solaris & vice versa. This will
// need to be cleaned when we clean up the backend for registering apps
name = name.replace('/', '-').replace('\\', '-');
super.setName(name);
if (this.getRoleMapper() != null) {
this.getRoleMapper().setName(name);
}
}
public void setLibraryDirectory(String value) {
libraryDirectory = value;
}
/**
* Returns an "intelligent" value for the library directory setting, meaning
* the current value if it has been set to a non-null, non-empty value;
* the default value if the value has never been set, and null if the value
* has been set to empty.
*
* @return String value of the library directory setting
*/
public String getLibraryDirectory() {
if (libraryDirectory == null) {
return LIBRARY_DIRECTORY_DEFAULT_VALUE;
}
return libraryDirectory.isEmpty() ? null : libraryDirectory;
}
public String getLibraryDirectoryRawValue() {
return libraryDirectory;
}
public void removeModule(ModuleDescriptor<BundleDescriptor> descriptor) {
if (modules.contains(descriptor)) {
if (descriptor.getDescriptor() != null) {
descriptor.getDescriptor().setApplication(null);
}
modules.remove(descriptor);
}
}
public void addModule(ModuleDescriptor<BundleDescriptor> descriptor) {
modules.add(descriptor);
if (descriptor.getDescriptor() != null) {
descriptor.getDescriptor().setApplication(this);
}
}
/**
* Obtain a full set of module descriptors
*
* @return the set of bundle descriptors
*/
public Set<ModuleDescriptor<BundleDescriptor>> getModules() {
return modules;
}
/**
* Get the uri of a target based on a source module and a
* a relative uri from the perspective of that source module.
*
* @param origin bundle descriptor within this application
* @param relativeTargetUri relative uri from the given bundle descriptor
* @return target uri
*/
public String getTargetUri(BundleDescriptor origin, String relativeTargetUri) {
try {
String archiveUri = origin.getModuleDescriptor().getArchiveUri();
URI originUri = new URI(archiveUri);
URI resolvedUri = originUri.resolve(relativeTargetUri);
return resolvedUri.getPath();
} catch (URISyntaxException use) {
LOG.log(Level.FINE, "origin " + origin + " has invalid syntax", use);
return null;
}
}
/**
* Get a target bundle descriptor based on an input bundle descriptor and
* a relative uri from the perspective of the input bundle descriptor.
*
* @param origin bundle descriptor within this application
* @param relativeTargetUri relative uri from the given bundle descriptor
* to another bundle within the application.
* @return target BundleDescriptor or null if not found.
*/
public BundleDescriptor getRelativeBundle(BundleDescriptor origin, String relativeTargetUri) {
String targetBundleUri = getTargetUri(origin, relativeTargetUri);
return targetBundleUri == null ? null : getModuleByUri(targetBundleUri);
}
/**
* Return the relative uri between two modules, from the perspective
* of the first bundle.
*
* @return relative uri or empty string if the two bundles are the same
*/
public String getRelativeUri(BundleDescriptor origin, BundleDescriptor target) {
String originUri = origin.getModuleDescriptor().getArchiveUri();
String targetUri = target.getModuleDescriptor().getArchiveUri();
StringTokenizer tokenizer = new StringTokenizer(originUri, "/");
int numTokens = tokenizer.countTokens();
int numSeparators = numTokens > 0 ? numTokens - 1 : 0;
StringBuilder relativeUri = new StringBuilder();
// The simplest way to compute a relative uri is to add one "../"
// for each sub-path in the origin URI, then add the target URI.
// It's possible for the result to not be normalized if the origin
// and target have at least one common root, but that shouldn't
// matter as long as when the relative URI is resolved against the
// origin it produces the target.
for (int i = 0; i < numSeparators; i++) {
relativeUri.append("../");
}
relativeUri.append(targetUri);
return relativeUri.toString();
}
/**
* Lookup module by uri.
*
* @param uri the module path in the application archive
* @return a bundle descriptor in this application identified by uri
* or null if not found.
*/
public ModuleDescriptor<BundleDescriptor> getModuleDescriptorByUri(String uri) {
for (ModuleDescriptor<BundleDescriptor> aModule : getModules()) {
if (aModule.getArchiveUri().equals(uri)) {
return aModule;
}
}
return null;
}
/**
* Lookup module by uri.
*
* @return a bundle descriptor in this application identified by uri
* or null if not found.
*/
public Collection<ModuleDescriptor<BundleDescriptor>> getModuleDescriptorsByType(ArchiveType type) {
if (type == null) {
throw new IllegalArgumentException("type cannot be null");