Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/virtuosotechnologies/asaph/standardmodel/StdVariation.java


1   /*
2   ================================================================================
3   
4     FILE:  StdVariation.java
5     
6     PROJECT:
7     
8       Asaph
9     
10    CONTENTS:
11    
12      Standard implementation of Variation
13    
14    PROGRAMMERS:
15    
16      Daniel Azuma (DA)  <dazuma@kagi.com>
17    
18    COPYRIGHT:
19    
20      Copyright (C) 2003  Daniel Azuma  (dazuma@kagi.com)
21      
22      This program is free software; you can redistribute it and/or
23      modify it under the terms of the GNU General Public License as
24      published by the Free Software Foundation; either version 2
25      of the License, or (at your option) any later version.
26      
27      This program is distributed in the hope that it will be useful,
28      but WITHOUT ANY WARRANTY; without even the implied warranty of
29      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30      GNU General Public License for more details.
31      
32      You should have received a copy of the GNU General Public
33      License along with this program; if not, write to
34        Free Software Foundation, Inc.
35        59 Temple Place, Suite 330
36        Boston, MA 02111-1307 USA
37  
38  ================================================================================
39  */
40  
41  
42  package com.virtuosotechnologies.asaph.standardmodel;
43  
44  
45  import java.io.IOException;
46  import org.xml.sax.SAXException;
47  import org.xml.sax.Attributes;
48  import org.xml.sax.ErrorHandler;
49  import org.xml.sax.Locator;
50  
51  import com.virtuosotechnologies.lib.util.StringID;
52  import com.virtuosotechnologies.lib.xml.XMLUnparser;
53  
54  import com.virtuosotechnologies.asaph.model.Variation;
55  import com.virtuosotechnologies.asaph.model.SimpleString;
56  
57  
58  /**
59   * Standard implementation of Variation
60   */
61  /*package*/ class StdVariation
62  extends BaseSongMember
63  implements
64    Variation
65  {
66    private StdSimpleString name_;
67    private StringID id_;
68    
69    
70    /*package*/ StdVariation(
71      StdSong parent,
72      String name,
73      StringID id)
74    {
75      super(parent);
76      name_ = new StdSimpleString(this, name);
77      id_ = id;
78    }
79    
80    
81    /*package*/ void unparse(
82      XMLUnparser unparser)
83    throws
84      IOException
85    {
86      unparser.startMultiLineElement(XMLConstants.VARIATION_ELEMENT);
87      unparser.addAttribute(XMLConstants.VARIATION_ID_ATTRIBUTE, id_.getValue());
88      name_.unparse(unparser, XMLConstants.VARIATIONNAME_ELEMENT);
89      unparser.endElement(XMLConstants.VARIATION_ELEMENT);
90    }
91    
92    
93    /*package*/ class ParseHandler
94    extends ParseHandlerBase
95    {
96      /*package*/ ParseHandler(
97        ErrorHandler errorHandler,
98        Locator locator)
99      {
100       super(errorHandler, locator, XMLConstants.VARIATION_ELEMENT);
101     }
102     
103     /*package*/ ParseHandlerBase localStartElement(
104       String uri,
105       String localName,
106       String qName,
107       Attributes attributes)
108     throws
109       SAXException
110     {
111       if (localName.equals(XMLConstants.VARIATIONNAME_ELEMENT))
112       {
113         return name_.new ParseHandler(getErrorHandler(), getDocumentLocator(),
114           XMLConstants.VARIATIONNAME_ELEMENT);
115       }
116       else
117       {
118         return super.localStartElement(uri, localName, qName, attributes);
119       }
120     }
121   }
122   
123   
124   //-------------------------------------------------------------------------
125   // Methods of Variation
126   //-------------------------------------------------------------------------
127   
128   /**
129    * Get a SimpleString containing the name of the variation.
130    * Every Variation will have a name, even if it is the empty string.
131    *
132    * @return name
133    */
134   public SimpleString getName()
135   {
136     return name_;
137   }
138   
139   
140   /**
141    * Get a string ID that can be used to serialize references to this
142    * Variation. The ID is guaranteed to be unique among Variations within
143    * the owning Song, and will remain the same for the same Variation across
144    * different executions of the tool. However, two Variations from different
145    * Songs may have the same string ID, and the same string ID may be
146    * shared between SongBlocks, Variations and ChordSets within the same
147    * Song.
148    *
149    * @return a unique serializable String ID for this Variation
150    */
151   public String getSerializableID()
152   {
153     return id_.getValue();
154   }
155 }