Author: matzew
Date: Wed Jul 12 18:58:04 2006
New Revision: 421475
URL: http://svn.apache.org/viewvc?rev=421475&view=rev
Log:
added public setCurrentInstance() (see SHALE-199)
Modified:
shale/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext.java
Modified:
shale/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext.java
URL:
http://svn.apache.org/viewvc/shale/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext.java?rev=421475&r1=421474&r2=421475&view=diff
==============================================================================
---
shale/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext.java
(original)
+++
shale/trunk/shale-test/src/main/java/org/apache/shale/test/mock/MockFacesContext.java
Wed Jul 12 18:58:04 2006
@@ -1,309 +1,321 @@
-/*
- * Copyright 2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shale.test.mock;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.FactoryFinder;
-import javax.faces.application.Application;
-import javax.faces.application.FacesMessage;
-import javax.faces.application.FacesMessage.Severity;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseStream;
-import javax.faces.context.ResponseWriter;
-import javax.faces.lifecycle.Lifecycle;
-import javax.faces.render.RenderKit;
-import javax.faces.render.RenderKitFactory;
-
-
-/**
- * <p>Mock implementation of <code>FacesContext</code>.</p>
- *
- * $Id$
- */
-
-public class MockFacesContext extends FacesContext {
-
-
- // ------------------------------------------------------------
Constructors
-
-
- public MockFacesContext() {
- super();
- setCurrentInstance(this);
- }
-
-
- public MockFacesContext(ExternalContext externalContext) {
- setExternalContext(externalContext);
- setCurrentInstance(this);
- }
-
-
- public MockFacesContext(ExternalContext externalContext, Lifecycle
lifecycle) {
- this(externalContext);
- }
-
-
- // ----------------------------------------------------- Mock Object
Methods
-
-
- /**
- * <p>Set the <code>Application</code> instance for this instance.</p>
- *
- * @param application The new Application
- */
- public void setApplication(Application application) {
-
- this.application = application;
-
- }
-
-
- /**
- * <p>Set the <code>ExternalContext</code> instance for this instance.</p>
- *
- * @param externalContext The new ExternalContext
- */
- public void setExternalContext(ExternalContext externalContext) {
-
- this.externalContext = externalContext;
-
- }
-
-
- // ------------------------------------------------------ Instance
Variables
-
-
- private Application application = null;
- private ExternalContext externalContext = null;
- private Map messages = new HashMap();
- private boolean renderResponse = false;
- private boolean responseComplete = false;
- private ResponseStream responseStream = null;
- private ResponseWriter responseWriter = null;
- private UIViewRoot viewRoot = null;
-
-
- // ---------------------------------------------------- FacesContext
Methods
-
-
- /** [EMAIL PROTECTED] */
- public Application getApplication() {
-
- return this.application;
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public Iterator getClientIdsWithMessages() {
-
- return messages.keySet().iterator();
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public ExternalContext getExternalContext() {
-
- return this.externalContext;
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public Severity getMaximumSeverity() {
-
- Severity severity = null;
- Iterator messages = getMessages();
- while (messages.hasNext()) {
- FacesMessage message = (FacesMessage) messages.next();
- if (severity == null) {
- severity = message.getSeverity();
- } else if (message.getSeverity().getOrdinal() >
severity.getOrdinal()) {
- severity = message.getSeverity();
- }
- }
- return severity;
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public Iterator getMessages() {
-
- ArrayList results = new ArrayList();
- Iterator clientIds = messages.keySet().iterator();
- while (clientIds.hasNext()) {
- String clientId = (String) clientIds.next();
- results.addAll((List) messages.get(clientId));
- }
- return results.iterator();
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public Iterator getMessages(String clientId) {
-
- List list = (List) messages.get(clientId);
- if (list == null) {
- list = new ArrayList();
- }
- return list.iterator();
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public RenderKit getRenderKit() {
-
- UIViewRoot vr = getViewRoot();
- if (vr == null) {
- return null;
- }
- String renderKitId = vr.getRenderKitId();
- if (renderKitId == null) {
- return null;
- }
- RenderKitFactory rkFactory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- return rkFactory.getRenderKit(this, renderKitId);
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public boolean getRenderResponse() {
-
- return this.renderResponse;
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public boolean getResponseComplete() {
-
- return this.responseComplete;
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public ResponseStream getResponseStream() {
-
- return this.responseStream;
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public void setResponseStream(ResponseStream responseStream) {
-
- this.responseStream = responseStream;
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public ResponseWriter getResponseWriter() {
-
- return this.responseWriter;
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public void setResponseWriter(ResponseWriter responseWriter) {
-
- this.responseWriter = responseWriter;
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public UIViewRoot getViewRoot() {
-
- return this.viewRoot;
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public void setViewRoot(UIViewRoot viewRoot) {
-
- this.viewRoot = viewRoot;
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public void addMessage(String clientId, FacesMessage message) {
-
- if (message == null) {
- throw new NullPointerException();
- }
- List list = (List) messages.get(clientId);
- if (list == null) {
- list = new ArrayList();
- messages.put(clientId, list);
- }
- list.add(message);
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public void release() {
-
- application = null;
- externalContext = null;
- messages.clear();
- renderResponse = false;
- responseComplete = false;
- responseStream = null;
- responseWriter = null;
- viewRoot = null;
- setCurrentInstance(null);
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public void renderResponse() {
-
- this.renderResponse = true;
-
- }
-
-
- /** [EMAIL PROTECTED] */
- public void responseComplete() {
-
- this.responseComplete = true;
-
- }
-
-
-}
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.test.mock;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseStream;
+import javax.faces.context.ResponseWriter;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+
+
+/**
+ * <p>Mock implementation of <code>FacesContext</code>.</p>
+ *
+ * $Id$
+ */
+
+public class MockFacesContext extends FacesContext {
+
+
+ // ------------------------------------------------------------
Constructors
+
+
+ public MockFacesContext() {
+ super();
+ setCurrentInstance(this);
+ }
+
+
+ public MockFacesContext(ExternalContext externalContext) {
+ setExternalContext(externalContext);
+ setCurrentInstance(this);
+ }
+
+
+ public MockFacesContext(ExternalContext externalContext, Lifecycle
lifecycle) {
+ this(externalContext);
+ }
+
+
+ // ----------------------------------------------------- Mock Object
Methods
+
+
+ /**
+ * <p>Set the <code>Application</code> instance for this instance.</p>
+ *
+ * @param application The new Application
+ */
+ public void setApplication(Application application) {
+
+ this.application = application;
+
+ }
+
+
+ /**
+ * <p>Set the <code>ExternalContext</code> instance for this instance.</p>
+ *
+ * @param externalContext The new ExternalContext
+ */
+ public void setExternalContext(ExternalContext externalContext) {
+
+ this.externalContext = externalContext;
+
+ }
+
+
+ /**
+ * <p>Set the <code>FacesContext</code> instance for this instance.</p>
+ *
+ * @param facesContext The new FacesContext
+ */
+ public void setCurrentInstance(FacesContext facesContext) {
+
+ FacesContext.setCurrentInstance(facesContext);
+
+ }
+
+
+ // ------------------------------------------------------ Instance
Variables
+
+
+ private Application application = null;
+ private ExternalContext externalContext = null;
+ private Map messages = new HashMap();
+ private boolean renderResponse = false;
+ private boolean responseComplete = false;
+ private ResponseStream responseStream = null;
+ private ResponseWriter responseWriter = null;
+ private UIViewRoot viewRoot = null;
+
+
+ // ---------------------------------------------------- FacesContext
Methods
+
+
+ /** [EMAIL PROTECTED] */
+ public Application getApplication() {
+
+ return this.application;
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public Iterator getClientIdsWithMessages() {
+
+ return messages.keySet().iterator();
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public ExternalContext getExternalContext() {
+
+ return this.externalContext;
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public Severity getMaximumSeverity() {
+
+ Severity severity = null;
+ Iterator messages = getMessages();
+ while (messages.hasNext()) {
+ FacesMessage message = (FacesMessage) messages.next();
+ if (severity == null) {
+ severity = message.getSeverity();
+ } else if (message.getSeverity().getOrdinal() >
severity.getOrdinal()) {
+ severity = message.getSeverity();
+ }
+ }
+ return severity;
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public Iterator getMessages() {
+
+ ArrayList results = new ArrayList();
+ Iterator clientIds = messages.keySet().iterator();
+ while (clientIds.hasNext()) {
+ String clientId = (String) clientIds.next();
+ results.addAll((List) messages.get(clientId));
+ }
+ return results.iterator();
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public Iterator getMessages(String clientId) {
+
+ List list = (List) messages.get(clientId);
+ if (list == null) {
+ list = new ArrayList();
+ }
+ return list.iterator();
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public RenderKit getRenderKit() {
+
+ UIViewRoot vr = getViewRoot();
+ if (vr == null) {
+ return null;
+ }
+ String renderKitId = vr.getRenderKitId();
+ if (renderKitId == null) {
+ return null;
+ }
+ RenderKitFactory rkFactory = (RenderKitFactory)
+ FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ return rkFactory.getRenderKit(this, renderKitId);
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public boolean getRenderResponse() {
+
+ return this.renderResponse;
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public boolean getResponseComplete() {
+
+ return this.responseComplete;
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public ResponseStream getResponseStream() {
+
+ return this.responseStream;
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public void setResponseStream(ResponseStream responseStream) {
+
+ this.responseStream = responseStream;
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public ResponseWriter getResponseWriter() {
+
+ return this.responseWriter;
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public void setResponseWriter(ResponseWriter responseWriter) {
+
+ this.responseWriter = responseWriter;
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public UIViewRoot getViewRoot() {
+
+ return this.viewRoot;
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public void setViewRoot(UIViewRoot viewRoot) {
+
+ this.viewRoot = viewRoot;
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public void addMessage(String clientId, FacesMessage message) {
+
+ if (message == null) {
+ throw new NullPointerException();
+ }
+ List list = (List) messages.get(clientId);
+ if (list == null) {
+ list = new ArrayList();
+ messages.put(clientId, list);
+ }
+ list.add(message);
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public void release() {
+
+ application = null;
+ externalContext = null;
+ messages.clear();
+ renderResponse = false;
+ responseComplete = false;
+ responseStream = null;
+ responseWriter = null;
+ viewRoot = null;
+ setCurrentInstance(null);
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public void renderResponse() {
+
+ this.renderResponse = true;
+
+ }
+
+
+ /** [EMAIL PROTECTED] */
+ public void responseComplete() {
+
+ this.responseComplete = true;
+
+ }
+
+
+}