+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START====================================================\r
- * * org.onap.aaf\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package com.att.dao.aaf.cass;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.DataInputStream;\r
-import java.io.DataOutputStream;\r
-import java.io.IOException;\r
-import java.nio.ByteBuffer;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Map.Entry;\r
-\r
-import com.att.cssa.rserv.Pair;\r
-import com.att.dao.Bytification;\r
-import com.att.dao.CassDAOImpl;\r
-import com.att.dao.Loader;\r
-\r
-\r
-public class Namespace implements Bytification {\r
- public static final int MAGIC=250935515;\r
- public static final int VERSION=1;\r
- public static final int BUFF_SIZE=48;\r
-\r
- public String name;\r
- public List<String> owner;\r
- public List<String> admin;\r
- public List<Pair<String,String>> attrib;\r
- public String description;\r
- public Integer type;\r
- public String parent;\r
- public Namespace() {}\r
- \r
- public Namespace(NsDAO.Data ndd) {\r
- name = ndd.name;\r
- description = ndd.description;\r
- type = ndd.type;\r
- parent = ndd.parent;\r
- if(ndd.attrib!=null && !ndd.attrib.isEmpty()) {\r
- attrib = new ArrayList<Pair<String,String>>();\r
- for( Entry<String, String> entry : ndd.attrib.entrySet()) {\r
- attrib.add(new Pair<String,String>(entry.getKey(),entry.getValue()));\r
- }\r
- }\r
- }\r
- \r
- public Namespace(NsDAO.Data ndd,List<String> owner, List<String> admin) {\r
- name = ndd.name;\r
- this.owner = owner;\r
- this.admin = admin;\r
- description = ndd.description;\r
- type = ndd.type;\r
- parent = ndd.parent;\r
- if(ndd.attrib!=null && !ndd.attrib.isEmpty()) {\r
- attrib = new ArrayList<Pair<String,String>>();\r
- for( Entry<String, String> entry : ndd.attrib.entrySet()) {\r
- attrib.add(new Pair<String,String>(entry.getKey(),entry.getValue()));\r
- }\r
- }\r
- }\r
-\r
- public NsDAO.Data data() {\r
- NsDAO.Data ndd = new NsDAO.Data();\r
- ndd.name = name;\r
- ndd.description = description;\r
- ndd.parent = parent;\r
- ndd.type = type;\r
- return ndd;\r
- }\r
-\r
- @Override\r
- public ByteBuffer bytify() throws IOException {\r
- ByteArrayOutputStream baos = new ByteArrayOutputStream();\r
- DataOutputStream os = new DataOutputStream(baos);\r
-\r
- Loader.writeHeader(os,MAGIC,VERSION);\r
- Loader.writeString(os, name);\r
- os.writeInt(type);\r
- Loader.writeStringSet(os,admin);\r
- Loader.writeStringSet(os,owner);\r
- Loader.writeString(os,description);\r
- Loader.writeString(os,parent);\r
-\r
- return ByteBuffer.wrap(baos.toByteArray());\r
- }\r
-\r
- @Override\r
- public void reconstitute(ByteBuffer bb) throws IOException {\r
- DataInputStream is = CassDAOImpl.toDIS(bb);\r
- /*int version = */Loader.readHeader(is,MAGIC,VERSION);\r
- // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields\r
- \r
- byte[] buff = new byte[BUFF_SIZE];\r
- name = Loader.readString(is, buff);\r
- type = is.readInt();\r
- admin = Loader.readStringList(is,buff);\r
- owner = Loader.readStringList(is,buff);\r
- description = Loader.readString(is,buff);\r
- parent = Loader.readString(is,buff);\r
- \r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#hashCode()\r
- */\r
- @Override\r
- public int hashCode() {\r
- return name.hashCode();\r
- }\r
- \r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#toString()\r
- */\r
- @Override\r
- public String toString() {\r
- return name.toString();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#equals(java.lang.Object)\r
- */\r
- @Override\r
- public boolean equals(Object arg0) {\r
- if(arg0==null || !(arg0 instanceof Namespace)) {\r
- return false;\r
- }\r
- return name.equals(((Namespace)arg0).name);\r
- }\r
-\r
-}\r