001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.lenya.cms.usecase;
019:
020: import java.util.List;
021:
022: import org.apache.cocoon.servlet.multipart.Part;
023: import org.apache.lenya.cms.repository.Session;
024:
025: /**
026: * Usecase interface.
027: *
028: * @version $Id: Usecase.java 568271 2007-08-21 20:49:18Z andreas $
029: */
030: public interface Usecase {
031:
032: /**
033: * The <code>Usecase</code> role.
034: */
035: String ROLE = Usecase.class.getName();
036:
037: /**
038: * @param url The URL the usecase is invoked on.
039: */
040: void setSourceURL(String url);
041:
042: /**
043: * Sets a parameter from the form.
044: * @param name The parameter name.
045: * @param value The parameter value.
046: */
047: void setParameter(String name, Object value);
048:
049: /**
050: * Returns the current value of a parameter.
051: * @param name The parameter name.
052: * @return An object.
053: */
054: Object getParameter(String name);
055:
056: /**
057: * Returns the current value of a parameter.
058: * @param name The parameter name.
059: * @param defaultValue The default value to return if the parameter is not set.
060: * @return An object.
061: */
062: Object getParameter(String name, Object defaultValue);
063:
064: /**
065: * Returns the current value of a parameter as a string.
066: * @param name The parameter name.
067: * @return A string or <code>null</code> if the parameter was not set.
068: */
069: String getParameterAsString(String name);
070:
071: /**
072: * @return The parameter names.
073: */
074: String[] getParameterNames();
075:
076: /**
077: * Sets a parameter from the form. This method is called for parts in
078: * multipart requests.
079: * @param name The parameter name.
080: * @param value The parameter value.
081: */
082: void setPart(String name, Part value);
083:
084: /**
085: * Returns the current value of a part parameter as a string.
086: * @param name The part parameter name.
087: * @return A part or <code>null</code> if the part was not set.
088: */
089: Part getPart(String name);
090:
091: /**
092: * Advances the usecase to the next step. This method is called when all
093: * parameters are set.
094: * @throws UsecaseException if an error occurs.
095: */
096: void advance() throws UsecaseException;
097:
098: /**
099: * Checks the conditions before a form is displayed.
100: * @throws UsecaseException if an error occurs that causes an unstable
101: * system.
102: */
103: void checkPreconditions() throws UsecaseException;
104:
105: /**
106: * Checks the conditions after the usecase was executed.
107: * @throws UsecaseException if an error occurs that causes an unstable
108: * system.
109: */
110: void checkPostconditions() throws UsecaseException;
111:
112: /**
113: * Checks the conditions right before the operation is executed.
114: * @throws UsecaseException if an error occurs that causes an unstable
115: * system.
116: */
117: void checkExecutionConditions() throws UsecaseException;
118:
119: /**
120: * Locks all objects that are involved in the transaction.
121: * @throws UsecaseException if an error occurs.
122: */
123: void lockInvolvedObjects() throws UsecaseException;
124:
125: /**
126: * Returns the error messages from the previous operation. Error messages
127: * prevent the operation from being executed.
128: * @return A list of {@link UsecaseMessage} objects.
129: */
130: List getErrorMessages();
131:
132: /**
133: * Returns the info messages from the previous operation. Info messages do
134: * not prevent the operation from being executed.
135: * @return A list of {@link UsecaseMessage} objects.
136: */
137: List getInfoMessages();
138:
139: /**
140: * Determine if the usecase has error messages.
141: * Provides a way of checking for errors without actually retrieving them.
142: * @return true if the usecase resulted in error messages.
143: */
144: public boolean hasErrors();
145:
146: /**
147: * Determine if the usecase has info messages.
148: * Provides a way of checking for info messages without actually retrieving them.
149: * @return true if the usecase resulted in info messages being generated.
150: */
151: public boolean hasInfoMessages();
152:
153: /**
154: * Executes the usecase. During this method error and info messages are
155: * filled in. If getErrorMessages() returns an empty array, the operation
156: * succeeded. Otherwise, the operation failed.
157: * @throws UsecaseException if an error occured that causes an unstable
158: * system.
159: */
160: void execute() throws UsecaseException;
161:
162: /**
163: * Cancels the usecase.
164: * @throws UsecaseException if an error occurs.
165: */
166: void cancel() throws UsecaseException;
167:
168: /**
169: * @return The web application URL the usecase was invoked on.
170: */
171: String getSourceURL();
172:
173: /**
174: * Returns the webapp URL which should be redirected to after the usecase is
175: * completed.
176: * @param success If the usecase was completed successfully.
177: * @return A web application URL.
178: */
179: String getTargetURL(boolean success);
180:
181: /**
182: * @param name The name of this usecase.
183: */
184: void setName(String name);
185:
186: /**
187: * @return The name of this usecase.
188: */
189: String getName();
190:
191: /**
192: * @return The view of the usecase.
193: */
194: UsecaseView getView();
195:
196: /**
197: * @param view The view of the usecase.
198: */
199: void setView(UsecaseView view);
200:
201: /**
202: * @return The repository session.
203: */
204: Session getSession();
205:
206: /**
207: * If you invoke this method, the usecase won't use its own isolated session,
208: * but the passed test session. The session will not be committed when the usecase
209: * is invoked, so you can check it for modifications without modifying the repository.
210: * @param session The test session.
211: */
212: void setTestSession(Session session);
213:
214: /**
215: * @return if the usecase uses optimistic offline lock.
216: */
217: boolean isOptimistic();
218: }
|