KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > client > MaintainedSampleLease


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package org.apache.excalibur.instrument.client;
21
22 import org.apache.avalon.framework.configuration.Configuration;
23 import org.apache.avalon.framework.configuration.ConfigurationException;
24 import org.apache.avalon.framework.configuration.DefaultConfiguration;
25
26 /**
27  *
28  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
29  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:23 $
30  * @since 4.1
31  */

32 class MaintainedSampleLease
33 {
34     private String JavaDoc m_instrumentName;
35     private String JavaDoc m_sampleName;
36     private int m_type;
37     private long m_interval;
38     private int m_size;
39     private long m_leaseDuration;
40     private String JavaDoc m_description;
41     
42     /*---------------------------------------------------------------
43      * Constructors
44      *-------------------------------------------------------------*/

45     MaintainedSampleLease( String JavaDoc instrumentName,
46                            int type,
47                            long interval,
48                            int size,
49                            long leaseDuration,
50                            String JavaDoc description )
51     {
52         m_instrumentName = instrumentName;
53         m_type = type;
54         m_interval = interval;
55         m_size = size;
56         m_leaseDuration = leaseDuration;
57         m_description = description;
58         
59         m_sampleName = InstrumentSampleUtils.generateFullInstrumentSampleName(
60             m_instrumentName, m_type, m_interval, m_size );
61     }
62     
63     MaintainedSampleLease( Configuration stateConfig ) throws ConfigurationException
64     {
65         m_instrumentName = stateConfig.getAttribute ( "instrument-name" );
66         m_type = stateConfig.getAttributeAsInteger( "type" );
67         m_interval = stateConfig.getAttributeAsLong ( "interval" );
68         m_size = stateConfig.getAttributeAsInteger( "size" );
69         m_leaseDuration = stateConfig.getAttributeAsLong ( "lease-duration" );
70         m_description = stateConfig.getAttribute ( "description" );
71         
72         m_sampleName = InstrumentSampleUtils.generateFullInstrumentSampleName(
73             m_instrumentName, m_type, m_interval, m_size );
74     }
75
76     /*---------------------------------------------------------------
77      * Methods
78      *-------------------------------------------------------------*/

79     /**
80      * Saves the current state into a Configuration.
81      *
82      * @return The state as a Configuration.
83      */

84     public final Configuration saveState()
85     {
86         DefaultConfiguration stateConfig = new DefaultConfiguration( "maintained-sample", "-" );
87         
88         stateConfig.setAttribute( "instrument-name", m_instrumentName );
89         stateConfig.setAttribute( "type",
90             InstrumentSampleUtils.getInstrumentSampleTypeName( m_type ) );
91         stateConfig.setAttribute( "interval", Long.toString( m_interval ) );
92         stateConfig.setAttribute( "size", Integer.toString( m_size ) );
93         stateConfig.setAttribute( "lease-duration", Long.toString( m_leaseDuration ) );
94         stateConfig.setAttribute( "description", m_description );
95         
96         return stateConfig;
97     }
98     
99     String JavaDoc getInstrumentName()
100     {
101         return m_instrumentName;
102     }
103     
104     String JavaDoc getSampleName()
105     {
106         return m_sampleName;
107     }
108     
109     int getType()
110     {
111         return m_type;
112     }
113     
114     long getInterval()
115     {
116         return m_interval;
117     }
118     
119     int getSize()
120     {
121         return m_size;
122     }
123     
124     long getLeaseDuration()
125     {
126         return m_leaseDuration;
127     }
128     
129     String JavaDoc getDescription()
130     {
131         return m_description;
132     }
133 }
134
135
Popular Tags