1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21 
22 package org.apache.openoffice.ooxml.schema.model.attribute;
23 
24 import org.apache.openoffice.ooxml.schema.model.base.Location;
25 import org.apache.openoffice.ooxml.schema.model.base.Node;
26 import org.apache.openoffice.ooxml.schema.model.base.QualifiedName;
27 import org.apache.openoffice.ooxml.schema.parser.FormDefault;
28 
29 /** Base class for both Attribute and AttributeReference classes.
30  */
31 public abstract class AttributeBase
32     extends Node
33 {
34     public enum Use
35     {
36         Optional,
37         Required
38     }
39 
40 
41 
AttributeBase( final QualifiedName aName, final String sUse, final String sDefault, final String sFixed, final FormDefault eFormDefault, final Location aLocation)42     public AttributeBase (
43         final QualifiedName aName,
44         final String sUse,
45         final String sDefault,
46         final String sFixed,
47         final FormDefault eFormDefault,
48         final Location aLocation)
49     {
50         super(null, aName, aLocation);
51 
52         switch(sUse)
53         {
54             case "optional":
55                 meUse = Use.Optional;
56                 break;
57             case "required":
58                 meUse = Use.Required;
59                 break;
60             default:
61                 throw new RuntimeException("value of 'use' attribute is neither 'optional' nor 'required' but "+sUse);
62         }
63         msDefault = sDefault;
64         msFixed = sFixed;
65         meFormDefault = eFormDefault;
66     }
67 
68 
69 
70 
GetFormDefault()71     public FormDefault GetFormDefault()
72     {
73         return meFormDefault;
74     }
75 
76 
77 
78 
GetUse()79     public Use GetUse ()
80     {
81         return meUse;
82     }
83 
84 
85 
86 
GetDefault()87     public String GetDefault()
88     {
89         return msDefault;
90     }
91 
92 
93 
94 
95     @Override
toString()96     public String toString ()
97     {
98         String sText = "use "+meUse.toString();
99         if (msDefault != null)
100             sText += ", default "+msDefault;
101         else
102             sText += ", no default";
103         if (msFixed != null)
104             sText += ", fixed to "+msFixed;
105         else
106             sText += ", not fixed";
107         return sText;
108     }
109 
110 
111 
112 
113     private final Use meUse;
114     private final String msDefault;
115     private final String msFixed;
116     private final FormDefault meFormDefault;
117 }
118