1a3b38aff585d5ff85251e1992bf03640cf4db7f
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.aaiclient.client.graphinventory.entities.uri;
22
23 import java.io.IOException;
24 import java.io.ObjectInputStream;
25 import java.io.ObjectOutputStream;
26 import java.io.Serializable;
27 import javax.ws.rs.core.UriBuilder;
28 import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectPlurals;
29 import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectType;
30
31 public abstract class SimplePluralUri<T extends GraphInventoryPluralResourceUri<?, ?>, Parent extends GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?>, PT extends GraphInventoryObjectPlurals, OT extends GraphInventoryObjectType>
32         extends SimpleBaseUri<T, Parent, PT> implements GraphInventoryPluralResourceUri<T, PT>, Serializable {
33
34     private static final long serialVersionUID = -337701171277616439L;
35
36     protected final PT pluralType;
37
38     protected SimplePluralUri(PT type, UriBuilder builder, Object... values) {
39         super(type, builder, values);
40         this.pluralType = type;
41     }
42
43     protected SimplePluralUri(PT type) {
44         super(type, new Object[0]);
45         this.pluralType = type;
46     }
47
48     protected SimplePluralUri(PT type, Object... values) {
49         super(type, values);
50         this.pluralType = type;
51     }
52
53     protected SimplePluralUri(Parent parentUri, PT childType) {
54         super(parentUri, childType, new Object[0]);
55         this.pluralType = childType;
56     }
57
58     public SimplePluralUri(SimplePluralUri<T, Parent, PT, OT> copy) {
59         super(copy);
60         this.pluralType = copy.pluralType;
61     }
62
63     protected void setInternalURI(UriBuilder builder) {
64         this.internalURI = builder;
65     }
66
67     private void writeObject(ObjectOutputStream oos) throws IOException {
68         oos.defaultWriteObject();
69         oos.writeUTF(this.internalURI.toTemplate());
70     }
71
72     private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
73         ois.defaultReadObject();
74         String uri = ois.readUTF();
75         this.setInternalURI(UriBuilder.fromUri(uri));
76     }
77 }