1 /**
2 *
3 * Copyright 2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.geronimo.j2ee.j2eeobjectnames;
18
19 import javax.management.ObjectName;
20
21 /**
22 * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
23 */
24 public class J2eeContextImpl implements J2eeContext {
25
26 private final String domainName;
27 private final String serverName;
28 private final String applicationName;
29 private final String moduleType;
30 private final String moduleName;
31 private final String j2eeName;
32 private final String j2eeType;
33
34 public J2eeContextImpl(String domainName, String serverName, String applicationName, String moduleType, String moduleName, String j2eeName, String j2eeType) {
35 this.domainName = domainName;
36 this.serverName = serverName;
37 this.applicationName = applicationName;
38 this.moduleType = moduleType;
39 this.moduleName = moduleName;
40 this.j2eeName = j2eeName;
41 this.j2eeType = j2eeType;
42 }
43
44 public static J2eeContextImpl newContext(ObjectName source, String moduleType) {
45 return new J2eeContextImpl(source.getDomain(),
46 source.getKeyProperty(NameFactory.J2EE_SERVER),
47 source.getKeyProperty(NameFactory.J2EE_APPLICATION),
48 moduleType,
49 source.getKeyProperty(moduleType),
50 source.getKeyProperty(NameFactory.J2EE_NAME),
51 source.getKeyProperty(NameFactory.J2EE_TYPE));
52 }
53
54 /**
55 * This method is a workaround for GERONIMO-1140 -- it's the same as the
56 * previous one except for the offending line. If this is determined to
57 * be a valid change in general, this can replace newContext(ObjectName, String)
58 * However, I'm not 100% sure that it's OK to have the J2EE_NAME in two
59 * consecutive parameters in the general case.
60 */
61 public static J2eeContextImpl newModuleContext(ObjectName source, String moduleType) {
62 return new J2eeContextImpl(source.getDomain(),
63 source.getKeyProperty(NameFactory.J2EE_SERVER),
64 source.getKeyProperty(NameFactory.J2EE_APPLICATION),
65 moduleType,
66 source.getKeyProperty(NameFactory.J2EE_NAME),
67 source.getKeyProperty(NameFactory.J2EE_NAME),
68 source.getKeyProperty(NameFactory.J2EE_TYPE));
69 }
70
71 public static J2eeContextImpl newModuleContextFromApplication(ObjectName source, String moduleType, String moduleName) {
72 return new J2eeContextImpl(source.getDomain(),
73 source.getKeyProperty(NameFactory.J2EE_SERVER),
74 source.getKeyProperty(NameFactory.J2EE_NAME),
75 moduleType,
76 moduleName,
77 null,
78 null);
79 }
80
81 public static J2eeContextImpl newModuleContextFromApplication(J2eeContext source, String moduleType, String moduleName) {
82 return new J2eeContextImpl(source.getJ2eeDomainName(),
83 source.getJ2eeServerName(),
84 source.getJ2eeApplicationName(),
85 moduleType,
86 moduleName,
87 null,
88 null);
89 }
90
91 public String getJ2eeDomainName() {
92 return domainName;
93 }
94
95 public String getJ2eeServerName() {
96 return serverName;
97 }
98
99 public String getJ2eeApplicationName() {
100 return applicationName;
101 }
102
103 public String getJ2eeModuleType() {
104 return moduleType;
105 }
106
107 public String getJ2eeModuleName() {
108 return moduleName;
109 }
110
111 public String getJ2eeName() {
112 return j2eeName;
113 }
114
115 public String getJ2eeType() {
116 return j2eeType;
117 }
118
119 public String getJ2eeDomainName(String override) {
120 return override == null ? domainName : override;
121 }
122
123 public String getJ2eeServerName(String override) {
124 return override == null ? serverName : override;
125 }
126
127 public String getJ2eeApplicationName(String override) {
128 return override == null ? applicationName : override;
129 }
130
131 public String getJ2eeModuleType(String override) {
132 return override == null ? moduleType : override;
133 }
134
135 public String getJ2eeModuleName(String override) {
136 return override == null ? moduleName : override;
137 }
138
139
140 public String getJ2eeName(String override) {
141 return override == null ? j2eeName : override;
142 }
143
144 public String getJ2eeType(String override) {
145 return override == null ? j2eeType : override;
146 }
147 }