001: /*
002: ItsNat Java Web Application Framework
003: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004: Author: Jose Maria Arranz Santamaria
005:
006: This program is free software: you can redistribute it and/or modify
007: it under the terms of the GNU Affero General Public License as published by
008: the Free Software Foundation, either version 3 of the License, or
009: (at your option) any later version. See the GNU Affero General Public
010: License for more details. See the copy of the GNU Affero General Public License
011: included in this program. If not, see <http://www.gnu.org/licenses/>.
012: */
013:
014: package org.itsnat.impl.core.event.fromserv;
015:
016: import java.util.EventObject;
017: import java.util.HashMap;
018: import java.util.Map;
019: import org.itsnat.core.ItsNatDocument;
020: import org.itsnat.core.ItsNatServletRequest;
021: import org.itsnat.core.ItsNatServletResponse;
022: import org.itsnat.core.SyncMode;
023: import org.itsnat.core.event.ItsNatEvent;
024: import org.itsnat.impl.core.ItsNatDocumentImpl;
025: import org.itsnat.impl.core.ItsNatServletRequestImpl;
026: import org.itsnat.impl.core.util.UserDataImpl;
027:
028: /**
029: *
030: * @author jmarranz
031: */
032: public abstract class ServerItsNatEventImpl extends EventObject
033: implements ItsNatEvent {
034: protected UserDataImpl userData; // No hace falta sincronizar, deberá accederse en monohilo
035: protected Map extraParams;
036:
037: /** Creates a new instance of ServerItsNatEventImpl */
038: public ServerItsNatEventImpl(ItsNatDocumentImpl itsNatDoc) {
039: super (itsNatDoc);
040: }
041:
042: public ItsNatDocument getItsNatDocument() {
043: return getItsNatDocumentImpl();
044: }
045:
046: public ItsNatDocumentImpl getItsNatDocumentImpl() {
047: return (ItsNatDocumentImpl) getSource();
048: }
049:
050: public int getSyncMode() {
051: return SyncMode.SYNC;
052: }
053:
054: public ItsNatServletRequest getItsNatServletRequest() {
055: // Por devolver algo, es raro que sea null pues lo normal es que
056: // todo lo que se hace en una app. web esté dentro de una request del client al servidor
057: return getItsNatDocumentImpl().getCurrentItsNatServletRequest();
058: }
059:
060: public ItsNatServletResponse getItsNatServletResponse() {
061: // Por devolver algo
062: ItsNatServletRequestImpl request = getItsNatDocumentImpl()
063: .getCurrentItsNatServletRequest();
064: if (request == null)
065: return null; // por si acaso
066: return request.getItsNatServletResponseImpl();
067: }
068:
069: public UserDataImpl getUserData() {
070: if (userData == null)
071: this .userData = new UserDataImpl(); // Para ahorrar memoria si no se usa. No es necesario sincronizar pues el evento es manejado por un unico hilo
072: return userData;
073: }
074:
075: public boolean containsUserValueName(String name) {
076: return getUserData().containsName(name);
077: }
078:
079: public String[] getUserValueNames() {
080: return getUserData().getUserDataNames();
081: }
082:
083: public Object getUserValue(String name) {
084: return getUserData().getUserData(name);
085: }
086:
087: public Object setUserValue(String name, Object value) {
088: return getUserData().setUserData(name, value);
089: }
090:
091: public Object removeUserValue(String name) {
092: return getUserData().removeUserData(name);
093: }
094:
095: public boolean hasExtraParams() {
096: if (extraParams == null)
097: return false;
098: return !extraParams.isEmpty();
099: }
100:
101: public Map getExtraParams() {
102: if (extraParams == null)
103: this .extraParams = new HashMap();
104: return extraParams;
105: }
106:
107: public Object getExtraParam(String name) {
108: if (!hasExtraParams())
109: return null;
110: return getExtraParams().get(name);
111: }
112:
113: public void setExtraParam(String name, Object value) {
114: getExtraParams().put(name, value);
115: }
116:
117: }
|