Update copyright.
[shibboleth/sp.git] / shibsp / attribute / Attribute.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/Attribute.h
19  * 
20  * A resolved attribute.
21  */
22
23 #ifndef __shibsp_attribute_h__
24 #define __shibsp_attribute_h__
25
26 #include <shibsp/remoting/ddf.h>
27
28 #include <string>
29 #include <vector>
30
31 namespace shibsp {
32
33     /**
34      * A resolved attribute.
35      * 
36      * <p>Resolved attributes are a neutral construct that represent both simple and
37      * complex attribute data structures that might be found in SAML assertions
38      * or obtained from other sources.
39      * 
40      * <p>Attributes consist of an id/name that is locally unique (that is, unique to a
41      * configuration at any given point in time) and zero or more values. Values can
42      * be of any type or structure, but will generally be made available to applications
43      * only if a serialized string form exists. More complex values can be used with
44      * access control plugins that understand them, however. 
45      */
46     class SHIBSP_API Attribute
47     {
48         MAKE_NONCOPYABLE(Attribute);
49     protected:
50         /**
51          * Constructor
52          * 
53          * @param id    Attribute identifier 
54          */
55         Attribute(const char* id) : m_id(id) {}
56
57         /**
58          * Maintains a copy of serialized attribute values, when possible.
59          * 
60          * <p>Implementations should maintain the array when values are added or removed.
61          */
62         mutable std::vector<std::string> m_serialized;
63
64     public:
65         virtual ~Attribute() {}
66         
67         /**
68          * Returns the Attribute identifier.
69          * 
70          * @return Attribute identifier
71          */
72         const char* getId() const {
73             return m_id.c_str();
74         }
75         
76         /**
77          * Returns the number of values.
78          * 
79          * @return  number of values
80          */
81         virtual size_t valueCount() const {
82             return m_serialized.size();
83         }
84         
85         /**
86          * Returns serialized attribute values encoded as UTF-8 strings.
87          * 
88          * @return  an immutable vector of values
89          */
90         virtual const std::vector<std::string>& getSerializedValues() const {
91             return m_serialized;
92         }
93         
94         /**
95          * Informs the attribute that values have changed and any serializations
96          * must be cleared. 
97          */
98         virtual void clearSerializedValues()=0;
99         
100         /**
101          * Marshalls an Attribute for remoting.
102          * 
103          * This allows Attribute objects to be communicated across process boundaries
104          * without excess XML parsing. The DDF returned must be a struct containing
105          * a string member called "id" and a list called "values". The name of the struct
106          * should contain the registered name of the Attribute implementation.  
107          */
108         virtual DDF marshall() const {
109             DDF ddf(NULL);
110             ddf.structure().addmember("id").string(m_id.c_str());
111             return ddf;
112         }
113         
114     private:
115         std::string m_id;
116     };
117
118 };
119
120 #endif /* __shibsp_attribute_h__ */