1 23 24 package com.sun.enterprise.tools.admingui.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.CCManageChildrenModel; 33 34 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 35 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 36 import com.sun.enterprise.tools.guiframework.view.descriptors.FakeContainerDescriptor; 37 import com.sun.enterprise.tools.guiframework.util.LogUtil; 38 39 import com.sun.enterprise.tools.admingui.taglib.DataSheet; 40 import com.sun.enterprise.tools.admingui.taglib.DataSheetModelInterface; 41 42 import java.io.InputStream ; 43 import java.net.URL ; 44 45 import org.xml.sax.EntityResolver ; 46 import org.xml.sax.InputSource ; 47 48 49 52 public class DataSheetDescriptor extends ViewDescriptor implements FakeContainerDescriptor { 53 54 57 public DataSheetDescriptor(String name) { 58 super(name); 59 } 60 61 62 public void registerChildren(ContainerViewBase instance) { 63 super.registerChildren(instance); 65 66 getModel().registerChildren(instance); 67 } 68 69 70 74 public ViewDescriptor getChildDescriptor(String name) { 75 ViewDescriptor desc = super.getChildDescriptor(name); 77 if (desc != null) { 78 return desc; 79 } 80 81 DataSheetModelInterface model = getModel(); 83 if (model != null && model.isChildSupported(name)) { 84 desc = new DataSheetChildDescriptor(name); 86 addChildDescriptor(desc); 93 return desc; 94 } 95 96 return null; 97 } 98 99 class myEntityResolver implements EntityResolver { 100 public InputSource resolveEntity (String publicId, String systemId) { 101 102 if (systemId != null && (systemId.startsWith("http")==false) && 103 (systemId.endsWith(".xml") || systemId.endsWith(".dtd"))) { 104 InputStream resourceStream = null; 105 int i = systemId.indexOf("dtd/"); 106 if (i >= 0) { 107 systemId = "xml/" + systemId.substring(i); 108 resourceStream = getClass().getClassLoader() 111 .getResourceAsStream(systemId); 112 if (resourceStream == null) { 113 String sURL = "file:///" + 115 RequestManager.getRequestContext().getServletContext() 116 .getRealPath(systemId); 117 try { 119 resourceStream = new URL (sURL).openStream(); 120 } catch (Exception ex) { 121 } 123 } 124 } 125 if (resourceStream != null) { 126 return new InputSource (resourceStream); 127 } 128 } 129 return null; 131 } 132 } 133 134 145 public DataSheetModelInterface getModel() { 146 boolean fromSession = shouldGetModelFromSession(); 148 boolean toSession = shouldPutModelToSession(); 149 String instanceName = getModelInstanceName(); 150 151 ModelManager mgr = RequestManager.getRequestContext().getModelManager(); 153 DataSheetModelInterface model = 154 (DataSheetModelInterface)mgr.getModel( 155 DataSheetModelInterface.class, 156 instanceName, fromSession, toSession); 157 158 if (model.getDocument() == null) { 160 InputStream in = getXMLFileAsStream(); 161 model.setEntityResolver(new DataSheetDescriptor.myEntityResolver()); 162 model.setDocument(in); 176 try { 177 in.close(); 178 } catch (java.io.IOException ex) { 179 } 181 } 182 return model; 183 } 184 185 186 192 public View getInstance(RequestContext ctx, ContainerView container, String name) { 193 return new DescriptorDataSheet(ctx, container, name, this, getModel()); 194 } 195 } 196 | Popular Tags |