1 16 package org.outerj.daisy.repository.commonimpl.acl; 17 18 import org.outerj.daisy.repository.acl.*; 19 import org.outerx.daisy.x10.AclObjectDocument; 20 import org.outerx.daisy.x10.AclEntryDocument; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 public final class AclObjectImpl implements AclObject { 26 private String objectExpr; 27 private Object compiledExpr; 28 private ArrayList entries = new ArrayList (); 29 private AclImpl ownerAcl; 30 private IntimateAccess intimateAccess = new IntimateAccess(); 31 private AclStrategy aclStrategy; 32 33 public AclObjectImpl(AclImpl ownerAcl, AclStrategy aclStrategy, String objectExpr) { 34 if (objectExpr == null) 35 throw new NullPointerException ("objectExpr cannot be null"); 36 37 this.objectExpr = objectExpr; 38 this.ownerAcl = ownerAcl; 39 this.aclStrategy = aclStrategy; 40 } 41 42 public IntimateAccess getIntimateAccess(AclStrategy aclStrategy) { 43 if (aclStrategy == this.aclStrategy) 44 return intimateAccess; 45 else 46 return null; 47 } 48 49 protected AclImpl getOwner() { 50 return ownerAcl; 51 } 52 53 public String getObjectExpr() { 54 return objectExpr; 55 } 56 57 public void setObjectExpr(String expr) { 58 if (ownerAcl.isReadOnly()) 59 throw new RuntimeException (AclImpl.READ_ONLY_MESSAGE); 60 61 if (expr == null) 62 throw new NullPointerException ("expr cannot be null"); 63 64 this.objectExpr = expr; 65 this.compiledExpr = null; 66 } 67 68 public AclEntry createNewEntry(AclSubjectType subjectType, long subjectValue) { 69 if (ownerAcl.isReadOnly()) 70 throw new RuntimeException (AclImpl.READ_ONLY_MESSAGE); 71 72 return new AclEntryImpl(ownerAcl, subjectType, subjectValue); 73 } 74 75 public AclEntry get(int index) { 76 return (AclEntry)entries.get(index); 77 } 78 79 public void remove(int index) { 80 if (ownerAcl.isReadOnly()) 81 throw new RuntimeException (AclImpl.READ_ONLY_MESSAGE); 82 83 entries.remove(index); 84 } 85 86 public void add(AclEntry aclEntry) { 87 preAddChecks(aclEntry); 88 entries.add(aclEntry); 89 } 90 91 private void preAddChecks(AclEntry aclEntry) { 92 if (ownerAcl.isReadOnly()) 93 throw new RuntimeException (AclImpl.READ_ONLY_MESSAGE); 94 95 if (aclEntry == null) 96 throw new NullPointerException ("null AclEntry not allowed."); 97 98 if (!(aclEntry instanceof AclEntryImpl)) 99 throw new RuntimeException ("Incorrect AclEntry implementation provided, only the ones obtained using createNewEntry() on this AclObject may be used."); 100 101 if (((AclEntryImpl)aclEntry).getOwner() != ownerAcl) 102 throw new RuntimeException ("The specified AclEntry belongs to a different Acl, it cannot be added to this AclObject."); 103 } 104 105 public void add(int index, AclEntry aclEntry) { 106 preAddChecks(aclEntry); 107 entries.add(index, aclEntry); 108 } 109 110 public void clear() { 111 if (ownerAcl.isReadOnly()) 112 throw new RuntimeException (AclImpl.READ_ONLY_MESSAGE); 113 114 entries.clear(); 115 } 116 117 public int size() { 118 return entries.size(); 119 } 120 121 public AclObjectDocument getXml() { 122 AclObjectDocument aclObjectDocument = AclObjectDocument.Factory.newInstance(); 123 AclObjectDocument.AclObject aclObject = aclObjectDocument.addNewAclObject(); 124 125 aclObject.setExpression(objectExpr); 126 127 AclEntryDocument.AclEntry[] aclEntriesXml = new AclEntryDocument.AclEntry[entries.size()]; 128 for (int i = 0; i < aclEntriesXml.length; i++) { 129 AclEntry aclEntry = (AclEntry)entries.get(i); 130 aclEntriesXml[i] = aclEntry.getXml().getAclEntry(); 131 } 132 133 aclObject.setAclEntryArray(aclEntriesXml); 134 135 return aclObjectDocument; 136 } 137 138 public class IntimateAccess { 139 private IntimateAccess() { 140 } 141 142 public List getEntries() { 143 return entries; 144 } 145 146 public void setCompiledExpression(Object compiledExpression) { 147 compiledExpr = compiledExpression; 148 } 149 150 public Object getCompiledExpression() { 151 return compiledExpr; 152 } 153 } 154 } 155 | Popular Tags |