Additional AuthnRequest creation options.
[shibboleth/sp.git] / shibsp / attribute / SimpleAttribute.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file shibsp/attribute/SimpleAttribute.h
19  * 
20  * An Attribute whose values are simple strings.
21  */
22
23 #ifndef __shibsp_simpattr_h__
24 #define __shibsp_simpattr_h__
25
26 #include <shibsp/attribute/Attribute.h>
27
28 namespace shibsp {
29
30     /**
31      * An Attribute whose values are simple strings.
32      */
33     class SHIBSP_API SimpleAttribute : public Attribute
34     {
35     public:
36         /**
37          * Constructor
38          * 
39          * @param id    Attribute identifier
40          */
41         SimpleAttribute(const char* id) : Attribute(id), m_caseSensitive(true) {}
42
43         /**
44          * Constructs based on a remoted SimpleAttribute.
45          * 
46          * @param in    input object containing marshalled SimpleAttribute
47          */
48         SimpleAttribute(DDF& in) : Attribute(in), m_caseSensitive(in["case_insensitive"].isnull()) {
49             DDF val = in.first().first();
50             while (val.string()) {
51                 m_serialized.push_back(val.string());
52                 val = in.first().next();
53             }
54         }
55         
56         virtual ~SimpleAttribute() {}
57
58         bool isCaseSensitive() const {
59             return m_caseSensitive;
60         }
61
62         /**
63          * Returns the set of values encoded as UTF-8 strings.
64          * 
65          * <p>For simple values, the serialized form is just the actual string,
66          * so the value array can be directly manipulated. 
67          * 
68          * @return  a mutable vector of the values
69          */
70         std::vector<std::string>& getValues() {
71             return m_serialized;
72         }
73         
74         void clearSerializedValues() {
75             // Do nothing, since our values are already serialized.
76         }
77         
78         DDF marshall() const {
79             DDF ddf = Attribute::marshall();
80             if (!m_caseSensitive)
81                 ddf.addmember("case_insensitive");
82             DDF vlist = ddf.first();
83             for (std::vector<std::string>::const_iterator i=m_serialized.begin(); i!=m_serialized.end(); ++i)
84                 vlist.add(DDF(NULL).string(i->c_str()));
85             return ddf;
86         }
87
88     private:
89         bool m_caseSensitive;
90     };
91
92 };
93
94 #endif /* __shibsp_simpattr_h__ */