This project has retired. For details please refer to its Attic page.
CmisExtensionElementImpl xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.commons.impl.dataobjects;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.HashMap;
24  import java.util.List;
25  import java.util.Map;
26  
27  import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
28  
29  public class CmisExtensionElementImpl implements CmisExtensionElement {
30  
31      private static final long serialVersionUID = 1L;
32  
33      private final String name;
34      private final String namespace;
35      private final String value;
36      private Map<String, String> attributes;
37      private final List<CmisExtensionElement> children;
38  
39      /**
40       * Constructor for a leaf.
41       */
42      public CmisExtensionElementImpl(String namespace, String name, Map<String, String> attributes, String value) {
43          if (name == null) {
44              throw new IllegalArgumentException("Name must set!");
45          }
46  
47          this.name = name;
48          this.namespace = namespace;
49          this.value = value;
50          children = Collections.emptyList();
51  
52          if (attributes != null) {
53              this.attributes = Collections.unmodifiableMap(new HashMap<String, String>(attributes));
54          } else {
55              this.attributes = Collections.emptyMap();
56          }
57      }
58  
59      /**
60       * Constructor for a node.
61       */
62      public CmisExtensionElementImpl(String namespace, String name, Map<String, String> attributes,
63              List<CmisExtensionElement> children) {
64          if (name == null) {
65              throw new IllegalArgumentException("Name must set!");
66          }
67  
68          this.name = name;
69          this.namespace = namespace;
70          this.value = null;
71  
72          if (children != null) {
73              this.children = Collections.unmodifiableList(new ArrayList<CmisExtensionElement>(children));
74          } else {
75              this.children = Collections.emptyList();
76          }
77  
78          if (attributes != null) {
79              this.attributes = Collections.unmodifiableMap(new HashMap<String, String>(attributes));
80          } else {
81              this.attributes = Collections.emptyMap();
82          }
83      }
84  
85      /**
86       * Copy constructor.
87       */
88      public CmisExtensionElementImpl(CmisExtensionElement element) {
89          if (element == null) {
90              throw new IllegalArgumentException("Element must set!");
91          }
92          if (element.getName() == null) {
93              throw new IllegalArgumentException("Name must set!");
94          }
95  
96          this.name = element.getName();
97          this.namespace = element.getNamespace();
98          this.value = element.getValue();
99          this.children = element.getChildren();
100     }
101 
102     public String getName() {
103         return name;
104     }
105 
106     public String getNamespace() {
107         return namespace;
108     }
109 
110     public String getValue() {
111         return value;
112     }
113 
114     public List<CmisExtensionElement> getChildren() {
115         return children;
116     }
117 
118     public Map<String, String> getAttributes() {
119         return attributes;
120     }
121 
122     @Override
123     public String toString() {
124         return (namespace == null ? "" : "{" + namespace + "}") + name + " " + attributes + ": "
125                 + (children.isEmpty() ? value : children.toString());
126     }
127 }