View Javadoc

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  import fulmine.Domain;
19  import fulmine.Type;
20  import fulmine.event.EventFrameExecution;
21  import fulmine.model.container.IContainer;
22  import fulmine.model.field.IField;
23  
24  /**
25   * A remote update handler that allows remote contexts to change the state of
26   * local containers as long as the permissions are valid.
27   * 
28   * @author Ramon Servadei
29   */
30  public class RemoteUpdateHandler implements IRemoteUpdateHandler
31  {
32      /** The context */
33      IFulmineContext context;
34  
35      /**
36       * Construct the handler with its context
37       */
38      public RemoteUpdateHandler()
39      {
40          super();
41      }
42  
43      public String handle(String identity, int type, int domain,
44          String fieldName, String valueAsString, int permissionApp,
45          int permissionCode, String originatingRemoteContextIdentity)
46      {
47          if (domain == Domain.FRAMEWORK.value())
48          {
49              return "Cannot update a framework container: " + identity;
50          }
51          final IContainer container =
52              this.context.getLocalContainer(identity, Type.get(type),
53                  Domain.get(domain));
54          final IField field = container.get(fieldName);
55          if (field != null
56              && this.context.getPermissionProfile().matches(
57                  (byte) permissionApp, (short) permissionCode,
58                  field.getApplication(), field.getPermission()))
59          {
60              container.beginFrame(new EventFrameExecution());
61              try
62              {
63                  field.setValueFromString(valueAsString);
64              }
65              finally
66              {
67                  container.endFrame();
68              }
69              return "Success";
70          }
71          return "Operation not permissioned for application=" + permissionApp
72              + ", permission=" + permissionCode;
73      }
74  
75      public void setContext(IFulmineContext context)
76      {
77          this.context = context;
78      }
79  
80  }