1 16 17 package org.apache.jetspeed.om.registry.base; 18 19 import java.io.ByteArrayInputStream ; 20 import java.io.ByteArrayOutputStream ; 21 import java.io.ObjectInputStream ; 22 import java.io.ObjectOutputStream ; 23 24 import org.apache.jetspeed.om.registry.RegistryEntry; 25 import org.apache.jetspeed.om.registry.InvalidEntryException; 26 import org.apache.jetspeed.om.registry.RegistryException; 27 import org.apache.jetspeed.om.registry.SecurityEntry; 28 import org.apache.jetspeed.services.Registry; 29 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 30 import org.apache.jetspeed.services.logging.JetspeedLogger; 31 32 44 public class BaseSecurityRegistry extends BaseRegistry 45 { 46 47 50 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(BaseSecurityRegistry.class.getName()); 51 52 55 public void setEntry( RegistryEntry entry ) throws InvalidEntryException 56 { 57 60 try 61 { 62 Registry.addEntry(Registry.SECURITY, entry); 63 } 64 catch (RegistryException e) 65 { 66 logger.error("Exception", e); 67 } 68 } 69 70 73 public void addEntry( RegistryEntry entry ) throws InvalidEntryException 74 { 75 78 try 79 { 80 Registry.addEntry(Registry.SECURITY, entry); 81 } 82 catch (RegistryException e) 83 { 84 logger.error("Exception", e); 85 } 86 } 87 88 91 public void removeEntry( String name ) 92 { 93 96 Registry.removeEntry(Registry.SECURITY, name); 97 } 98 99 102 public void removeEntry( RegistryEntry entry ) 103 { 104 107 if (entry != null) 108 { 109 Registry.removeEntry(Registry.SECURITY, entry.getName()); 110 } 111 } 112 113 119 public RegistryEntry createEntry() 120 { 121 return new BaseSecurityEntry(); 122 } 123 124 130 public SecurityEntry getSecurityEntry(String name) 131 { 132 try 133 { 134 return (SecurityEntry) this.getEntry(name); 135 } 136 catch (InvalidEntryException e) 137 { 138 logger.error("Exception", e); 139 } 140 141 return null; 142 } 143 144 147 public SecurityEntry createSecurityEntry() 148 { 149 return (SecurityEntry) this.createEntry(); 150 } 151 152 159 public SecurityEntry cloneSecurityEntry(String original, String newName) 160 { 161 SecurityEntry baseEntry = getSecurityEntry(original); 162 if (baseEntry != null) 163 { 164 SecurityEntry newEntry = cloneEntry(baseEntry); 165 newEntry.setName(newName); 166 return newEntry; 167 } 168 169 return null; 170 } 171 172 173 179 private static SecurityEntry cloneEntry(SecurityEntry secEntry) 180 { 181 SecurityEntry clonedEntry = null; 182 try 183 { 184 ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream (100); 185 ObjectOutputStream objectoutputstream = new ObjectOutputStream (bytearrayoutputstream); 186 objectoutputstream.writeObject(secEntry); 187 byte abyte0[] = bytearrayoutputstream.toByteArray(); 188 objectoutputstream.close(); 189 ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream (abyte0); 190 ObjectInputStream objectinputstream = new ObjectInputStream (bytearrayinputstream); 191 clonedEntry = (SecurityEntry) objectinputstream.readObject(); 192 objectinputstream.close(); 193 } 194 catch (Exception exception) 195 { 196 } 198 return clonedEntry; 199 } 200 } 201 | Popular Tags |