1 17 18 19 20 package org.apache.lenya.ac.file; 21 22 import java.io.File ; 23 24 import org.apache.avalon.framework.configuration.Configuration; 25 import org.apache.avalon.framework.configuration.ConfigurationException; 26 import org.apache.avalon.framework.configuration.DefaultConfiguration; 27 import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer; 28 import org.apache.lenya.ac.AccessControlException; 29 import org.apache.lenya.ac.Item; 30 import org.apache.lenya.ac.impl.AbstractGroup; 31 import org.apache.lenya.ac.impl.ItemConfiguration; 32 33 36 public class FileGroup extends AbstractGroup implements Item { 37 38 41 public void delete() throws AccessControlException { 42 super.delete(); 43 getFile().delete(); 44 } 45 46 49 public FileGroup() { 50 } 51 52 57 public FileGroup(File configurationDirectory, String id) { 58 super(id); 59 setConfigurationDirectory(configurationDirectory); 60 } 61 62 67 public void configure(Configuration config) throws ConfigurationException { 68 new ItemConfiguration().configure(this, config); 69 } 70 71 75 protected File getFile() { 76 File xmlPath = getConfigurationDirectory(); 77 File xmlFile = new File (xmlPath, getId() + FileGroupManager.SUFFIX); 78 return xmlFile; 79 } 80 81 86 public void save() throws AccessControlException { 87 DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer(); 88 Configuration config = createConfiguration(); 89 File xmlfile = getFile(); 90 91 try { 92 serializer.serializeToFile(xmlfile, config); 93 } catch (Exception e) { 94 throw new AccessControlException(e); 95 } 96 } 97 98 101 public static final String GROUP = "group"; 102 103 108 private Configuration createConfiguration() { 109 DefaultConfiguration config = new DefaultConfiguration(GROUP); 110 new ItemConfiguration().save(this, config); 111 112 return config; 113 } 114 115 private File configurationDirectory; 116 117 121 protected File getConfigurationDirectory() { 122 return configurationDirectory; 123 } 124 125 128 public void setConfigurationDirectory(File configurationDirectory) { 129 assert (configurationDirectory != null) && configurationDirectory.isDirectory(); 130 this.configurationDirectory = configurationDirectory; 131 } 132 } 133 | Popular Tags |