KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > guiframework > view > descriptors > CCPropertySheetDescriptor


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.tools.guiframework.view.descriptors;
25
26 import com.iplanet.jato.ModelManager;
27 import com.iplanet.jato.RequestManager;
28 import com.iplanet.jato.RequestContext;
29 import com.iplanet.jato.view.ContainerView;
30 import com.iplanet.jato.view.ContainerViewBase;
31 import com.iplanet.jato.view.View;
32 import com.sun.web.ui.model.CCPropertySheetModel;
33 import com.sun.web.ui.model.CCPropertySheetModelInterface;
34 import com.sun.web.ui.view.propertysheet.CCPropertySheet;
35
36 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
37 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPropertySheet;
38
39 import java.io.InputStream JavaDoc;
40
41
42 /**
43  *
44  */

45 public class CCPropertySheetDescriptor extends ViewDescriptor implements FakeContainerDescriptor {
46
47     /**
48      * Constructor
49      */

50     public CCPropertySheetDescriptor(String JavaDoc name) {
51     super(name);
52     }
53
54
55     public void registerChildren(ContainerViewBase instance) {
56     // Invoke the super registerChild
57
super.registerChildren(instance);
58
59     getModel().registerChildren(instance);
60     }
61     
62
63     /**
64      * This method creates empty descriptors on the fly for fields that are
65      * defined by the underlying model.
66      */

67     public ViewDescriptor getChildDescriptor(String JavaDoc name) {
68         // Do the normal stuff if we can...
69
ViewDescriptor desc = super.getChildDescriptor(name);
70     if (desc != null) {
71         return desc;
72     }
73
74     // Do we need to create a descriptor on the fly?
75
CCPropertySheetModelInterface model = getModel();
76         if (model != null && model.isChildSupported(name)) {
77         // YES
78
desc = new CCPropertySheetChildDescriptor(name);
79         // NOTE: This call is safe (mostly), because although we are
80
// NOTE: modifying a static structure... this change is applicable
81
// NOTE: to all users. However, there is a slight possibility of
82
// NOTE: of a sync. problem... not worth worrying about now. If
83
// NOTE: this does become a problem, just remove the
84
// NOTE: addChildDescriptor() line below.
85
addChildDescriptor(desc);
86         return desc;
87     }
88
89     return null;
90     }
91
92
93     /**
94      * <P>This method will get the CCPropertySheetModel for this property
95      * sheet. If one has not already been created, it will create a new one.
96      * This method depends on the "XML_FILE" property being defined. You must
97      * also have a model mapping entry in the "ModelTypeMap" for
98      * "CCPropertySheetModelInterface.class".</P>
99      *
100      * <P>Optionally, you may specify whether this model should be retrieved
101      * and/or stored from/in session. The GET_FROM_SESSION and
102      * STORE_IN_SESSION parameters control this.</P>
103      */

104     public CCPropertySheetModelInterface getModel() {
105     // Determine if the session should be used w/ the model manager.
106
boolean fromSession = shouldGetModelFromSession();
107     boolean toSession = shouldPutModelToSession();
108     String JavaDoc instanceName = getModelInstanceName();
109
110     // Use the ModelManager to create/get the model
111
ModelManager mgr = RequestManager.getRequestContext().getModelManager();
112     CCPropertySheetModelInterface model =
113         (CCPropertySheetModelInterface)mgr.getModel(
114         CCPropertySheetModelInterface.class,
115         instanceName, fromSession, toSession);
116
117     // Make sure the XML file is set on the Model
118
if (model.getDocument() == null) {
119         InputStream JavaDoc in = getXMLFileAsStream();
120         model.setDocument(in);
121         try {
122         in.close();
123         } catch (java.io.IOException JavaDoc ex) {
124         // Ignore
125
}
126         }
127     return model;
128     }
129
130
131     /**
132      * This is a factory method for CCActionTable instances.
133      *
134      * @param ctx The RequestContext
135      * @param container The container for the newly created
136      */

137     public View getInstance(RequestContext ctx, ContainerView container, String JavaDoc name) {
138     return new DescriptorCCPropertySheet(ctx, container, name, this, getModel());
139     }
140 }
141
Popular Tags