Skip to Content.
Sympa Menu

notify-dpml - r1009 - in trunk/main: depot/tools/builder/src/main/net/dpml/tools/tasks planet/web/server/src/main/net/dpml/web/server planet/web/test/src/main/org/acme

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1009 - in trunk/main: depot/tools/builder/src/main/net/dpml/tools/tasks planet/web/server/src/main/net/dpml/web/server planet/web/test/src/main/org/acme
  • Date: Wed, 1 Feb 2006 19:05:36 +0100

Author: mcconnell
Date: 2006-02-01 19:05:34 +0100 (Wed, 01 Feb 2006)
New Revision: 1009

Modified:

trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/FeatureTask.java
trunk/main/planet/web/server/src/main/net/dpml/web/server/Server.java
trunk/main/planet/web/test/src/main/org/acme/ChatFilter.java
Log:
housekeeping

Modified:
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/FeatureTask.java
===================================================================
---
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/FeatureTask.java
2006-02-01 17:42:32 UTC (rev 1008)
+++
trunk/main/depot/tools/builder/src/main/net/dpml/tools/tasks/FeatureTask.java
2006-02-01 18:05:34 UTC (rev 1009)
@@ -18,6 +18,8 @@

package net.dpml.tools.tasks;

+import java.io.File;
+
import net.dpml.library.model.ResourceNotFoundException;
import net.dpml.library.model.Resource;

@@ -183,6 +185,30 @@
return path + "#" + version;
}
}
+ else if( m_feature.equals( "path" ) )
+ {
+ if( null == m_type )
+ {
+ final String error =
+ "Type attribute must be supplied in conjuction with the
uri attribute.";
+ throw new BuildException( error, getLocation() );
+ }
+ else
+ {
+ Artifact artifact = resource.getArtifact( m_type );
+ try
+ {
+ File cached = (File) artifact.toURL().getContent( new
Class[]{File.class});
+ return cached.getCanonicalPath();
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unable to resolve resource path.";
+ throw new BuildException( error, e, getLocation() );
+ }
+ }
+ }
else if( m_feature.equals( "filename" ) )
{
if( null == m_type )

Modified:
trunk/main/planet/web/server/src/main/net/dpml/web/server/Server.java
===================================================================
--- trunk/main/planet/web/server/src/main/net/dpml/web/server/Server.java
2006-02-01 17:42:32 UTC (rev 1008)
+++ trunk/main/planet/web/server/src/main/net/dpml/web/server/Server.java
2006-02-01 18:05:34 UTC (rev 1009)
@@ -55,10 +55,10 @@
{
super();

- getLogger().debug( "commancing http server deployment" );
m_logger = logger;
m_context = context;

+ getLogger().debug( "commancing http server deployment" );
URI standard = new URI( "local:xml:dpml/planet/web/jetty" );
URI uri = context.getConfiguration( standard );
Thread.currentThread().setContextClassLoader(
getClass().getClassLoader() );

Modified: trunk/main/planet/web/test/src/main/org/acme/ChatFilter.java
===================================================================
--- trunk/main/planet/web/test/src/main/org/acme/ChatFilter.java
2006-02-01 17:42:32 UTC (rev 1008)
+++ trunk/main/planet/web/test/src/main/org/acme/ChatFilter.java
2006-02-01 18:05:34 UTC (rev 1009)
@@ -1,17 +1,19 @@
-//========================================================================
-//$Id: ChatFilter.java,v 1.4 2005/11/14 11:00:33 gregwilkins Exp $
-//Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
-//------------------------------------------------------------------------
-//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.
-//========================================================================
+/*
+ * Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
+ * Copyright 2006 Stephen McConnell.
+ *
+ * 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.acme;

@@ -31,213 +33,233 @@
import org.mortbay.util.ajax.ContinuationSupport;

public class ChatFilter extends AjaxFilter
-{
+{
private final String mutex="mutex";
private Map chatroom;

-
- /* ------------------------------------------------------------ */
- /*
- * @see org.mortbay.ajax.AjaxFilter#init(javax.servlet.FilterConfig)
- */
- public void init(FilterConfig filterConfig) throws ServletException
+ /**
+ * @param filterConfig the filter configuration
+ * @exception ServletException if a servlet exception occurs
+ * @see org.mortbay.ajax.AjaxFilter#init(javax.servlet.FilterConfig)
+ */
+ public void init( FilterConfig filterConfig ) throws ServletException
{
super.init(filterConfig);
chatroom=new HashMap();
}

- /* ------------------------------------------------------------ */
- /*
- * @see org.mortbay.ajax.AjaxFilter#destroy()
- */
+ /**
+ * Destroy the instance.
+ * @see org.mortbay.ajax.AjaxFilter#destroy()
+ */
public void destroy()
{
super.destroy();
chatroom=null;
}

- /* ------------------------------------------------------------ */
- /*
- * @see org.mortbay.ajax.AjaxFilter#handle(java.lang.String,
javax.servlet.http.HttpServletRequest,
org.mortbay.ajax.AjaxFilter.AjaxResponse)
- */
- public void handle(String method, HttpServletRequest request,
AjaxResponse response)
+ /**
+ * Handle a request.
+ * @param method the method name
+ * @param request the request
+ * @param response the response
+ * @see org.mortbay.ajax.AjaxFilter#handle(java.lang.String,
javax.servlet.http.HttpServletRequest,
org.mortbay.ajax.AjaxFilter.AjaxResponse)
+ */
+ public void handle( String method, HttpServletRequest request,
AjaxResponse response )
{
- if ("join".equals(method))
- doJoinChat(request,response);
- else if ("chat".equals(method))
- doChat(request,response);
- else if ("getEvents".equals(method))
+ if( "join".equals( method ) )
+ {
+ doJoinChat( request, response );
+ }
+ else if( "chat".equals( method ) )
+ {
+ doChat( request, response );
+ }
+ else if( "getEvents".equals( method ) )
+ {
doGetEvents(request,response);
- else if ("leave".equals(method))
+ }
+ else if( "leave".equals( method ) )
+ {
doLeaveChat(request,response);
+ }
else
- super.handle(method, request, response);
+ {
+ super.handle(method, request, response);
+ }
}
-
- /* ------------------------------------------------------------ */
- private void doJoinChat(HttpServletRequest request, AjaxResponse
response)
+
+ private void doJoinChat( HttpServletRequest request, AjaxResponse
response )
{
- HttpSession session = request.getSession(true);
+ HttpSession session = request.getSession( true );
String id = session.getId();
- String name=request.getParameter("name");
- if (name==null || name.length()==0)
- name="Newbie";
- Member member=null;
+ String name = request.getParameter( "name" );
+ if( name == null || name.length() == 0 )
+ {
+ name = "Newbie";
+ }

- synchronized (mutex)
+ Member member = null;
+
+ synchronized( mutex )
{
- if (chatroom.containsKey(id))
+ if( chatroom.containsKey( id ) )
{
// exists already, so just update name
- member=(Member)chatroom.get(id);
- if (!name.equals(member.getName()))
- member.rename(name);
+ member = (Member) chatroom.get( id );
+ if( !name.equals( member.getName() ) )
+ {
+ member.rename( name );
+ }
}
else
{
- member = new Member(session,name);
- chatroom.put(session.getId(),member);
- sendEvent(member,"has joined the chat",true);
+ member = new Member( session, name );
+ chatroom.put( session.getId(), member );
+ sendEvent( member, "has joined the chat", true );
}

- sendMembers(response);
- response.objectResponse("joined", "<ok/>");
+ sendMembers( response );
+ response.objectResponse( "joined", "<ok/>" );
}
}

-
- /* ------------------------------------------------------------ */
- private void doLeaveChat(HttpServletRequest request, AjaxResponse
response)
+ private void doLeaveChat( HttpServletRequest request, AjaxResponse
response )
{
HttpSession session = request.getSession(true);
String id = session.getId();

Member member=null;
- synchronized (mutex)
+ synchronized( mutex )
{
- member = (Member)chatroom.get(id);
- if (member==null)
+ member = (Member) chatroom.get( id );
+ if( member==null )
+ {
return;
- if ("Elvis".equals(member.getName()))
- sendEvent(member,"has left the building",true);
+ }
+ if( "Elvis".equals( member.getName() ) )
+ {
+ sendEvent( member, "has left the building", true );
+ }
else
- sendEvent(member,"has left the chat",true);
+ {
+ sendEvent( member, "has left the chat", true );
+ }
chatroom.remove(id);
}
- sendMembers(response);
- response.objectResponse("left", "<ok/>");
+ sendMembers( response );
+ response.objectResponse( "left", "<ok/>" );
}

-
- /* ------------------------------------------------------------ */
- private void doChat(HttpServletRequest request, AjaxResponse response)
+ private void doChat( HttpServletRequest request, AjaxResponse response )
{
- HttpSession session = request.getSession(true);
+ HttpSession session = request.getSession( true );
String id = session.getId();
- String text = request.getParameter("text");
+ String text = request.getParameter( "text" );

- Member member=null;
- synchronized (mutex)
+ Member member = null;
+ synchronized( mutex )
{
- member = (Member)chatroom.get(id);
+ member = (Member) chatroom.get( id );
}

- if (member==null)
+ if( member == null )
+ {
return;
- sendEvent(member, text, false);
-
+ }
+ sendEvent( member, text, false );
}


- /* ------------------------------------------------------------ */
- private void doGetEvents(HttpServletRequest request, AjaxResponse
response)
+ private void doGetEvents( HttpServletRequest request, AjaxResponse
response )
{
- HttpSession session = request.getSession(true);
+ HttpSession session = request.getSession( true );
String id = session.getId();
- long timeoutMS = 10000L; // TODO configure.
+ long timeoutMS = 10000L;

Member member=null;
- synchronized (mutex)
+ synchronized( mutex )
{
- member = (Member)chatroom.get(id);
+ member = (Member) chatroom.get( id );
}

- boolean alerts=false;
- if (member!=null)
+ boolean alerts = false;
+ if( member != null )
{
// Get an existing Continuation or create a new one if there are
no events.
- if (!member.hasEvents())
+ if( !member.hasEvents() )
{
- Continuation continuation =
ContinuationSupport.getContinuation(request, mutex);
- member.setContinuation(continuation);
- continuation.suspend(timeoutMS);
+ Continuation continuation =
ContinuationSupport.getContinuation( request, mutex );
+ member.setContinuation( continuation );
+ continuation.suspend( timeoutMS );
}

- member.setContinuation(null);
- alerts=member.sendEvents(response);
+ member.setContinuation( null );
+ alerts = member.sendEvents( response );

- if (alerts)
- sendMembers(response);
-
+ if( alerts )
+ {
+ sendMembers( response );
+ }
// Signal for a new poll
- response.objectResponse("poll", "<ok/>");
+ response.objectResponse( "poll", "<ok/>" );
}
}

- /* ------------------------------------------------------------ */
- private void sendEvent(Member member, String text, boolean alert)
+ private void sendEvent( Member member, String text, boolean alert )
{
- Event event=new Event(member.getName(),text,alert);
+ Event event = new Event( member.getName(), text, alert );

- ArrayList invalids=null;
- synchronized (mutex)
+ ArrayList invalids = null;
+ synchronized( mutex )
{
Iterator iter = chatroom.values().iterator();
- while (iter.hasNext())
+ while( iter.hasNext() )
{
- Member m = (Member)iter.next();
+ Member m = (Member) iter.next();

try
{
- m.getSession().getAttribute("anything");
- m.addEvent(event);
+ m.getSession().getAttribute( "anything" );
+ m.addEvent( event );
}
- catch(IllegalStateException e)
+ catch( IllegalStateException e )
{
- if (invalids==null)
+ if( invalids==null )
+ {
invalids=new ArrayList();
- invalids.add(m);
+ }
+ invalids.add( m );
iter.remove();
}
}
}

- for (int i=0;invalids!=null && i<invalids.size();i++)
+ for( int i=0; invalids != null && i< invalids.size(); i++ )
{
- Member m = (Member)invalids.get(i);
- sendEvent(m,"has timed out of the chat",true);
+ Member m = (Member) invalids.get( i );
+ sendEvent( m, "has timed out of the chat", true );
}
}

- private void sendMembers(AjaxResponse response)
+ private void sendMembers( AjaxResponse response )
{
StringBuffer buf = new StringBuffer();
buf.append("<ul>\n");
- synchronized (mutex)
+ synchronized( mutex )
{
Iterator iter = chatroom.values().iterator();
- while (iter.hasNext())
+ while( iter.hasNext() )
{
- Member m = (Member)iter.next();
- buf.append("<li>");
- buf.append(encodeText(m.getName()));
- buf.append("</li>\n");
+ Member m = (Member) iter.next();
+ buf.append( "<li>" );
+ buf.append( encodeText( m.getName() ) );
+ buf.append( "</li>\n" );
}
}
- buf.append("</ul>\n");
- response.elementResponse("members", buf.toString());
+ buf.append( "</ul>\n" );
+ response.elementResponse( "members", buf.toString() );
}
-

private static class Event
{
@@ -245,11 +267,11 @@
private String _text;
private boolean _alert;

- Event(String from, String text, boolean alert)
+ Event( String from, String text, boolean alert )
{
- _from=from;
- _text=text;
- _alert=alert;
+ _from = from;
+ _text = text;
+ _alert = alert;
}

boolean isAlert()
@@ -259,11 +281,14 @@

public String toString()
{
- return "<event from=\""+_from+"\"
alert=\""+_alert+"\">"+encodeText(_text)+"</event>";
+ return "<event from=\""
+ +_from
+ + "\" alert=\""
+ + _alert
+ + "\">"
+ + encodeText( _text )
+ + "</event>";
}
-
-
-
}

private class Member
@@ -273,13 +298,12 @@
private List _events = new ArrayList();
private Continuation _continuation;

- Member(HttpSession session, String name)
+ Member( HttpSession session, String name )
{
_session=session;
_name=name;
}

- /* ------------------------------------------------------------ */
/**
* @return Returns the name.
*/
@@ -288,16 +312,14 @@
return _name;
}

- /* ------------------------------------------------------------ */
/**
* @param name The name to set.
*/
- public void setName(String name)
+ public void setName( String name )
{
_name = name;
}

- /* ------------------------------------------------------------ */
/**
* @return Returns the session.
*/
@@ -306,7 +328,6 @@
return _session;
}

- /* ------------------------------------------------------------ */
/**
* @return Returns the continuation.
*/
@@ -315,56 +336,52 @@
return _continuation;
}

- /* ------------------------------------------------------------ */
/**
* @param continuation The continuation to set.
*/
- public void setContinuation(Continuation continuation)
+ public void setContinuation( Continuation continuation )
{
_continuation = continuation;
}

- /* ------------------------------------------------------------ */
- public void addEvent(Event event)
+ public void addEvent( Event event )
{
- synchronized (this)
+ synchronized( this )
{
- _events.add(event);
- if (_continuation!=null)
+ _events.add( event );
+ if( _continuation!=null )
+ {
_continuation.resume();
+ }
}
}

- /* ------------------------------------------------------------ */
public boolean hasEvents()
{
- return _events!=null && _events.size()>0;
+ return _events != null && _events.size() > 0;
}

- /* ------------------------------------------------------------ */
- public void rename(String name)
+ public void rename( String name )
{
String oldName = getName();
- setName(name);
- ChatFilter.this.sendEvent(this,oldName+" has been renamed to
"+name,true);
+ setName( name );
+ ChatFilter.this.sendEvent( this, oldName + " has been renamed to
" + name, true );
}

- /* ------------------------------------------------------------ */
- public boolean sendEvents(AjaxResponse response)
+ public boolean sendEvents( AjaxResponse response )
{
- synchronized (this)
+ synchronized( this )
{
boolean alerts=false;
- for (int i=0;i<_events.size();i++)
+ for( int i=0; i< _events.size(); i++ )
{
- Event event = (Event)_events.get(i);
- response.objectResponse("event", event.toString());
+ Event event = (Event) _events.get( i );
+ response.objectResponse( "event", event.toString() );
alerts |= event.isAlert();
}
_events.clear();
return alerts;
}
}
-
}
}




  • r1009 - in trunk/main: depot/tools/builder/src/main/net/dpml/tools/tasks planet/web/server/src/main/net/dpml/web/server planet/web/test/src/main/org/acme, mcconnell at BerliOS, 02/01/2006

Archive powered by MHonArc 2.6.24.

Top of Page