1 17 18 package org.apache.lenya.ac.file; 19 20 import java.io.File ; 21 22 import org.apache.avalon.framework.configuration.Configuration; 23 import org.apache.avalon.framework.configuration.ConfigurationException; 24 import org.apache.avalon.framework.configuration.DefaultConfiguration; 25 import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer; 26 import org.apache.lenya.ac.AccessControlException; 27 import org.apache.lenya.ac.Item; 28 import org.apache.lenya.ac.impl.AbstractRole; 29 import org.apache.lenya.ac.impl.ItemConfiguration; 30 31 35 public class FileRole extends AbstractRole implements Item { 36 37 42 public FileRole(File configurationDirectory, String id) { 43 setId(id); 44 setConfigurationDirectory(configurationDirectory); 45 } 46 47 public static final String ROLE = "role"; 48 49 52 public FileRole() { 53 } 54 55 61 public void configure(Configuration config) throws ConfigurationException { 62 new ItemConfiguration().configure(this, config); 63 } 64 65 70 public void save() throws AccessControlException { 71 DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer(); 72 Configuration config = createConfiguration(); 73 File xmlPath = getConfigurationDirectory(); 74 File xmlfile = new File (xmlPath, getId() + FileRoleManager.SUFFIX); 75 76 try { 77 serializer.serializeToFile(xmlfile, config); 78 } catch (Exception e) { 79 throw new AccessControlException(e); 80 } 81 } 82 83 88 private Configuration createConfiguration() { 89 DefaultConfiguration config = new DefaultConfiguration(ROLE); 90 new ItemConfiguration().save(this, config); 91 return config; 92 } 93 94 private File configurationDirectory; 95 96 100 public File getConfigurationDirectory() { 101 return configurationDirectory; 102 } 103 104 107 public void setConfigurationDirectory(File file) { 108 configurationDirectory = file; 109 } 110 } 111 | Popular Tags |