crafterm 2003/01/17 03:31:18 Modified: src/scratchpad/src/org/apache/cocoon/webservices/instrument DeploymentDescriptor.wsdd InstrumentationService.java InstrumentationServiceImpl.java Log: * Implemented getSampleNames(). This allows one to obtain a list of available instrument samples, eg. for browsing purposes. Revision Changes Path 1.2 +1 -1 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/webservices/instrument/DeploymentDescriptor.wsdd Index: DeploymentDescriptor.wsdd =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/webservices/instrument/DeploymentDescriptor.wsdd,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DeploymentDescriptor.wsdd 8 Nov 2002 17:39:19 -0000 1.1 +++ DeploymentDescriptor.wsdd 17 Jan 2003 11:31:17 -0000 1.2 @@ -5,7 +5,7 @@ <parameter name="role" value="org.apache.cocoon.webservices.instrument.InstrumentationService"/> <parameter name="className" value="org.apache.cocoon.webservices.instrument.InstrumentationService"/> <parameter name="handlerClass" value="org.apache.cocoon.components.axis.providers.AvalonProvider"/> - <parameter name="allowedMethods" value="getSampleSnapshot"/> + <parameter name="allowedMethods" value="getSampleSnapshot getSampleNames"/> </service> </deployment> 1.2 +8 -1 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/webservices/instrument/InstrumentationService.java Index: InstrumentationService.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/webservices/instrument/InstrumentationService.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InstrumentationService.java 8 Nov 2002 17:39:19 -0000 1.1 +++ InstrumentationService.java 17 Jan 2003 11:31:17 -0000 1.2 @@ -98,4 +98,11 @@ */ int[] getSampleSnapshot(String path) throws Exception; + + /** + * Obtains an array of instrumentable sample names + * + * @return a {@link String[]} array of sample names + */ + String[] getSampleNames(); } 1.2 +59 -13 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/webservices/instrument/InstrumentationServiceImpl.java Index: InstrumentationServiceImpl.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/webservices/instrument/InstrumentationServiceImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InstrumentationServiceImpl.java 8 Nov 2002 17:39:19 -0000 1.1 +++ InstrumentationServiceImpl.java 17 Jan 2003 11:31:17 -0000 1.2 @@ -50,10 +50,15 @@ */ package org.apache.cocoon.webservices.instrument; +import java.util.ArrayList; +import java.util.List; + import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.excalibur.instrument.InstrumentManager; import org.apache.excalibur.instrument.manager.DefaultInstrumentManager; import org.apache.excalibur.instrument.manager.interfaces.InstrumentableDescriptor; +import org.apache.excalibur.instrument.manager.interfaces.InstrumentDescriptor; +import org.apache.excalibur.instrument.manager.interfaces.InstrumentSampleDescriptor; /** * Implementation of {@link InstrumentationService} component. This component @@ -65,8 +70,8 @@ public final class InstrumentationServiceImpl extends AbstractLogEnabled implements InstrumentationService { - // empty integer array, used if a sample is request, but no manager exists. private static final int[] EMPTY_INT_ARRAY = {}; + private static final String[] EMPTY_STRING_ARRAY = {}; // instrument manager reference private DefaultInstrumentManager m_iManager; @@ -129,12 +134,11 @@ throws Exception { // ensure we have an instrument manager available - if (m_iManager == null) { - if (getLogger().isWarnEnabled()) - getLogger().warn( - "No instrument manager available," + - "please enable instrumentation in your web.xml" - ); + if (!haveInstrumentManager()) { + getLogger().warn( + "No instrument manager available," + + "please enable instrumentation in your web.xml" + ); return EMPTY_INT_ARRAY; } @@ -144,12 +148,54 @@ } /** - * REVISIT: this is currently unused, but might be good for browsing - * instrument samples in the future. + * Obtain a list of available samples, useful for browsing + * available samples. + * + * @return an {@link String}[] array of sample names + */ + public String[] getSampleNames() { + + // ensure we have an instrument manager available + if (!haveInstrumentManager()) { + getLogger().warn( + "No instrument manager available," + + "please enable instrumentation in your web.xml" + ); + return EMPTY_STRING_ARRAY; + } + + // list all instrumentables + final InstrumentableDescriptor[] descriptors = + m_iManager.getInstrumentableDescriptors(); + final List names = new ArrayList(); + + for (int i = 0; i < descriptors.length; ++i) { + + // list all instruments + InstrumentDescriptor[] insts = + descriptors[i].getInstrumentDescriptors(); + + for (int k = 0; k < insts.length; ++k) { + + // list all samples + InstrumentSampleDescriptor[] samples = + insts[k].getInstrumentSampleDescriptors(); + + for (int j = 0; j < samples.length; ++j) { + names.add(samples[j].getName()); + } + } + } + + return (String[])names.toArray(new String[]{}); + } + + /** + * Helper method to determine if a valid instrument manager is available * - * @return an {@link InstrumentableDescriptor}[] value + * @return true if an instrument manager is present, false otherwise */ - public InstrumentableDescriptor[] getInstrumentableDescriptors() { - return m_iManager.getInstrumentableDescriptors(); + private boolean haveInstrumentManager() { + return (m_iManager != null); } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]