1 19 20 package com.sslexplorer.policyframework; 21 22 import com.sslexplorer.boot.Util; 23 import com.sslexplorer.core.CoreAttributeConstants; 24 import com.sslexplorer.core.CoreEvent; 25 import com.sslexplorer.security.SessionInfo; 26 27 33 public class ResourceChangeEvent extends CoreEvent { 34 35 private Resource resource; 36 37 46 public ResourceChangeEvent(Object source, int id, 47 SessionInfo session, Throwable exception) { 48 super(source, id, exception, session, STATE_UNSUCCESSFUL); 49 addAttribute(CoreAttributeConstants.EVENT_ATTR_EXCEPTION_MESSAGE, 50 Util.getExceptionMessageChain(exception)); 51 52 53 } 54 55 64 public ResourceChangeEvent(Object source, int id, Resource resource, 65 SessionInfo session, int state) { 66 super(source, id, resource, session, state); 67 this.resource = resource; 68 if(state == CoreEvent.STATE_UNSUCCESSFUL || ( state == CoreEvent.STATE_SUCCESSFUL && resource != null) ) { 69 if(resource != null) { 70 if (resource.getResourceId() != -1){ 71 addAttribute(CoreAttributeConstants.EVENT_ATTR_RESOURCE_NAME, resource.getResourceName()); 72 addAttribute(CoreAttributeConstants.EVENT_ATTR_RESOURCE_DESCRIPTION, resource.getResourceDescription()); 73 } 74 if(resource instanceof OwnedResource) { 75 OwnedResource or = (OwnedResource)resource; 76 if(or.getOwnerUsername() != null) { 77 addAttribute(CoreAttributeConstants.EVENT_ATTR_RESOURCE_OWNER, or.getOwnerUsername()); 78 } 79 } 80 } 81 } 82 else { 83 throw new IllegalArgumentException ("Must provide a non-null resource if the event was successful."); 84 } 85 } 86 87 92 public Resource getResource() { 93 return resource; 94 } 95 96 } 97 | Popular Tags |