View Javadoc

1   // $Id: AbstractXSObjectCommand.java 165 2009-05-28 21:46:38Z agony $
2   /*
3    * xsAnalyzer - XML schema analyzing tool. Copyright (C) 2008 Michael Engelhardt
4    * 
5    * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6    * License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7    * version.
8    * 
9    * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
10   * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11   * 
12   * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
13   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14   */
15  /**
16   * 
17   */
18  package de.mindcrimeilab.xsanalyzer.actions;
19  
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.apache.xerces.xs.XSObject;
24  import org.springframework.binding.value.ValueModel;
25  import org.springframework.richclient.command.ActionCommand;
26  
27  import de.mindcrimeilab.util.Accessor;
28  
29  /**
30   * 
31   * @author Michael Engelhardt<me@mindcrime-ilab.de>
32   * 
33   * @author $Author: agony $
34   * 
35   * @version $Revision: 165 $
36   */
37  public abstract class AbstractXSObjectCommand extends ActionCommand {
38  
39      private ValueModel valueModel;
40  
41      private Accessor accessor;
42  
43      /**
44       * @param commandId
45       */
46      public AbstractXSObjectCommand(String commandId, ValueModel valueModel, Accessor accessor) {
47          super(commandId);
48          this.valueModel = valueModel;
49          this.accessor = accessor;
50      }
51  
52      /**
53       * @return the accessor
54       */
55      public Accessor<XSObject, ? super Object> getAccessor() {
56          return accessor;
57      }
58  
59      /**
60       * @param accessor
61       *            the accessor to set
62       */
63      public void setAccessor(Accessor accessor) {
64          this.accessor = accessor;
65      }
66  
67      /**
68       * @return the valueModel
69       */
70      public ValueModel getValueModel() {
71          return valueModel;
72      }
73  
74      /**
75       * @param valueModel
76       *            the valueModel to set
77       */
78      public void setValueModel(ValueModel valueModel) {
79          this.valueModel = valueModel;
80      }
81  
82      protected abstract void executeWrappedExecutor(Map<String, XSObject> parameter);
83  
84      @Override
85      protected void doExecuteCommand() {
86          Map<String, XSObject> parameter = new HashMap<String, XSObject>();
87          final Object object = ((Object[]) valueModel.getValue())[0];
88          final XSObject target;
89          if (null != accessor) {
90              target = (XSObject) accessor.getValue(object);
91          }
92          else {
93              target = (XSObject) object;
94          }
95  
96          assert target instanceof XSObject;
97  
98          parameter.put(TypeHierarchyExecutor.TARGET_OBJECT, target);
99          logger.debug("Getting value from ValueModel [" + valueModel.getValue() + "]");
100         executeWrappedExecutor(parameter);
101     }
102 
103 }