001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.engine;
016
017 import org.apache.hivemind.util.Defense;
018 import org.apache.tapestry.IDirect;
019 import org.apache.tapestry.IDynamicInvoker;
020
021 import java.util.Collection;
022
023 /**
024 * Parameter object used by {@link org.apache.tapestry.engine.DirectService}.
025 *
026 * @author Howard M. Lewis Ship
027 * @since 4.0
028 */
029 public class DirectServiceParameter
030 {
031 private IDirect _direct;
032
033 private Object[] _serviceParameters;
034
035 private String[] _updateParts;
036
037 private boolean _json;
038
039 private boolean _async;
040
041 public DirectServiceParameter(IDirect direct)
042 {
043 this(direct, null);
044 }
045
046 public DirectServiceParameter(IDirect direct, Object[] serviceParameters)
047 {
048 this(direct, serviceParameters, null);
049 }
050
051 public DirectServiceParameter(IDirect direct, Object[] serviceParameters, IDynamicInvoker invoker)
052 {
053 Defense.notNull(direct, "direct");
054
055 _direct = direct;
056 _serviceParameters = serviceParameters;
057
058 if (invoker == null) {
059
060 Collection comps = direct.getUpdateComponents();
061 if (comps == null)
062 _updateParts = new String[0];
063 else
064 _updateParts = (String[])comps.toArray(new String[comps.size()]);
065
066 _json = direct.isJson();
067 _async = direct.isAsync();
068 } else {
069
070 Collection comps = invoker.getUpdateComponents();
071 if (comps == null)
072 _updateParts = new String[0];
073 else
074 _updateParts = (String[])comps.toArray(new String[comps.size()]);
075
076 _json = invoker.isJson();
077 _async = invoker.isAsync();
078 }
079
080 // if they gave only an updateComponents param make it async by default
081
082 if (!_json && !_async && _updateParts.length > 0)
083 _async = true;
084 }
085
086 public IDirect getDirect()
087 {
088 return _direct;
089 }
090
091 public Object[] getServiceParameters()
092 {
093 return _serviceParameters;
094 }
095
096 public String[] getUpdateParts()
097 {
098 return _updateParts;
099 }
100
101 public boolean isJson()
102 {
103 return _json;
104 }
105
106 public boolean isAsync()
107 {
108 return _async;
109 }
110 }