1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * Copyright © 2017 Amdocs
\r
7 * * ===========================================================================
\r
8 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * * you may not use this file except in compliance with the License.
\r
10 * * You may obtain a copy of the License at
\r
12 * * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * * Unless required by applicable law or agreed to in writing, software
\r
15 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * * See the License for the specific language governing permissions and
\r
18 * * limitations under the License.
\r
19 * * ============LICENSE_END====================================================
\r
21 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 ******************************************************************************/
\r
24 package com.att.dao.aaf.cass;
\r
26 import java.io.ByteArrayOutputStream;
\r
27 import java.io.DataInputStream;
\r
28 import java.io.DataOutputStream;
\r
29 import java.io.IOException;
\r
30 import java.nio.ByteBuffer;
\r
31 import java.util.ArrayList;
\r
32 import java.util.List;
\r
33 import java.util.Map.Entry;
\r
35 import com.att.cssa.rserv.Pair;
\r
36 import com.att.dao.Bytification;
\r
37 import com.att.dao.CassDAOImpl;
\r
38 import com.att.dao.Loader;
\r
41 public class Namespace implements Bytification {
\r
42 public static final int MAGIC=250935515;
\r
43 public static final int VERSION=1;
\r
44 public static final int BUFF_SIZE=48;
\r
47 public List<String> owner;
\r
48 public List<String> admin;
\r
49 public List<Pair<String,String>> attrib;
\r
50 public String description;
\r
51 public Integer type;
\r
52 public String parent;
\r
53 public Namespace() {}
\r
55 public Namespace(NsDAO.Data ndd) {
\r
57 description = ndd.description;
\r
59 parent = ndd.parent;
\r
60 if(ndd.attrib!=null && !ndd.attrib.isEmpty()) {
\r
61 attrib = new ArrayList<Pair<String,String>>();
\r
62 for( Entry<String, String> entry : ndd.attrib.entrySet()) {
\r
63 attrib.add(new Pair<String,String>(entry.getKey(),entry.getValue()));
\r
68 public Namespace(NsDAO.Data ndd,List<String> owner, List<String> admin) {
\r
72 description = ndd.description;
\r
74 parent = ndd.parent;
\r
75 if(ndd.attrib!=null && !ndd.attrib.isEmpty()) {
\r
76 attrib = new ArrayList<Pair<String,String>>();
\r
77 for( Entry<String, String> entry : ndd.attrib.entrySet()) {
\r
78 attrib.add(new Pair<String,String>(entry.getKey(),entry.getValue()));
\r
83 public NsDAO.Data data() {
\r
84 NsDAO.Data ndd = new NsDAO.Data();
\r
86 ndd.description = description;
\r
87 ndd.parent = parent;
\r
93 public ByteBuffer bytify() throws IOException {
\r
94 ByteArrayOutputStream baos = new ByteArrayOutputStream();
\r
95 DataOutputStream os = new DataOutputStream(baos);
\r
97 Loader.writeHeader(os,MAGIC,VERSION);
\r
98 Loader.writeString(os, name);
\r
100 Loader.writeStringSet(os,admin);
\r
101 Loader.writeStringSet(os,owner);
\r
102 Loader.writeString(os,description);
\r
103 Loader.writeString(os,parent);
\r
105 return ByteBuffer.wrap(baos.toByteArray());
\r
109 public void reconstitute(ByteBuffer bb) throws IOException {
\r
110 DataInputStream is = CassDAOImpl.toDIS(bb);
\r
111 /*int version = */Loader.readHeader(is,MAGIC,VERSION);
\r
112 // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields
\r
114 byte[] buff = new byte[BUFF_SIZE];
\r
115 name = Loader.readString(is, buff);
\r
116 type = is.readInt();
\r
117 admin = Loader.readStringList(is,buff);
\r
118 owner = Loader.readStringList(is,buff);
\r
119 description = Loader.readString(is,buff);
\r
120 parent = Loader.readString(is,buff);
\r
125 * @see java.lang.Object#hashCode()
\r
128 public int hashCode() {
\r
129 return name.hashCode();
\r
134 * @see java.lang.Object#toString()
\r
137 public String toString() {
\r
138 return name.toString();
\r
142 * @see java.lang.Object#equals(java.lang.Object)
\r
145 public boolean equals(Object arg0) {
\r
146 if(arg0==null || !(arg0 instanceof Namespace)) {
\r
149 return name.equals(((Namespace)arg0).name);
\r