KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > appclient > jws > UserContentOrigin


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.appclient.jws;
25
26 import com.sun.enterprise.deployment.Application;
27 import com.sun.enterprise.deployment.interfaces.DeploymentImplConstants;
28 import com.sun.enterprise.deployment.util.ModuleDescriptor;
29 import com.sun.enterprise.instance.BaseManager;
30 import java.io.File JavaDoc;
31 import java.io.FileNotFoundException JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.net.URI JavaDoc;
34
35 /**
36  *Represents an origin of user-provided content - application origins or
37  *app client origins.
38  *
39  * @author tjquinn
40  */

41 public abstract class UserContentOrigin extends ContentOrigin {
42
43     /** descriptor for the origin */
44     protected Application application;
45     
46     /**
47      *Creates a new instance of the content origin.
48      *@param the Application object for the content origin
49      */

50     public UserContentOrigin(Application application) {
51         super();
52         this.application = application;
53     }
54
55     /**
56      *Returns the registration name for the top-level module associated with this
57      *nested app client.
58      *<p>
59      *This method is primarily used to get a name to use in checking whether
60      *the relevant module has been enabled or disabled for Java Web Start access.
61      *@return the application's registration name
62      */

63     public String JavaDoc getTopLevelRegistrationName() {
64         return getApplication().getRegistrationName();
65     }
66
67     /**
68      *Returns a string representation of this content origin.
69      *@return string describing the origin's current state
70      */

71     public String JavaDoc toString() {
72         StringBuilder JavaDoc sb = new StringBuilder JavaDoc(super.toString());
73         sb.append(" registration name=").append(application.getRegistrationName());
74 // .append(", enabled=").append(enabled);
75
return sb.toString();
76     }
77    
78     /**
79      *Returns the origin's corresponding Application object.
80      *@return Application descriptor from which this origin was derived
81      */

82     public Application getApplication() {
83         return application;
84     }
85     
86     /**
87      *Returns a File object for the generated app client jar file for this top-level
88      *app client.
89      *@return File for the generated jar file
90      */

91     public File JavaDoc locateGeneratedAppclientJarFile(BaseManager mgr) throws FileNotFoundException JavaDoc {
92         String JavaDoc regName = application.getRegistrationName();
93         
94         String JavaDoc generatedAppClientJarDirSpec = mgr.getGeneratedXMLLocation(regName);
95         String JavaDoc generatedAppClientJarName = getTopLevelRegistrationName() + DeploymentImplConstants.ClientJarSuffix;
96         
97         File JavaDoc generatedAppClientJar = new File JavaDoc (generatedAppClientJarDirSpec, generatedAppClientJarName);
98         if ( ! generatedAppClientJar.exists()) {
99             throw new FileNotFoundException JavaDoc(generatedAppClientJar.getAbsolutePath());
100         }
101         return generatedAppClientJar;
102     }
103     /**
104      *Returns whether this content origin's appclient is enabled for Java
105      *Web Start access.
106      *@return boolean indicating whether the appclient is enabled for JWS access
107      */

108     public boolean isEnabled() {
109         try {
110             return AppclientJWSSupportInfo.getInstance().isEnabled(this);
111         } catch (IOException JavaDoc ioe) {
112             /*
113              *An IOException can occur if some infrastructure objects cannot be
114              *located in obtaining the instance. Very unlikely and also logged elsewhere.
115              */

116             return false;
117         } catch (Exception JavaDoc e) {
118             throw new RuntimeException JavaDoc(e);
119         }
120     }
121 }
Popular Tags