You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-dev@ws.apache.org by sc...@apache.org on 2005/02/25 19:03:34 UTC
svn commit: r155352 -
incubator/apollo/trunk/src/site/content/example/src/java/org/oasisOpen/docs/wsrf/x2005/x01/wsrfInterop20Draft03Wsdl/PrinterPortResource.java
Author: scamp
Date: Fri Feb 25 10:03:32 2005
New Revision: 155352
URL: http://svn.apache.org/viewcvs?view=rev&rev=155352
Log: (empty)
Modified:
incubator/apollo/trunk/src/site/content/example/src/java/org/oasisOpen/docs/wsrf/x2005/x01/wsrfInterop20Draft03Wsdl/PrinterPortResource.java
Modified: incubator/apollo/trunk/src/site/content/example/src/java/org/oasisOpen/docs/wsrf/x2005/x01/wsrfInterop20Draft03Wsdl/PrinterPortResource.java
URL: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/site/content/example/src/java/org/oasisOpen/docs/wsrf/x2005/x01/wsrfInterop20Draft03Wsdl/PrinterPortResource.java?view=diff&r1=155351&r2=155352
==============================================================================
--- incubator/apollo/trunk/src/site/content/example/src/java/org/oasisOpen/docs/wsrf/x2005/x01/wsrfInterop20Draft03Wsdl/PrinterPortResource.java (original)
+++ incubator/apollo/trunk/src/site/content/example/src/java/org/oasisOpen/docs/wsrf/x2005/x01/wsrfInterop20Draft03Wsdl/PrinterPortResource.java Fri Feb 25 10:03:32 2005
@@ -16,11 +16,14 @@
package org.oasisOpen.docs.wsrf.x2005.x01.wsrfInterop20Draft03Wsdl;
import org.apache.ws.resource.properties.ResourceProperty;
+import org.apache.ws.resource.properties.impl.XmlBeansResourceProperty;
+import org.apache.ws.util.timer.TimerImpl;
+import org.apache.xmlbeans.XmlInteger;
import org.oasisOpen.docs.wsrf.x2005.x01.wsrfInterop20Draft03.*;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType;
+
import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
import commonj.timers.TimerListener;
import commonj.timers.Timer;
@@ -31,92 +34,116 @@
* NOTE: This class is generated but IS meant to be modified.
*/
public class PrinterPortResource
- extends AbstractPrinterPortResource implements TimerListener
-{
- private String m_name;
- private EndpointReferenceType m_epr;
-
- private List m_printQueue = new ArrayList();
-
- /**
- * Creates a new {@link PrinterPortResource} object.
- *
- * @param name DOCUMENT_ME
- * @param eprForResource DOCUMENT_ME
- */
- public PrinterPortResource( String name,
- EndpointReferenceType eprForResource )
- {
- m_name = name;
- m_epr = eprForResource;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public EndpointReferenceType getEpr( )
- {
- return m_epr;
- }
-
- /**
- * Initializes this resource's state (properties, etc.).
- */
- public void init( )
- {
- super.init( );
- ResourceProperty resourceProperty = m_propSet.get( PrinterPortPropertyQNames.PRINTER_REFERENCE );
- PrinterReferenceDocument printerRefDoc = PrinterReferenceDocument.Factory.newInstance( );
- printerRefDoc.setPrinterReference( getEpr( ) );
- resourceProperty.add( printerRefDoc );
-
- resourceProperty = m_propSet.get( PrinterPortPropertyQNames.PRINTER_STATE );
- PrinterStateDocument printerState = PrinterStateDocument.Factory.newInstance( );
- printerState.setPrinterState( PrinterStateType.IDLE );
- resourceProperty.add( printerState );
-
- resourceProperty = m_propSet.get( PrinterPortPropertyQNames.PRINTER_NAME );
- PrinterNameDocument printName = PrinterNameDocument.Factory.newInstance( );
- printName.setPrinterName( m_name );
- resourceProperty.add( printName );
-
- resourceProperty = m_propSet.get( PrinterPortPropertyQNames.PRINTER_IS_ACCEPTING_JOBS );
- PrinterIsAcceptingJobsDocument isAccepting = PrinterIsAcceptingJobsDocument.Factory.newInstance( );
- isAccepting.setPrinterIsAcceptingJobs( false );
- resourceProperty.add( isAccepting );
-
- resourceProperty = m_propSet.get( PrinterPortPropertyQNames.QUEUED_JOB_COUNT );
- QueuedJobCountDocument queuedJobCountDocument = QueuedJobCountDocument.Factory.newInstance( );
- queuedJobCountDocument.setQueuedJobCount( BigInteger.valueOf( 0 ) );
- resourceProperty.add( queuedJobCountDocument );
-
- resourceProperty = m_propSet.get( PrinterPortPropertyQNames.OPERATIONS_SUPPORTED );
- OperationsSupportedDocument operationsSupportedDocument =
- OperationsSupportedDocument.Factory.newInstance( );
- List operationsSupported = new ArrayList( );
- operationsSupported.add( Operations.PRINT_JOB ); //refer to doc...
- operationsSupported.add( Operations.CREATE_JOB ); //refer to doc...
- operationsSupported.add( Operations.SEND_DOCUMENT ); //refer to doc...
- operationsSupportedDocument.setOperationsSupported( operationsSupported );
- resourceProperty.add( operationsSupportedDocument );
-
- resourceProperty = m_propSet.get( PrinterPortPropertyQNames.DOCUMENT_FORMAT_SUPPORTED );
- DocumentFormatSupportedDocument documentFormatSupportedDocument =
- DocumentFormatSupportedDocument.Factory.newInstance( );
- MimeMediaTypes mimeMediaTypes =
- documentFormatSupportedDocument.addNewDocumentFormatSupported( );
- mimeMediaTypes.addMimeMediaType( MimeMediaTypeType.TEXT_PLAIN );
- resourceProperty.add( documentFormatSupportedDocument );
- }
+ extends AbstractPrinterPortResource implements TimerListener {
+ private String m_name;
+ private EndpointReferenceType m_epr;
+
+ private List m_printQueue = new ArrayList();
+ private Timer m_timer;
+ private Random m_random = new Random(new Date().getTime());;
+
+ /**
+ * Creates a new {@link PrinterPortResource} object.
+ *
+ * @param name DOCUMENT_ME
+ * @param eprForResource DOCUMENT_ME
+ */
+ public PrinterPortResource(String name,
+ EndpointReferenceType eprForResource) {
+ m_name = name;
+ m_epr = eprForResource;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public EndpointReferenceType getEpr() {
+ return m_epr;
+ }
+
+ /**
+ * Initializes this resource's state (properties, etc.).
+ */
+ public void init() {
+ super.init();
+ ResourceProperty resourceProperty = m_propSet.get(PrinterPortPropertyQNames.PRINTER_REFERENCE);
+ PrinterReferenceDocument printerRefDoc = PrinterReferenceDocument.Factory.newInstance();
+ printerRefDoc.setPrinterReference(getEpr());
+ resourceProperty.add(printerRefDoc);
+
+ resourceProperty = m_propSet.get(PrinterPortPropertyQNames.PRINTER_STATE);
+ PrinterStateDocument printerState = PrinterStateDocument.Factory.newInstance();
+ printerState.setPrinterState(PrinterStateType.IDLE);
+ resourceProperty.add(printerState);
+
+ resourceProperty = m_propSet.get(PrinterPortPropertyQNames.PRINTER_NAME);
+ PrinterNameDocument printName = PrinterNameDocument.Factory.newInstance();
+ printName.setPrinterName(m_name);
+ resourceProperty.add(printName);
+
+ resourceProperty = m_propSet.get(PrinterPortPropertyQNames.PRINTER_IS_ACCEPTING_JOBS);
+ PrinterIsAcceptingJobsDocument isAccepting = PrinterIsAcceptingJobsDocument.Factory.newInstance();
+ isAccepting.setPrinterIsAcceptingJobs(false);
+ resourceProperty.add(isAccepting);
+
+ resourceProperty = m_propSet.get(PrinterPortPropertyQNames.QUEUED_JOB_COUNT);
+ QueuedJobCountDocument queuedJobCountDocument = QueuedJobCountDocument.Factory.newInstance();
+ queuedJobCountDocument.setQueuedJobCount(BigInteger.valueOf(0));
+ resourceProperty.add(queuedJobCountDocument);
+
+ resourceProperty = m_propSet.get(PrinterPortPropertyQNames.OPERATIONS_SUPPORTED);
+ OperationsSupportedDocument operationsSupportedDocument =
+ OperationsSupportedDocument.Factory.newInstance();
+ List operationsSupported = new ArrayList();
+ operationsSupported.add(Operations.PRINT_JOB); //refer to doc...
+ operationsSupported.add(Operations.CREATE_JOB); //refer to doc...
+ operationsSupported.add(Operations.SEND_DOCUMENT); //refer to doc...
+ operationsSupportedDocument.setOperationsSupported(operationsSupported);
+ resourceProperty.add(operationsSupportedDocument);
+
+ resourceProperty = m_propSet.get(PrinterPortPropertyQNames.DOCUMENT_FORMAT_SUPPORTED);
+ DocumentFormatSupportedDocument documentFormatSupportedDocument =
+ DocumentFormatSupportedDocument.Factory.newInstance();
+ MimeMediaTypes mimeMediaTypes =
+ documentFormatSupportedDocument.addNewDocumentFormatSupported();
+ mimeMediaTypes.addMimeMediaType(MimeMediaTypeType.TEXT_PLAIN);
+ resourceProperty.add(documentFormatSupportedDocument);
+ }
- public void addJobToQueue(JobPortResource job)
- {
+ public void addJobToQueue(JobPortResource job) {
+ //if timer doesn't exist, create
+ if (m_timer == null) {
+ resetTimer();
+ }
m_printQueue.add(job);
}
+ public void resetTimer() {
+ //scale and translate the random to get a number between 1 and 3 mins
+ double doubleLength = m_random.nextDouble() * 120000.0 + 60000.0;
+ long lengthOfTime = (long) doubleLength;
+ m_timer = new TimerImpl(this, lengthOfTime);
+ }
+
public void timerExpired(Timer timer) {
+ //make sure we have something in queue, remove the 0th print job
+ if (m_printQueue.size() > 0) {
+ JobPortResource job = (JobPortResource) m_printQueue.remove(0);
+ //set termination time to now to make it be removed.
+ job.setTerminationTime(Calendar.getInstance());
+ decrementQueueCount();
+ }
+ resetTimer();//restart timer
+ }
+
+ private void decrementQueueCount() {
+ XmlBeansResourceProperty resourceProperty = (XmlBeansResourceProperty) getResourcePropertySet().get(PrinterPortPropertyQNames.QUEUED_JOB_COUNT);
+ XmlInteger count = (XmlInteger) resourceProperty.get(0);
+ int intCount = count.getBigIntegerValue().intValue();
+ --intCount;
+ count.setBigIntegerValue(BigInteger.valueOf(intCount));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: apollo-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: apollo-dev-help@ws.apache.org