Java 3D Desktop Environment旨在使用Java 3D来创建一个3D桌面环境。功能包括:分布式的应用程序

源代码在线查看: wrappercomponent.java

软件大小: 1221 K
上传用户: spy0207
关键词: Java Environment Desktop 3D
下载地址: 免注册下载 普通下载 VIP

相关代码

				package org.j3de.server;       
				    
				import java.io.IOException;
				import java.io.StreamTokenizer;
				import java.io.StringReader;
				import java.lang.reflect.Constructor;
				import java.lang.reflect.InvocationTargetException;
				import java.net.SocketPermission;
				import java.security.PermissionCollection;
				import java.security.Permissions;   
				import java.security.Permission;
				import java.util.jar.JarFile;
				
				import org.w3c.dom.NamedNodeMap;
				import org.w3c.dom.Node;       
				import org.w3c.dom.NodeList;
				import org.w3c.dom.Document;
				
				import org.j3de.exception.ExceptionHandler;
				import org.j3de.util.AbstractComponent;
				import org.j3de.util.ConfigurationException;
				import org.j3de.util.Configurable;
				
				public abstract class WrapperComponent extends AbstractComponent {               
				  private final static String JARFILE   = "jarfile";
				  private final static String JARURL    = "jarurl";
				  private final static int    QUOTE     = 39;
				  private final static int    COMMA     = 44;
				  private final static int    SEMICOLON = 59;
				  
				  private String      jarFile;
				  private String      jarURL;
				
				  protected abstract void setComponent(Object component);
				  
				  public void configure(Node node, Document nodeFactory)  throws ConfigurationException {  
				    super.configure(node, nodeFactory); 
				                                                             
				    jarURL   = helper.getPropertyValue(JARURL);               
				    ClassLoader loader = getJarFiles(node);     
				    setComponent(helper.getComponent("wrappedComponent", null, null, null, loader));      
				  }                                                   
				
				  private ClassLoader getJarFiles(Node root) throws ConfigurationException { 
				    JarClassLoader loader = JarClassLoader.getClassLoader();
				    
				    NodeList childNodes = root.getChildNodes();   
				    
				    for (int i=0; i				      Node node = childNodes.item(i);
				      if (node.getNodeName().equals("jarfile")) {
				        NamedNodeMap attributes = node.getAttributes();  
				        Node attrib = attributes.getNamedItem("name");
				        
				        String name        = null;
				        String permissions = null;
				        
				        try {
				          name        = attributes.getNamedItem("name").getNodeValue();   
				          permissions = attributes.getNamedItem("permissions").getNodeValue();   
				        } catch (NullPointerException e) {
				        }
				        
				        if (name != null) {  
				          PermissionCollection pc = getPermissionCollection(permissions);   
				          loader.addJarFile(name, pc);  
				        }
				      }
				    }           
				    
				    return loader;
				  }            
				  
				  private PermissionCollection getPermissionCollection(String permissions) throws ConfigurationException {
				    PermissionCollection pc = new Permissions();
				    
				    // Add Default Permission : Every Class loaded locally is allowed to connect to any client.
				    // This should be moved to the Configuration-File !
				    pc.add(new SocketPermission("*", "listen,connect,resolve"));    
				    
				    if (permissions == null)
				      return pc;
				     
				    try {
				      StreamTokenizer st = new StreamTokenizer(new StringReader(permissions));
				      st.nextToken();
				      
				      String permissionName = null;
				      String param1         = null;
				      String param2         = null;
				      
				      // Format of Permisions :
				      // classname ['param1'] [, 'param2'] ; nextpermission 
				      
				      while (st.ttype != StreamTokenizer.TT_EOF) {
				        if (st.ttype == StreamTokenizer.TT_WORD) {
				          permissionName = st.sval;   
				        } else
				          throw new ConfigurationException("Error Parsing Permissions : Permissions-Classname expected"); 
				 
				        st.nextToken();
				         
				        if (st.ttype == QUOTE) {
				          param1 = st.sval;   
				     
				          st.nextToken();
				          
				          if (st.ttype == COMMA) { 
				            st.nextToken();     
				            
				            if (st.ttype == QUOTE) {
				              param2 = st.sval;      
				              addPermission(pc, permissionName, param1, param2);
				              
				              st.nextToken();           
				              
				              if (st.ttype != SEMICOLON)
				                throw new ConfigurationException("Error Parsing Permissions : Semicolon Expected");
				            
				            } else 
				              throw new ConfigurationException("Error Parsing Permissions : Parameter Expected");
				        
				          } else if (st.ttype == SEMICOLON) {
				            addPermission(pc, permissionName, param1, param2);
				          } else
				            throw new ConfigurationException("Error Parsing Permissions : Parameter or Semicolon Expected");
				        
				        } else if (st.ttype == SEMICOLON) {
				          addPermission(pc, permissionName, param1, param2);
				        } else
				          throw new ConfigurationException("Error Parsing Permissions : Parameter or Semicolon Expected");
				        
				        st.nextToken();
				      
				      }
				    } catch (IOException e) {
				      ExceptionHandler.handleException(e);
				    }
				      
				    return pc;
				  }       
				  
				  private void  addPermission(PermissionCollection pc, 
				                              String classname, 
				                              String param1,
				                              String param2) throws ConfigurationException {
				    try {                                 
				      Class permissionClass = Class.forName(classname);
				      if (!Permission.class.isAssignableFrom(permissionClass))
				        throw new ConfigurationException(classname + " is not of type Permission");
				        
				      Constructor constructor;
				      Class[]     params;
				      Object[]    paramValues;
				      
				      if (param1 == null) {
				        params         = new Class[0];                               
				        paramValues    = new Object[0];
				        constructor    = permissionClass.getConstructor(params);
				      } else if (param2 == null) {
				        params         = new Class[1];                               
				        params[0]      = String.class;
				        paramValues    = new Object[1];  
				        paramValues[0] = param1;
				        constructor    = permissionClass.getConstructor(params);
				      } else {
				        params = new Class[2];                               
				        params[0]      = String.class;
				        params[1]      = String.class;
				        paramValues    = new Object[2];  
				        paramValues[0] = param1;
				        paramValues[1] = param2;
				        constructor = permissionClass.getConstructor(params);
				      }
				      
				      pc.add((Permission)constructor.newInstance(paramValues));
				      
				    } catch (Exception e) {
				      ExceptionHandler.handleException(e);
				    }
				  }
				    
				  public String getJarURL() {
				    return jarURL;
				  }
				
				}
							

相关资源