1 /* 2 Copyright 2009 Ramon Servadei 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 package fulmine.context; 17 18 /** 19 * An object that handles update operations, issued from remote contexts, to 20 * local containers. The updates occur using the RPC mechanism. 21 * 22 * @author Ramon Servadei 23 */ 24 public interface IRemoteUpdateHandler 25 { 26 /** The name for the 'update remote container' RPC */ 27 String RPC_NAME = "handle"; 28 29 /** The RPC key for the 'update remote container' RPC */ 30 String RPC_KEY = RPC_NAME + "SIISSIIS"; 31 32 /** 33 * Holds the argument positions for the 34 * {@link IRemoteUpdateHandler#handle(String, int, int, String, String, int, int, String)} 35 * method. 36 * 37 * @author Ramon Servadei 38 */ 39 enum ARG_POSITIONS 40 { 41 IDENTITY, 42 TYPE, 43 DOMAIN, 44 FIELD_NAME, 45 VALUE_AS_STRING, 46 PERMISSION_APP, 47 PERMISSION_CODE, 48 ORIGINATING_CONTEXT 49 } 50 51 /** 52 * Handle the RPC call to update a local container from a remote context. 53 * 54 * @param identity 55 * the container identity, used to locate the container 56 * @param type 57 * the container type, used to locate the container 58 * @param domain 59 * the container domain, used to locate the container 60 * @param fieldName 61 * the field in the container to update 62 * @param valueAsString 63 * the new value for the field, in string form 64 * @param permissionApp 65 * the application permission of the context issuing the change, 66 * see {@link IPermissionProfile} 67 * @param permissionCode 68 * the permission of the context issuing the change, see 69 * {@link IPermissionProfile} 70 * @param originatingRemoteContextIdentity 71 * the identity of the remote context issuing the command 72 * @return a string indicating the status of the operation 73 */ 74 String handle(String identity, int type, int domain, String fieldName, 75 String valueAsString, int permissionApp, int permissionCode, 76 String originatingRemoteContextIdentity); 77 78 /** 79 * Setter for the context 80 * 81 * @param context 82 * the context 83 */ 84 void setContext(IFulmineContext context); 85 } 86 87 /** 88 * A handler that does not allow any updates to local containers from remote 89 * contexts. 90 * 91 * @author Ramon Servadei 92 */ 93 final class VetoingRemoteUpdateHandler implements IRemoteUpdateHandler 94 { 95 public String handle(String identity, int type, int domain, 96 String fieldName, String valueAsString, int permissionApp, 97 int permissionCode, String remoteContextIdentity) 98 { 99 return "Operation not permitted"; 100 } 101 102 public void setContext(IFulmineContext context) 103 { 104 // noop 105 } 106 } 107 108 /** 109 * A handler that delegates the operations to an internal delegate. 110 * 111 * @author Ramon Servadei 112 */ 113 final class DelegatingRemoteUpdateHandler implements IRemoteUpdateHandler 114 { 115 /** The delegate */ 116 IRemoteUpdateHandler delegate; 117 118 public String handle(String identity, int type, int domain, 119 String fieldName, String valueAsString, int permissionApp, 120 int permissionCode, String remoteContextIdentity) 121 { 122 return this.delegate.handle(identity, type, domain, fieldName, 123 valueAsString, permissionApp, permissionCode, remoteContextIdentity); 124 } 125 126 final IRemoteUpdateHandler getDelegate() 127 { 128 return this.delegate; 129 } 130 131 final void setDelegate(IRemoteUpdateHandler delegate) 132 { 133 this.delegate = delegate; 134 } 135 136 public void setContext(IFulmineContext context) 137 { 138 // noop 139 } 140 }