You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2005/03/30 18:27:05 UTC
cvs commit: jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/valid TestNumberValidator.java
hlship 2005/03/30 08:27:05
Modified: . .classpath
framework/src/test/org/apache/tapestry/describe
TestHTMLDescriptionReceiver.java
config common.properties
framework/src/java/org/apache/tapestry/describe
HTMLDescriptionReceiver.java RenderBridge.java
RenderableAdapterFactory.java
HTMLDescriberImpl.java
RenderableAdapterFactoryImpl.java
framework/src/descriptor/META-INF tapestry.describe.xml
tapestry.asset.xml
portlet/src/descriptor/META-INF hivemodule.xml
framework/src/java/org/apache/tapestry/valid
NumberValidator.java
framework/src/java/org/apache/tapestry/util/io
ISqueezeAdaptor.java DataSqueezerImpl.java
framework/src/java/org/apache/tapestry/coerce
TypeConverterWrapper.java
framework/src/test/org/apache/tapestry/junit/valid
TestNumberValidator.java
Added: framework/src/test/org/apache/tapestry/describe
TestRenderStrategy.java
TestLocationRenderStrategy.java
framework/src/java/org/apache/tapestry/describe
DescribableStrategy.java
LocationRenderStrategy.java DefaultStrategy.java
DefaultRenderStrategy.java
ServletContextStrategy.java
HttpServletRequestStrategy.java NativeStrategy.java
HttpSessionStrategy.java CookieStrategy.java
RenderStrategy.java ServletStrategy.java
portlet/src/java/org/apache/tapestry/portlet
PortletSessionDescribableStrategy.java
Removed: framework/src/test/org/apache/tapestry/describe
TestRenderableAdapter.java
TestLocationRenderableAdapter.java
framework/src/java/org/apache/tapestry/describe
ServletDescribableAdapter.java
DefaultDescribableAdapter.java
LocationRenderableAdapter.java
CookieDescribableAdapter.java
DefaultRenderableAdapter.java
NativeDescribableAdapter.java
DescribableAdapter.java RenderableAdapter.java
HttpSessionDescribableAdapter.java
ServletContextDescribableAdapter.java
HttpServletRequestDescriber.java
portlet/src/java/org/apache/tapestry/portlet
PortletSessionDescribableAdapter.java
Log:
Rename interfaces and classes related to rendering and describing, to reflect that they are Gang-of-Four Strategies (not really adaptors).
Revision Changes Path
1.77 +2 -2 jakarta-tapestry/.classpath
Index: .classpath
===================================================================
RCS file: /home/cvs/jakarta-tapestry/.classpath,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -r1.76 -r1.77
--- .classpath 29 Mar 2005 13:50:23 -0000 1.76
+++ .classpath 30 Mar 2005 16:27:04 -0000 1.77
@@ -31,7 +31,7 @@
<classpathentry kind="lib" path="ext-package/lib/jboss-j2ee-3.2.1.jar"/>
<classpathentry kind="lib" path="ext-package/lib/portlet-api-1.0.jar"/>
<classpathentry kind="lib" path="ext-package/lib/jcharts-0.6.0.jar"/>
- <classpathentry kind="lib" path="ext-package/lib/hivemind-1.1-alpha-3.jar"/>
- <classpathentry kind="lib" path="ext-package/lib/hivemind-lib-1.1-alpha-3.jar"/>
+ <classpathentry kind="lib" path="ext-package/lib/hivemind-1.1-alpha-4-snapshot.jar"/>
+ <classpathentry kind="lib" path="ext-package/lib/hivemind-lib-1.1-alpha-4-snapshot.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1.4 +30 -28 jakarta-tapestry/framework/src/test/org/apache/tapestry/describe/TestHTMLDescriptionReceiver.java
Index: TestHTMLDescriptionReceiver.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/describe/TestHTMLDescriptionReceiver.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestHTMLDescriptionReceiver.java 30 Mar 2005 14:32:52 -0000 1.3
+++ TestHTMLDescriptionReceiver.java 30 Mar 2005 16:27:04 -0000 1.4
@@ -31,12 +31,12 @@
*/
public class TestHTMLDescriptionReceiver extends BaseDescribeTestCase
{
- protected DescribableAdapter newAdapter()
+ protected DescribableStrategy newStrategy()
{
- return (DescribableAdapter) newMock(DescribableAdapter.class);
+ return (DescribableStrategy) newMock(DescribableStrategy.class);
}
- public static class NoopAdapterFixture implements DescribableAdapter
+ public static class NoOpStrategy implements DescribableStrategy
{
public void describeObject(Object object, DescriptionReceiver receiver)
{
@@ -98,7 +98,7 @@
public void testSetTitleTwiceFails()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy adapter = newStrategy();
replayControls();
@@ -123,7 +123,7 @@
public void testSetSectionBeforeTitleFails()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy adapter = newStrategy();
replayControls();
@@ -145,7 +145,7 @@
public void testIntProperty()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy adapter = newStrategy();
trainForTitle(writer, "Object Title");
trainForSection(writer, "Section");
@@ -165,7 +165,7 @@
public void testPropertiesWithoutSection()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy adapter = newStrategy();
trainForTitle(writer, "Object Title");
trainForKeyValue(writer, "first", "1");
@@ -197,7 +197,7 @@
public void testFinishWithProperties()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy adapter = newStrategy();
trainForTitle(writer, "Object Title");
trainForKeyValue(writer, "first", "1");
@@ -224,7 +224,7 @@
public void testFinishNoPropertiesNoTitle()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy adapter = newStrategy();
String object = "Fred";
@@ -243,7 +243,7 @@
public void testFinishNoPropertiesWithTitle()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy adapter = newStrategy();
String object = "Fred";
@@ -264,7 +264,7 @@
public void testArray()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = new NoopAdapterFixture();
+ DescribableStrategy adapter = new NoOpStrategy();
Object[] array = new Object[]
{ "Fred", "Barney" };
@@ -286,7 +286,7 @@
public void testCollection()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = new NoopAdapterFixture();
+ DescribableStrategy adapter = new NoOpStrategy();
Object[] array = new Object[]
{ "Fred", "Barney" };
@@ -309,11 +309,11 @@
public void testArrayNullAndEmpty()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy strategy = newStrategy();
replayControls();
- HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, adapter);
+ HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, strategy);
dr.title("Array");
dr.array("null", null);
@@ -325,11 +325,11 @@
public void testCollectionNullAndEmpty()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy strategy = newStrategy();
replayControls();
- HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, adapter);
+ HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, strategy);
dr.title("Collection");
dr.collection("null", null);
@@ -341,7 +341,7 @@
public void testScalarProperties()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy strategy = newStrategy();
trainForTitle(writer, "Scalars");
trainForKeyValue(writer, "boolean", "true");
@@ -355,7 +355,7 @@
replayControls();
- HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, adapter);
+ HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, strategy);
dr.title("Scalars");
dr.property("boolean", true);
@@ -373,13 +373,13 @@
public void testNullRoot()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy strategy = newStrategy();
writer.print(HTMLDescriptionReceiver.NULL_VALUE);
replayControls();
- HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, adapter);
+ HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, strategy);
dr.describe(null);
@@ -389,14 +389,14 @@
public void testNullProperty()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy strategy = newStrategy();
trainForTitle(writer, "Null Property");
trainForKeyValue(writer, "null", HTMLDescriptionReceiver.NULL_VALUE);
replayControls();
- HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, adapter);
+ HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, strategy);
dr.title("Null Property");
dr.property("null", null);
@@ -408,7 +408,7 @@
public void testHTMLDescriber()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = new NoopAdapterFixture();
+ DescribableStrategy strategy = new NoOpStrategy();
String object = "Tapestry";
@@ -418,7 +418,7 @@
replayControls();
HTMLDescriberImpl d = new HTMLDescriberImpl();
- d.setAdapter(adapter);
+ d.setStrategy(strategy);
d.describeObject(object, writer);
@@ -428,13 +428,13 @@
public void testDescribeAlternate()
{
IMarkupWriter writer = newWriter();
- DescribableAdapter adapter = newAdapter();
+ DescribableStrategy strategy = newStrategy();
Object alternate = new Object();
- HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, adapter);
+ HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, strategy);
- adapter.describeObject(alternate, dr);
+ strategy.describeObject(alternate, dr);
replayControls();
@@ -450,7 +450,9 @@
Registry r = RegistryBuilder.constructDefaultRegistry();
// The Portlet code, which may be in the classpath under Eclipse, adds a second
// implementation.
- HTMLDescriber d = (HTMLDescriber) r.getService("tapestry.describe.HTMLDescriber", HTMLDescriber.class);
+ HTMLDescriber d = (HTMLDescriber) r.getService(
+ "tapestry.describe.HTMLDescriber",
+ HTMLDescriber.class);
writer.print("Tapestry");
writer.println();
1.1 jakarta-tapestry/framework/src/test/org/apache/tapestry/describe/TestRenderStrategy.java
Index: TestRenderStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRender;
import org.apache.tapestry.IRequestCycle;
/**
* Tests for {@link org.apache.tapestry.describe.RenderableAdapterFactoryImpl},
* {@link org.apache.tapestry.describe.RenderBridge}and
* {@link org.apache.tapestry.describe.DefaultRenderStrategy}.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class TestRenderStrategy extends BaseDescribeTestCase
{
private RenderStrategy newStrategy()
{
return (RenderStrategy) newMock(RenderStrategy.class);
}
public void testRenderBridge()
{
IMarkupWriter writer = newWriter();
RenderStrategy strategy = newStrategy();
IRequestCycle cycle = newCycle();
Object object = new Object();
strategy.renderObject(object, writer, cycle);
replayControls();
new RenderBridge(object, strategy).render(writer, cycle);
verifyControls();
}
public void testRenderableAdapterFactory()
{
IMarkupWriter writer = newWriter();
RenderStrategy strategy = newStrategy();
IRequestCycle cycle = newCycle();
Object object = new Object();
strategy.renderObject(object, writer, cycle);
replayControls();
RenderableAdapterFactoryImpl factory = new RenderableAdapterFactoryImpl();
factory.setStrategy(strategy);
IRender renderable = factory.getRenderableAdaptor(object);
renderable.render(writer, cycle);
verifyControls();
}
public void testDefaultRenderableAdapter()
{
IMarkupWriter writer = newWriter();
HTMLDescriber describer = newDescriber();
IRequestCycle cycle = newCycle();
Object object = new Object();
describer.describeObject(object, writer);
replayControls();
DefaultRenderStrategy strategy = new DefaultRenderStrategy();
strategy.setDescriber(describer);
strategy.renderObject(object, writer, cycle);
verifyControls();
}
}
1.1 jakarta-tapestry/framework/src/test/org/apache/tapestry/describe/TestLocationRenderStrategy.java
Index: TestLocationRenderStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
import java.net.URL;
import org.apache.hivemind.Location;
import org.apache.hivemind.Resource;
import org.apache.hivemind.impl.LocationImpl;
import org.apache.hivemind.util.URLResource;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.easymock.MockControl;
/**
* Tests for {@link org.apache.tapestry.describe.LocationRenderStrategy}.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class TestLocationRenderStrategy extends BaseDescribeTestCase
{
private Resource newResource(URL url)
{
MockControl control = newControl(Resource.class);
Resource resource = (Resource) control.getMock();
resource.getResourceURL();
control.setReturnValue(url);
return resource;
}
private Location newLocation(String file, int lineNumber)
{
URL url = getClass().getResource(file);
Resource resource = new URLResource(url);
return new LocationImpl(resource, lineNumber);
}
private void train(IMarkupWriter writer, int startLine, int lineNumber, String[] lines)
{
writer.beginEmpty("br");
writer.begin("table");
writer.attribute("class", "location-content");
for (int i = 0; i < lines.length; i++)
{
int currentLine = startLine + i;
writer.begin("tr");
if (currentLine == lineNumber)
writer.attribute("class", "target-line");
writer.begin("td");
writer.attribute("class", "line-number");
writer.print(currentLine);
writer.end();
writer.begin("td");
writer.print(lines[i]);
writer.end("tr");
writer.println();
}
writer.end("table");
}
public void testNoURL()
{
IMarkupWriter writer = newWriter();
IRequestCycle cycle = newCycle();
Resource resource = newResource(null);
MockControl lc = newControl(Location.class);
Location l = (Location) lc.getMock();
l.getResource();
lc.setReturnValue(resource);
writer.print(l.toString());
replayControls();
new LocationRenderStrategy().renderObject(l, writer, cycle);
verifyControls();
}
/**
* Test when the highlight line is close to the end of the document.
*/
public void testShortContent()
{
IMarkupWriter writer = newWriter();
IRequestCycle cycle = newCycle();
Location l = newLocation("Short.txt", 7);
writer.print(l.toString());
train(writer, 2, 7, new String[]
{ "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" });
replayControls();
new LocationRenderStrategy().renderObject(l, writer, cycle);
verifyControls();
}
/**
* Test when the highlight line is close to the end of the document.
*/
public void testLongContent()
{
IMarkupWriter writer = newWriter();
IRequestCycle cycle = newCycle();
Location l = newLocation("Long.txt", 3);
writer.print(l.toString());
train(writer, 1, 3, new String[]
{ "Line One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight" });
replayControls();
new LocationRenderStrategy().renderObject(l, writer, cycle);
verifyControls();
}
}
1.40 +1 -1 jakarta-tapestry/config/common.properties
Index: common.properties
===================================================================
RCS file: /home/cvs/jakarta-tapestry/config/common.properties,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- common.properties 26 Mar 2005 22:14:46 -0000 1.39
+++ common.properties 30 Mar 2005 16:27:04 -0000 1.40
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-hivemind.version=1.1-alpha-3
+hivemind.version=1.1-alpha-4-snapshot
javassist.version=3.0-rc-1
ognl.version=2.6.7
codec.version=1.3
1.4 +8 -8 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/HTMLDescriptionReceiver.java
Index: HTMLDescriptionReceiver.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/HTMLDescriptionReceiver.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- HTMLDescriptionReceiver.java 29 Mar 2005 22:19:54 -0000 1.3
+++ HTMLDescriptionReceiver.java 30 Mar 2005 16:27:04 -0000 1.4
@@ -44,24 +44,24 @@
private String _section;
- private DescribableAdapter _adapter;
+ private DescribableStrategy _strategy;
private HTMLDescriptionReceiverStyles _styles;
- public HTMLDescriptionReceiver(IMarkupWriter writer, DescribableAdapter adapter)
+ public HTMLDescriptionReceiver(IMarkupWriter writer, DescribableStrategy adapter)
{
this(writer, adapter, new HTMLDescriptionReceiverStyles());
}
- public HTMLDescriptionReceiver(IMarkupWriter writer, DescribableAdapter adapter,
+ public HTMLDescriptionReceiver(IMarkupWriter writer, DescribableStrategy strategy,
HTMLDescriptionReceiverStyles styles)
{
Defense.notNull(writer, "writer");
- Defense.notNull(adapter, "adapter");
+ Defense.notNull(strategy, "strategy");
Defense.notNull(styles, "styles");
_writer = writer;
- _adapter = adapter;
+ _strategy = strategy;
_styles = styles;
}
@@ -73,14 +73,14 @@
return;
}
- _adapter.describeObject(object, this);
+ _strategy.describeObject(object, this);
finishUp(object);
}
public void describeAlternate(Object alternate)
{
- _adapter.describeObject(alternate, this);
+ _strategy.describeObject(alternate, this);
}
void finishUp(Object object)
@@ -198,7 +198,7 @@
return;
}
- new HTMLDescriptionReceiver(_writer, _adapter, _styles).describe(value);
+ new HTMLDescriptionReceiver(_writer, _strategy, _styles).describe(value);
}
public void property(String key, boolean value)
1.2 +7 -7 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/RenderBridge.java
Index: RenderBridge.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/RenderBridge.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RenderBridge.java 7 Mar 2005 19:51:53 -0000 1.1
+++ RenderBridge.java 30 Mar 2005 16:27:04 -0000 1.2
@@ -20,8 +20,8 @@
import org.apache.tapestry.IRequestCycle;
/**
- * Implements {@link IRender}for a particular object by delegating to a
- * {@link org.apache.tapestry.describe.RenderableAdapter}.
+ * Implements {@link IRender} for a particular object by delegating to a
+ * {@link org.apache.tapestry.describe.RenderStrategy}.
*
* @author Howard M. Lewis Ship
* @since 3.1
@@ -30,18 +30,18 @@
{
private Object _object;
- private RenderableAdapter _adapter;
+ private RenderStrategy _strategy;
- public RenderBridge(Object object, RenderableAdapter adapter)
+ public RenderBridge(Object object, RenderStrategy strategy)
{
- Defense.notNull(adapter, "adapter");
+ Defense.notNull(strategy, "strategy");
_object = object;
- _adapter = adapter;
+ _strategy = strategy;
}
public void render(IMarkupWriter writer, IRequestCycle cycle)
{
- _adapter.renderObject(_object, writer, cycle);
+ _strategy.renderObject(_object, writer, cycle);
}
}
\ No newline at end of file
1.2 +2 -1 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/RenderableAdapterFactory.java
Index: RenderableAdapterFactory.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/RenderableAdapterFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RenderableAdapterFactory.java 7 Mar 2005 19:51:53 -0000 1.1
+++ RenderableAdapterFactory.java 30 Mar 2005 16:27:04 -0000 1.2
@@ -18,7 +18,8 @@
/**
* A source of light-weight objects that can render a particular object. This is a more pure
- * implementation of the GoF Adapter pattern.
+ * implementation of the GoF Adapter pattern, based on wrapping a
+ * {@link org.apache.tapestry.describe.RenderStrategy}.
*
* @author Howard M. Lewis Ship
* @since 3.1
1.3 +4 -4 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/HTMLDescriberImpl.java
Index: HTMLDescriberImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/HTMLDescriberImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HTMLDescriberImpl.java 29 Mar 2005 22:19:54 -0000 1.2
+++ HTMLDescriberImpl.java 30 Mar 2005 16:27:04 -0000 1.3
@@ -22,20 +22,20 @@
*/
public class HTMLDescriberImpl implements HTMLDescriber
{
- private DescribableAdapter _adapter;
+ private DescribableStrategy _strategy;
private HTMLDescriptionReceiverStyles _styles = new HTMLDescriptionReceiverStyles();
public void describeObject(Object object, IMarkupWriter writer)
{
- HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, _adapter, _styles);
+ HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, _strategy, _styles);
dr.describe(object);
}
- public void setAdapter(DescribableAdapter adapter)
+ public void setStrategy(DescribableStrategy strategy)
{
- _adapter = adapter;
+ _strategy = strategy;
}
public void setTableClass(String tableClass)
1.2 +4 -4 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/RenderableAdapterFactoryImpl.java
Index: RenderableAdapterFactoryImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/RenderableAdapterFactoryImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RenderableAdapterFactoryImpl.java 7 Mar 2005 19:51:54 -0000 1.1
+++ RenderableAdapterFactoryImpl.java 30 Mar 2005 16:27:04 -0000 1.2
@@ -22,18 +22,18 @@
*/
public class RenderableAdapterFactoryImpl implements RenderableAdapterFactory
{
- private RenderableAdapter _adapter;
+ private RenderStrategy _strategy;
/**
* Returns a new instance of {@link RenderBridge}.
*/
public IRender getRenderableAdaptor(Object object)
{
- return new RenderBridge(object, _adapter);
+ return new RenderBridge(object, _strategy);
}
- public void setAdapter(RenderableAdapter adapter)
+ public void setStrategy(RenderStrategy adapter)
{
- _adapter = adapter;
+ _strategy = adapter;
}
}
\ No newline at end of file
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/DescribableStrategy.java
Index: DescribableStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
/**
* Strategy class allowing objects that don't implement
* {@link org.apache.tapestry.describe.Describable} to be described.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public interface DescribableStrategy
{
public void describeObject(Object object, DescriptionReceiver receiver);
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/LocationRenderStrategy.java
Index: LocationRenderStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.Reader;
import java.net.URL;
import org.apache.hivemind.Location;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
/**
* Adapter for displaying {@link org.apache.hivemind.Location} objects as HTML. This may
* include showing the content of the {@link org.apache.hivemind.Resource}, with the line indicated
* in the Location highlighted.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class LocationRenderStrategy implements RenderStrategy
{
/**
* Lines before and after the actual location to display.
*/
private static final int RANGE = 5;
public void renderObject(Object object, IMarkupWriter writer, IRequestCycle cycle)
{
Location l = (Location) object;
// Always print out the location as a string.
writer.print(l.toString());
URL url = l.getResource().getResourceURL();
if (url == null)
return;
writeResourceContent(writer, url, l.getLineNumber());
}
private void writeResourceContent(IMarkupWriter writer, URL url, int lineNumber)
{
LineNumberReader reader = null;
try
{
reader = new LineNumberReader(new BufferedReader(
new InputStreamReader(url.openStream())));
writer.beginEmpty("br");
writer.begin("table");
writer.attribute("class", "location-content");
while (true)
{
String line = reader.readLine();
if (line == null)
break;
int currentLine = reader.getLineNumber();
if (currentLine > lineNumber + RANGE)
break;
if (currentLine < lineNumber - RANGE)
continue;
writer.begin("tr");
if (currentLine == lineNumber)
writer.attribute("class", "target-line");
writer.begin("td");
writer.attribute("class", "line-number");
writer.print(currentLine);
writer.end();
writer.begin("td");
writer.print(line);
writer.end("tr");
writer.println();
}
reader.close();
reader = null;
}
catch (Exception ex)
{
// Ignore it.
}
finally
{
writer.end("table");
close(reader);
}
}
private void close(Reader reader)
{
try
{
if (reader != null)
reader.close();
}
catch (IOException ex)
{
// Ignore
}
}
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/DefaultStrategy.java
Index: DefaultStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
/**
* Catch-all implementation (for java.lang.Object) that does nothing.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class DefaultStrategy implements DescribableStrategy
{
public void describeObject(Object object, DescriptionReceiver receiver)
{
// Does nothing, which results in the object's toString().
}
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/DefaultRenderStrategy.java
Index: DefaultRenderStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
/**
* Default implementation that delegates to the {@link org.apache.tapestry.describe.HTMLDescriber}
* service.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class DefaultRenderStrategy implements RenderStrategy
{
private HTMLDescriber _describer;
/**
* Invokes {@link HTMLDescriber#describeObject(Object, IMarkupWriter)}.
*/
public void renderObject(Object object, IMarkupWriter writer, IRequestCycle cycle)
{
_describer.describeObject(object, writer);
}
public void setDescriber(HTMLDescriber describer)
{
_describer = describer;
}
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/ServletContextStrategy.java
Index: ServletContextStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
import java.util.Iterator;
import javax.servlet.ServletContext;
import org.apache.tapestry.web.WebUtils;
/**
* Describes a {@link javax.servlet.ServletContext}.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class ServletContextStrategy implements DescribableStrategy
{
public void describeObject(Object object, DescriptionReceiver receiver)
{
ServletContext context = (ServletContext) object;
receiver.title("ServletContext");
receiver.property("serverInfo", context.getServerInfo());
receiver.property("version", context.getMajorVersion() + "." + context.getMinorVersion());
receiver.section("Attributes");
Iterator i = WebUtils.toSortedList(context.getAttributeNames()).iterator();
while (i.hasNext())
{
String key = (String) i.next();
receiver.property(key, context.getAttribute(key));
}
receiver.section("Initialization Parameters");
i = WebUtils.toSortedList(context.getInitParameterNames()).iterator();
while (i.hasNext())
{
String key = (String) i.next();
receiver.property(key, context.getInitParameter(key));
}
}
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/HttpServletRequestStrategy.java
Index: HttpServletRequestStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.tapestry.web.WebUtils;
/**
* Strategy for describing an {@link javax.servlet.http.HttpServletRequest}.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class HttpServletRequestStrategy implements DescribableStrategy
{
public void describeObject(Object object, DescriptionReceiver receiver)
{
HttpServletRequest request = (HttpServletRequest) object;
receiver.title("HttpServletRequest");
receiver.property("authType", request.getAuthType());
receiver.property("characterEncoding", request.getCharacterEncoding());
receiver.property("contentLength", request.getContentLength());
receiver.property("contextPath", request.getContextPath());
receiver.property("contentType", request.getContentType());
receiver.array("cookies", request.getCookies());
receiver.property("locale", request.getLocale());
receiver.property("method", request.getMethod());
receiver.property("pathInfo", request.getPathInfo());
receiver.property("pathTranslated", request.getPathTranslated());
receiver.property("protocol", request.getProtocol());
receiver.property("queryString", request.getQueryString());
receiver.property("requestURI", request.getRequestURI());
receiver.property("scheme", request.getScheme());
receiver.property("secure", request.isSecure());
receiver.property("serverName", request.getServerName());
receiver.property("serverPort", request.getServerPort());
receiver.property("servletPath", request.getServletPath());
receiver.property("userPrincipal", request.getUserPrincipal());
receiver.section("Parameters");
List keys = WebUtils.toSortedList(request.getParameterNames());
Iterator i = keys.iterator();
while (i.hasNext())
{
String key = (String) i.next();
String[] values = request.getParameterValues(key);
receiver.array(key, values);
}
receiver.section("Headers");
keys = WebUtils.toSortedList(request.getHeaderNames());
i = keys.iterator();
while (i.hasNext())
{
String key = (String) i.next();
String value = request.getHeader(key);
receiver.property(key, value);
}
receiver.section("Attributes");
keys = WebUtils.toSortedList(request.getAttributeNames());
i = keys.iterator();
while (i.hasNext())
{
String key = (String) i.next();
Object value = request.getAttribute(key);
receiver.property(key, value);
}
}
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/NativeStrategy.java
Index: NativeStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
/**
* Implementation for objects that natively implement
* {@link org.apache.tapestry.describe.Describable}.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class NativeStrategy implements DescribableStrategy
{
public void describeObject(Object object, DescriptionReceiver receiver)
{
Describable d = (Describable) object;
d.describeTo(receiver);
}
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/HttpSessionStrategy.java
Index: HttpSessionStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
import java.util.Date;
import java.util.Iterator;
import javax.servlet.http.HttpSession;
import org.apache.tapestry.web.WebUtils;
/**
* Describes an {@link javax.servlet.http.HttpSession}.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class HttpSessionStrategy implements DescribableStrategy
{
public void describeObject(Object object, DescriptionReceiver receiver)
{
HttpSession session = (HttpSession) object;
receiver.title("HttpSession");
receiver.property("creationTime", new Date(session.getCreationTime()));
receiver.property("id", session.getId());
receiver.property("lastAccessedTime", new Date(session.getLastAccessedTime()));
receiver.property("maxInactiveInterval", session.getMaxInactiveInterval());
receiver.property("new", session.isNew());
receiver.section("Attributes");
Iterator i = WebUtils.toSortedList(session.getAttributeNames()).iterator();
while (i.hasNext())
{
String key = (String) i.next();
receiver.property(key, session.getAttribute(key));
}
}
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/CookieStrategy.java
Index: CookieStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
import javax.servlet.http.Cookie;
/**
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class CookieStrategy implements DescribableStrategy
{
public void describeObject(Object object, DescriptionReceiver receiver)
{
Cookie cookie = (Cookie) object;
receiver.title("Cookie: " + cookie.getName());
receiver.property("comment", cookie.getComment());
receiver.property("domain", cookie.getDomain());
receiver.property("maxAge", cookie.getMaxAge());
receiver.property("path", cookie.getPath());
receiver.property("secure", cookie.getSecure());
receiver.property("value", cookie.getValue());
receiver.property("version", cookie.getVersion());
}
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/RenderStrategy.java
Index: RenderStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
/**
* A strategy interface for rendering an object (even if it doesn't implement
* {@link org.apache.tapestry.IRender}).
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public interface RenderStrategy
{
public void renderObject(Object object, IMarkupWriter writer, IRequestCycle cycle);
}
1.1 jakarta-tapestry/framework/src/java/org/apache/tapestry/describe/ServletStrategy.java
Index: ServletStrategy.java
===================================================================
// Copyright 2005 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.tapestry.describe;
import java.util.Iterator;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import org.apache.tapestry.web.WebUtils;
/**
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class ServletStrategy implements DescribableStrategy
{
public void describeObject(Object object, DescriptionReceiver receiver)
{
Servlet servlet = (Servlet) object;
ServletConfig config = servlet.getServletConfig();
receiver.title("HttpServlet");
receiver.property("servletInfo", servlet.getServletInfo());
receiver.property("servletName", config.getServletName());
receiver.section("Initialization Parameters");
Iterator i = WebUtils.toSortedList(config.getInitParameterNames()).iterator();
while (i.hasNext())
{
String key = (String) i.next();
receiver.property(key, config.getInitParameter(key));
}
}
}
1.3 +28 -27 jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.describe.xml
Index: tapestry.describe.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.describe.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- tapestry.describe.xml 29 Mar 2005 22:19:54 -0000 1.2
+++ tapestry.describe.xml 30 Mar 2005 16:27:05 -0000 1.3
@@ -19,27 +19,27 @@
Services and adaptors for "describing" various objects into an HTML representation.
- <configuration-point id="DescribeAdaptors" schema-id="hivemind.lib.AdapterRegistry">
+ <configuration-point id="DescribableStrategies" schema-id="hivemind.lib.StrategyRegistry">
- Maps classes to DescribableAdapter instances.
+ Maps classes to DescribableStrategy instances.
</configuration-point>
- <contribution configuration-id="DescribeAdaptors">
- <adapter class="Describable" object="instance:NativeDescribableAdapter"/>
- <adapter class="java.lang.Object" object="instance:DefaultDescribableAdapter"/>
- <adapter class="javax.servlet.http.HttpServletRequest" object="instance:HttpServletRequestDescriber"/>
- <adapter class="javax.servlet.http.Cookie" object="instance:CookieDescribableAdapter"/>
- <adapter class="javax.servlet.http.HttpSession" object="instance:HttpSessionDescribableAdapter"/>
- <adapter class="javax.servlet.ServletContext" object="instance:ServletContextDescribableAdapter"/>
- <adapter class="javax.servlet.Servlet" object="instance:ServletDescribableAdapter"/>
+ <contribution configuration-id="DescribableStrategies">
+ <strategy class="Describable" object="instance:NativeStrategy"/>
+ <strategy class="java.lang.Object" object="instance:DefaultStrategy"/>
+ <strategy class="javax.servlet.http.HttpServletRequest" object="instance:HttpServletRequestStrategy"/>
+ <strategy class="javax.servlet.http.Cookie" object="instance:CookieStrategy"/>
+ <strategy class="javax.servlet.http.HttpSession" object="instance:HttpSessionStrategy"/>
+ <strategy class="javax.servlet.ServletContext" object="instance:ServletContextStrategy"/>
+ <strategy class="javax.servlet.Servlet" object="instance:ServletStrategy"/>
</contribution>
- <service-point id="DescribeAdaptor" interface="DescribableAdapter">
- Adaptor registry facade for DescribableAdapter.
+ <service-point id="DescribableStrategy" interface="DescribableStrategy">
+ Strategy registry facade for DescribableStrategy.
- <invoke-factory service-id="hivemind.lib.AdapterRegistryFactory">
- <construct configuration-id="DescribeAdaptors"/>
+ <invoke-factory service-id="hivemind.lib.StrategyFactory">
+ <construct configuration-id="DescribableStrategies"/>
</invoke-factory>
</service-point>
@@ -49,40 +49,41 @@
<invoke-factory>
<construct class="HTMLDescriberImpl">
- <set-service property="adapter" service-id="DescribeAdaptor"/>
+ <set-service property="strategy" service-id="DescribableStrategy"/>
</construct>
</invoke-factory>
</service-point>
- <service-point id="DefaultRenderableAdapter" interface="RenderableAdapter">
+ <service-point id="DefaultRenderStrategy" interface="RenderStrategy">
Default adapter for objects that uses the HTMLDescriber service to do
the work.
<invoke-factory>
- <construct class="DefaultRenderableAdapter">
+ <construct class="DefaultRenderStrategy">
<set-object property="describer" value="infrastructure:HTMLDescriber"/>
</construct>
</invoke-factory>
</service-point>
- <configuration-point id="RenderableAdapters" schema-id="hivemind.lib.AdapterRegistry">
+ <configuration-point id="RenderStrategies" schema-id="hivemind.lib.StrategyRegistry">
- Maps classes to RenderableAdapters.
+ Maps classes to RenderStrategy objects.
</configuration-point>
- <contribution configuration-id="RenderableAdapters">
- <adapter class="java.lang.Object" object="service:DefaultRenderableAdapter"/>
- <adapter class="org.apache.hivemind.Location" object="instance:LocationRenderableAdapter"/>
+ <contribution configuration-id="RenderStrategies">
+ <strategy class="java.lang.Object" object="service:DefaultRenderStrategy"/>
+ <strategy class="org.apache.hivemind.Location" object="instance:LocationRenderStrategy"/>
</contribution>
- <service-point id="RenderableAdapter" interface="RenderableAdapter">
+ <service-point id="RenderStrategy" interface="RenderStrategy">
- Adapter registry for RenderableAdapters.
+ Strategy service based on the RenderStrategies configuration point, which
+ allows arbitrary objects to be rendered as HTML.
- <invoke-factory service-id="hivemind.lib.AdapterRegistryFactory">
- <construct configuration-id="RenderableAdapters"/>
+ <invoke-factory service-id="hivemind.lib.StrategyFactory">
+ <construct configuration-id="RenderStrategies"/>
</invoke-factory>
</service-point>
@@ -92,7 +93,7 @@
<invoke-factory>
<construct class="RenderableAdapterFactoryImpl">
- <set-service property="adapter" service-id="RenderableAdapter"/>
+ <set-service property="strategy" service-id="RenderStrategy"/>
</construct>
</invoke-factory>
</service-point>
1.11 +6 -6 jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.asset.xml
Index: tapestry.asset.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.asset.xml,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- tapestry.asset.xml 29 Mar 2005 13:35:42 -0000 1.10
+++ tapestry.asset.xml 30 Mar 2005 16:27:05 -0000 1.11
@@ -81,13 +81,13 @@
</invoke-factory>
</service-point>
- <configuration-point id="AssetFactoryAdapters" schema-id="hivemind.lib.AdapterRegistry"/>
+ <configuration-point id="AssetFactoryStrategies" schema-id="hivemind.lib.StrategyRegistry"/>
- <contribution configuration-id="AssetFactoryAdapters">
- <adapter class="org.apache.hivemind.util.ContextResource"
+ <contribution configuration-id="AssetFactoryStrategies">
+ <strategy class="org.apache.hivemind.util.ContextResource"
object="service:ContextAssetFactory"/>
- <adapter class="org.apache.hivemind.util.ClasspathResource"
+ <strategy class="org.apache.hivemind.util.ClasspathResource"
object="service:ClasspathAssetFactory"/>
</contribution>
@@ -98,8 +98,8 @@
the type of resource. Used when the asset path does not contain
a prefix.
- <invoke-factory service-id="hivemind.lib.AdapterRegistryFactory">
- <construct configuration-id="AssetFactoryAdapters"/>
+ <invoke-factory service-id="hivemind.lib.StrategyFactory">
+ <construct configuration-id="AssetFactoryStrategies"/>
</invoke-factory>
</service-point>
1.8 +3 -3 jakarta-tapestry/portlet/src/descriptor/META-INF/hivemodule.xml
Index: hivemodule.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/portlet/src/descriptor/META-INF/hivemodule.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- hivemodule.xml 29 Mar 2005 22:19:54 -0000 1.7
+++ hivemodule.xml 30 Mar 2005 16:27:05 -0000 1.8
@@ -218,7 +218,7 @@
<invoke-factory>
<construct class="org.apache.tapestry.describe.HTMLDescriberImpl">
- <set-service property="adapter" service-id="tapestry.describe.DescribeAdaptor"/>
+ <set-service property="strategy" service-id="tapestry.describe.DescribableStrategy"/>
<set property="headerClass" value="portlet-section-header"/>
<set property="subheaderClass" value="portlet-section-subheader"/>
<set property="tableClass" value="portlet-section-body"/>
@@ -226,7 +226,7 @@
</invoke-factory>
</service-point>
- <contribution configuration-id="tapestry.describe.DescribeAdaptors">
- <adapter class="javax.portlet.PortletSession" object="instance:PortletSessionDescribableAdapter"/>
+ <contribution configuration-id="tapestry.describe.DescribableStrategies">
+ <strategy class="javax.portlet.PortletSession" object="instance:PortletSessionDescribableStrategy"/>
</contribution>
</module>
\ No newline at end of file
1.5 +21 -21 jakarta-tapestry/framework/src/java/org/apache/tapestry/valid/NumberValidator.java
Index: NumberValidator.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/valid/NumberValidator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- NumberValidator.java 6 Jan 2005 02:17:23 -0000 1.4
+++ NumberValidator.java 30 Mar 2005 16:27:05 -0000 1.5
@@ -20,8 +20,8 @@
import java.util.Map;
import org.apache.hivemind.ApplicationRuntimeException;
-import org.apache.hivemind.lib.util.AdapterRegistry;
-import org.apache.hivemind.lib.util.AdapterRegistryImpl;
+import org.apache.hivemind.lib.util.StrategyRegistry;
+import org.apache.hivemind.lib.util.StrategyRegistryImpl;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.Tapestry;
@@ -89,7 +89,7 @@
private String _numberRangeMessage;
- private static AdapterRegistry _numberAdaptors = new AdapterRegistryImpl();
+ private static StrategyRegistry _numberAdaptors = new StrategyRegistryImpl();
public final static int NUMBER_TYPE_INTEGER = 0;
@@ -99,7 +99,7 @@
* This class is not meant for use outside of NumberValidator; it is public only to fascilitate
* some unit testing.
*/
- public static abstract class NumberAdaptor
+ public static abstract class NumberStrategy
{
/**
* Parses a non-empty {@link String}into the correct subclass of {@link Number}.
@@ -138,7 +138,7 @@
protected abstract Number coerce(Number number);
}
- private static abstract class IntegerNumberAdaptor extends NumberAdaptor
+ private static abstract class IntegerNumberAdaptor extends NumberStrategy
{
public int getNumberType()
{
@@ -146,7 +146,7 @@
}
}
- private static abstract class RealNumberAdaptor extends NumberAdaptor
+ private static abstract class RealNumberAdaptor extends NumberStrategy
{
public int getNumberType()
{
@@ -260,12 +260,12 @@
static
{
- NumberAdaptor byteAdaptor = new ByteAdaptor();
- NumberAdaptor shortAdaptor = new ShortAdaptor();
- NumberAdaptor intAdaptor = new IntAdaptor();
- NumberAdaptor longAdaptor = new LongAdaptor();
- NumberAdaptor floatAdaptor = new FloatAdaptor();
- NumberAdaptor doubleAdaptor = new DoubleAdaptor();
+ NumberStrategy byteAdaptor = new ByteAdaptor();
+ NumberStrategy shortAdaptor = new ShortAdaptor();
+ NumberStrategy intAdaptor = new IntAdaptor();
+ NumberStrategy longAdaptor = new LongAdaptor();
+ NumberStrategy floatAdaptor = new FloatAdaptor();
+ NumberStrategy doubleAdaptor = new DoubleAdaptor();
_numberAdaptors.register(Byte.class, byteAdaptor);
_numberAdaptors.register(byte.class, byteAdaptor);
@@ -300,9 +300,9 @@
return value.toString();
}
- private NumberAdaptor getAdaptor(IFormComponent field)
+ private NumberStrategy getStrategy(IFormComponent field)
{
- NumberAdaptor result = getAdaptor(_valueTypeClass);
+ NumberStrategy result = getStrategy(_valueTypeClass);
if (result == null)
throw new ApplicationRuntimeException(Tapestry.format(
@@ -314,7 +314,7 @@
}
/**
- * Returns an adaptor for the given type.
+ * Returns an strategy for the given type.
* <p>
* Note: this method exists only for testing purposes. It is not meant to be invoked by user
* code and is subject to change at any time.
@@ -324,9 +324,9 @@
* @return the adaptor, or null if no such adaptor may be found
* @since 3.0
*/
- public static NumberAdaptor getAdaptor(Class type)
+ public static NumberStrategy getStrategy(Class type)
{
- return (NumberAdaptor) _numberAdaptors.getAdapter(type);
+ return (NumberStrategy) _numberAdaptors.getStrategy(type);
}
public Object toObject(IFormComponent field, String value) throws ValidatorException
@@ -334,7 +334,7 @@
if (checkRequired(field, value))
return null;
- NumberAdaptor adaptor = getAdaptor(field);
+ NumberStrategy adaptor = getStrategy(field);
Number result = null;
try
@@ -654,10 +654,10 @@
public boolean isIntegerNumber()
{
- NumberAdaptor result = (NumberAdaptor) _numberAdaptors.getAdapter(_valueTypeClass);
- if (result == null)
+ NumberStrategy strategy = (NumberStrategy) _numberAdaptors.getStrategy(_valueTypeClass);
+ if (strategy == null)
return false;
- return result.getNumberType() == NUMBER_TYPE_INTEGER;
+ return strategy.getNumberType() == NUMBER_TYPE_INTEGER;
}
}
\ No newline at end of file
1.5 +5 -0 jakarta-tapestry/framework/src/java/org/apache/tapestry/util/io/ISqueezeAdaptor.java
Index: ISqueezeAdaptor.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/util/io/ISqueezeAdaptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ISqueezeAdaptor.java 6 Jan 2005 02:17:14 -0000 1.4
+++ ISqueezeAdaptor.java 30 Mar 2005 16:27:05 -0000 1.5
@@ -23,7 +23,12 @@
* into a String format (squeeze it), or convert from a String back into a Java
* type (unsqueeze).
*
+ * <p>
+ * This interface is somewhat misnamed; this is more of the GoF Strategy pattern
+ * than GoF Adaptor pattern.
+ *
* @author Howard Lewis Ship
+ *
*/
public interface ISqueezeAdaptor
1.5 +4 -4 jakarta-tapestry/framework/src/java/org/apache/tapestry/util/io/DataSqueezerImpl.java
Index: DataSqueezerImpl.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/util/io/DataSqueezerImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DataSqueezerImpl.java 6 Jan 2005 02:17:14 -0000 1.4
+++ DataSqueezerImpl.java 30 Mar 2005 16:27:05 -0000 1.5
@@ -17,8 +17,8 @@
import java.io.IOException;
import org.apache.hivemind.ClassResolver;
-import org.apache.hivemind.lib.util.AdapterRegistry;
-import org.apache.hivemind.lib.util.AdapterRegistryImpl;
+import org.apache.hivemind.lib.util.StrategyRegistry;
+import org.apache.hivemind.lib.util.StrategyRegistryImpl;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.services.DataSqueezer;
@@ -52,7 +52,7 @@
* AdaptorRegistry cache of adaptors.
*/
- private AdapterRegistry _adaptors = new AdapterRegistryImpl();
+ private StrategyRegistry _adaptors = new StrategyRegistryImpl();
/**
* Resource resolver used to deserialize classes.
@@ -163,7 +163,7 @@
if (data == null)
return NULL_PREFIX;
- adaptor = (ISqueezeAdaptor) _adaptors.getAdapter(data.getClass());
+ adaptor = (ISqueezeAdaptor) _adaptors.getStrategy(data.getClass());
return adaptor.squeeze(this, data);
}
1.1 jakarta-tapestry/portlet/src/java/org/apache/tapestry/portlet/PortletSessionDescribableStrategy.java
Index: PortletSessionDescribableStrategy.java
===================================================================
// Copyright 2005 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.tapestry.portlet;
import java.util.Date;
import java.util.Iterator;
import javax.portlet.PortletSession;
import org.apache.tapestry.describe.DescribableStrategy;
import org.apache.tapestry.describe.DescriptionReceiver;
import org.apache.tapestry.web.WebUtils;
/**
* Describes {@link javax.portlet.PortletSession}.
*
* @author Howard M. Lewis Ship
* @since 3.1
*/
public class PortletSessionDescribableStrategy implements DescribableStrategy
{
public void describeObject(Object object, DescriptionReceiver receiver)
{
PortletSession session = (PortletSession) object;
receiver.title("PortletSession");
receiver.property("creationTime", new Date(session.getCreationTime()));
receiver.property("id", session.getId());
receiver.property("lastAccessedTime", new Date(session.getLastAccessedTime()));
receiver.property("maxInactiveInterval", session.getMaxInactiveInterval());
receiver.property("new", session.isNew());
receiver.section("Attributes");
Iterator i = WebUtils.toSortedList(session.getAttributeNames()).iterator();
while (i.hasNext())
{
String key = (String) i.next();
receiver.property(key, session.getAttribute(key));
}
}
}
1.3 +5 -5 jakarta-tapestry/framework/src/java/org/apache/tapestry/coerce/TypeConverterWrapper.java
Index: TypeConverterWrapper.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/coerce/TypeConverterWrapper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TypeConverterWrapper.java 6 Jan 2005 02:17:10 -0000 1.2
+++ TypeConverterWrapper.java 30 Mar 2005 16:27:05 -0000 1.3
@@ -17,12 +17,12 @@
import java.util.Iterator;
import java.util.List;
-import org.apache.hivemind.lib.util.AdapterRegistry;
-import org.apache.hivemind.lib.util.AdapterRegistryImpl;
+import org.apache.hivemind.lib.util.StrategyRegistry;
+import org.apache.hivemind.lib.util.StrategyRegistryImpl;
/**
* A service implementation that works around an
- * {@link org.apache.hivemind.lib.util.AdapterRegistry}. The registry is contructed from a
+ * {@link org.apache.hivemind.lib.util.StrategyRegistry}. The registry is contructed from a
* configuration that follows the <code>tapestry.coerce.Converters</code> schema (a List of
* {@link org.apache.tapestry.coerce.TypeConverterContribution}plus an additional converter for
* nulls.
@@ -32,7 +32,7 @@
*/
public class TypeConverterWrapper implements TypeConverter
{
- private AdapterRegistry _registry = new AdapterRegistryImpl();
+ private StrategyRegistry _registry = new StrategyRegistryImpl();
private List _contributions;
@@ -60,7 +60,7 @@
return _nullConverter.convertValue(null);
}
- TypeConverter delegate = (TypeConverter) _registry.getAdapter(value.getClass());
+ TypeConverter delegate = (TypeConverter) _registry.getStrategy(value.getClass());
return delegate.convertValue(value);
}
1.5 +2 -2 jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/valid/TestNumberValidator.java
Index: TestNumberValidator.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/valid/TestNumberValidator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestNumberValidator.java 6 Feb 2005 15:08:50 -0000 1.4
+++ TestNumberValidator.java 30 Mar 2005 16:27:05 -0000 1.5
@@ -247,7 +247,7 @@
private void checkAdaptorType(int expectedType, Class numberType)
{
- NumberValidator.NumberAdaptor a = NumberValidator.getAdaptor(numberType);
+ NumberValidator.NumberStrategy a = NumberValidator.getStrategy(numberType);
assertEquals(expectedType, a.getNumberType());
}
@@ -270,7 +270,7 @@
private void checkCompare(Number left, Number right)
{
- NumberValidator.NumberAdaptor a = NumberValidator.getAdaptor(left.getClass());
+ NumberValidator.NumberStrategy a = NumberValidator.getStrategy(left.getClass());
assertEquals(0, a.compare(left, right));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org