001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ScaffoldPlatformContext.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.framework;
030:
031: import com.sun.jbi.JBIProvider;
032: import com.sun.jbi.platform.PlatformContext;
033: import com.sun.jbi.platform.PlatformEventListener;
034: import com.sun.jbi.security.KeyStoreUtil;
035: import java.util.HashSet;
036: import java.util.Set;
037: import javax.management.MBeanServer;
038: import javax.management.MBeanServerConnection;
039: import javax.naming.InitialContext;
040: import javax.transaction.TransactionManager;
041:
042: /**
043: * This is a test class to provide a simple PlatformContext implementation
044: * for use by the TestEnvironmentContext class.
045: *
046: * @author Sun Microsystems, Inc.
047: */
048: public class ScaffoldPlatformContext implements PlatformContext {
049: private String mInstanceRoot;
050: private String mInstallRoot;
051: private TransactionManager mTransactionManager;
052:
053: /** Create a new PlatformContextImpl. */
054: public ScaffoldPlatformContext() {
055: mInstallRoot = System.getProperty("java.io.tmpdir");
056: mInstanceRoot = System.getProperty("java.io.tmpdir");
057:
058: try {
059: javax.naming.InitialContext ctx = new javax.naming.InitialContext();
060: mTransactionManager = (javax.transaction.TransactionManager) ctx
061: .lookup("java:appserver/TransactionManager");
062: } catch (Exception ex) {
063: ex.printStackTrace();
064: }
065: }
066:
067: /**
068: * Get the TransactionManager for this implementation. The instance
069: * returned is an implementation of the standard JTS interface. If none
070: * is available, returns null.
071: * @return A TransactionManager instance.
072: * @throws Exception if a TransactionManager cannot be obtained.
073: */
074: public TransactionManager getTransactionManager() throws Exception {
075: return mTransactionManager;
076: }
077:
078: /**
079: * Get the MBean server connection for a particular instance.
080: * @return the <CODE>MBeanServerConnection</CODE> for the specified instance.
081: */
082: public MBeanServerConnection getMBeanServerConnection(
083: String instanceName) {
084: return java.lang.management.ManagementFactory
085: .getPlatformMBeanServer();
086: }
087:
088: /**
089: * Get the instance name of the platform's administration server. If the
090: * platform does not provide a separate administration server, then this
091: * method returns the name of the local instance.
092: * @return instance name of the administration server
093: */
094: public String getAdminServerName() {
095: return getInstanceName();
096: }
097:
098: /**
099: * Determine whether this instance is the administration server instance.
100: * @return <CODE>true</CODE> if this instance is the administration server,
101: * <CODE>false</CODE> if not.
102: */
103: public boolean isAdminServer() {
104: return true;
105: }
106:
107: /**
108: * Get the name of this instance.
109: * @return the name of this server instance.
110: */
111: public String getInstanceName() {
112: return "server";
113: }
114:
115: /**
116: * @return true if the instance is up and running, false otherwise
117: */
118: public boolean isInstanceUp(String instanceName) {
119: return true;
120: }
121:
122: /**
123: * Determine whether multiple servers are permitted within this AS
124: * installation.
125: * @return true if multiple servers are permitted.
126: */
127: public boolean supportsMultipleServers() {
128: return false;
129: }
130:
131: /**
132: * Get the Target Name. If the instance is not a clustered instance then
133: * the target name is the instance name. If the instance is part of a
134: * cluster then the target name is the cluster name.
135: *
136: * @return the target name.
137: */
138: public String getTargetName() {
139: return "server";
140: }
141:
142: /**
143: * Get the Target Name for a specified instance. If the instance is not
144: * clustered the instance name is returned. This operation is invoked by
145: * the JBI instance MBeans only.
146: *
147: * @return the target name.
148: */
149: public String getTargetName(String instanceName) {
150: return "server";
151: }
152:
153: /**
154: * Get a set of the names of all the standalone servers in the domain.
155: * @return a set of names of standalone servers in the domain.
156: */
157: public Set<String> getStandaloneServerNames() {
158: return new HashSet<String>();
159: }
160:
161: /**
162: * Get a set of the names of all the clustered servers in the domain.
163: * @return a set of names of clustered servers in the domain.
164: */
165: public Set<String> getClusteredServerNames() {
166: return new HashSet<String>();
167: }
168:
169: /**
170: * Get a set of the names of all the clusters in the domain.
171: * @return a set of names of clusters in the domain.
172: */
173: public Set<String> getClusterNames() {
174: return new HashSet<String>();
175: }
176:
177: /**
178: * Get a set of the names of all the servers in the specified cluster.
179: * @return a set of names of servers in the cluster.
180: */
181: public Set<String> getServersInCluster(String clusterName) {
182: return new HashSet<String>();
183: }
184:
185: /**
186: * Determine whether a target is a valid server or cluster name.
187: * @return <CODE>true</CODE> if <CODE>targetName</CODE> is a valid
188: * standalone server name or cluster name, <CODE>false</CODE> if not.
189: */
190: public boolean isValidTarget(String targetName) {
191: return true;
192: }
193:
194: /**
195: * Determine whether a target is a cluster.
196: * @return <CODE>true</CODE> if <CODE>targetName</CODE> is a cluster,
197: * <CODE>false</CODE> if not.
198: */
199: public boolean isCluster(String targetName) {
200: return false;
201: }
202:
203: /**
204: * Determine whether a target is a standalone server.
205: * @return <CODE>true</CODE> if <CODE>targetName</CODE> is a standalone
206: * server, <CODE>false</CODE> if not.
207: */
208: public boolean isStandaloneServer(String targetName) {
209: return true;
210: }
211:
212: /**
213: * Determine whether the target is a clustered server.
214: * @return <CODE>true</CODE> if <CODE>targetName</CODE> is a clustered
215: * server, <CODE>false</CODE> if not.
216: */
217: public boolean isClusteredServer(String targetName) {
218: return false;
219: }
220:
221: /**
222: * Determine whether or not an instance is clustered.
223: * @return <CODE>true</CODE> if the instance is clustered,
224: * <CODE>false</CODE> if not.
225: */
226: public boolean isInstanceClustered(String instanceName) {
227: return false;
228: }
229:
230: /**
231: * Get a string representation of the DAS JMX RMI connector port.
232: * @return the JMX RMI connector port as a (CODE>String</CODE>.
233: */
234: public String getJmxRmiPort() {
235: return null;
236: }
237:
238: /**
239: * Provides access to the platform's MBean server.
240: * @return platform MBean server.
241: */
242: public MBeanServer getMBeanServer() {
243: return java.lang.management.ManagementFactory
244: .getPlatformMBeanServer();
245: }
246:
247: /**
248: * Get the full path to the platform's instance root directory.
249: * @return platform instance root
250: */
251: public String getInstanceRoot() {
252: return mInstanceRoot;
253: }
254:
255: /**
256: * Get the full path to the platform's instaall root directory.
257: * @return platform install root
258: */
259: public String getInstallRoot() {
260: return mInstallRoot;
261: }
262:
263: /**
264: * Set the full path to the platform's instance root directory.
265: * @param instanceRoot platform instance root
266: */
267: public void setInstanceRoot(String instanceRoot) {
268: mInstanceRoot = instanceRoot;
269: }
270:
271: /**
272: * Set the full path to the platform's install root directory.
273: * @param install platform install root
274: */
275: public void setInstallRoot(String installRoot) {
276: mInstallRoot = installRoot;
277: }
278:
279: /**
280: * Returns the provider type for this platform.
281: * @return enum value corresponding to this platform implementation.
282: */
283: public JBIProvider getProvider() {
284: return JBIProvider.OTHER;
285: }
286:
287: /**
288: * Returns the KeyStoreUtil for Java SE. Currently unsupported
289: *
290: * @return a KeyStoreUtil
291: * @exception UnsupportedOperationException
292: */
293: public KeyStoreUtil getKeyStoreUtil() {
294: throw new UnsupportedOperationException();
295: }
296:
297: /**
298: * Retrieves the naming context that should be used to locate platform
299: * resources (e.g. TransactionManager).
300: * @return naming context
301: */
302: public InitialContext getNamingContext() {
303: return null;
304: }
305:
306: /**
307: * Get the JBI system class loader for this implementation.
308: *
309: * @return the <CODE>ClassLoader</CODE> that is the "system" class loader
310: * from a JBI runtime perspective.
311: * @throws SecurityException if access to the class loader is denied.
312: */
313: public ClassLoader getSystemClassLoader() throws SecurityException {
314: return this .getClass().getClassLoader();
315: }
316:
317: /**
318: * Register a listener for platform events.
319: * @param listener listener implementation
320: */
321: public void addListener(PlatformEventListener listener) {
322:
323: }
324:
325: /**
326: * Remove a listener for platform events.
327: * @param listener listener implementation
328: */
329: public void removeListener(PlatformEventListener listener) {
330:
331: }
332:
333: /**
334: * Specify the transaction manager.
335: * @param transactionManager the TM
336: */
337: public void setTransactionManager(
338: TransactionManager transactionManager) {
339: mTransactionManager = transactionManager;
340: }
341: }
|