KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > j2ee > j2eeobjectnames > J2eeContextImpl


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 JavaDoc;
20
21 /**
22  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
23  */

24 public class J2eeContextImpl implements J2eeContext {
25
26     private final String JavaDoc domainName;
27     private final String JavaDoc serverName;
28     private final String JavaDoc applicationName;
29     private final String JavaDoc moduleType;
30     private final String JavaDoc moduleName;
31     private final String JavaDoc j2eeName;
32     private final String JavaDoc j2eeType;
33
34     public J2eeContextImpl(String JavaDoc domainName, String JavaDoc serverName, String JavaDoc applicationName, String JavaDoc moduleType, String JavaDoc moduleName, String JavaDoc j2eeName, String JavaDoc 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 JavaDoc source, String JavaDoc 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), // <-- This might be wrong!!! GERONIMO-1140
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 JavaDoc source, String JavaDoc 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 JavaDoc source, String JavaDoc moduleType, String JavaDoc moduleName) {
72         return new J2eeContextImpl(source.getDomain(),
73                 source.getKeyProperty(NameFactory.J2EE_SERVER),
74                 source.getKeyProperty(NameFactory.J2EE_NAME), //application name in module is name key property in application's object name
75
moduleType,
76                 moduleName,
77                 null,
78                 null);
79     }
80
81     public static J2eeContextImpl newModuleContextFromApplication(J2eeContext source, String JavaDoc moduleType, String JavaDoc 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 JavaDoc getJ2eeDomainName() {
92         return domainName;
93     }
94
95     public String JavaDoc getJ2eeServerName() {
96         return serverName;
97     }
98
99     public String JavaDoc getJ2eeApplicationName() {
100         return applicationName;
101     }
102
103     public String JavaDoc getJ2eeModuleType() {
104         return moduleType;
105     }
106
107     public String JavaDoc getJ2eeModuleName() {
108         return moduleName;
109     }
110
111     public String JavaDoc getJ2eeName() {
112         return j2eeName;
113     }
114
115     public String JavaDoc getJ2eeType() {
116         return j2eeType;
117     }
118
119     public String JavaDoc getJ2eeDomainName(String JavaDoc override) {
120         return override == null ? domainName : override;
121     }
122
123     public String JavaDoc getJ2eeServerName(String JavaDoc override) {
124         return override == null ? serverName : override;
125     }
126
127     public String JavaDoc getJ2eeApplicationName(String JavaDoc override) {
128         return override == null ? applicationName : override;
129     }
130
131     public String JavaDoc getJ2eeModuleType(String JavaDoc override) {
132         return override == null ? moduleType : override;
133     }
134
135     public String JavaDoc getJ2eeModuleName(String JavaDoc override) {
136         return override == null ? moduleName : override;
137     }
138
139     //most likely the last 2 don't make any sense.
140
public String JavaDoc getJ2eeName(String JavaDoc override) {
141         return override == null ? j2eeName : override;
142     }
143
144     public String JavaDoc getJ2eeType(String JavaDoc override) {
145         return override == null ? j2eeType : override;
146     }
147 }
148
Popular Tags