Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | package org.onosproject.config.model; |
| 17 | |
| 18 | /** |
| 19 | * Created by sdn on 12/15/16. |
| 20 | */ |
| 21 | public class DefaultResourceIdentifier<V> implements ResourceIdentifier { |
| 22 | NodeKey key; |
| 23 | ResourceIdentifier next; |
| 24 | |
| 25 | public DefaultResourceIdentifier(String nm, String nmspc) { |
| 26 | this.key = new NodeKey(nm, nmspc); |
| 27 | this.next = null; |
| 28 | } |
| 29 | |
| 30 | public DefaultResourceIdentifier(ResourceIdentifier parent, NodeKey ckey) { |
| 31 | this.key = parent.nodeKey(); |
| 32 | //new NodeKey(parent.nodeKey().schemaId.name, parent.nodeKey().schemaId.nameSpace); |
| 33 | this.next = new DefaultResourceIdentifier(ckey); |
| 34 | } |
| 35 | |
| 36 | public DefaultResourceIdentifier(ResourceIdentifier parent, ResourceIdentifier child) { |
| 37 | this.key = parent.nodeKey(); |
| 38 | this.next = child; |
| 39 | } |
| 40 | |
| 41 | public DefaultResourceIdentifier(NodeKey nkey) { |
| 42 | this.key = nkey; |
| 43 | this.next = null; |
| 44 | } |
| 45 | |
| 46 | /*public void setChild(NodeKey ckey) { |
| 47 | this.next = new DefaultResourceIdentifier(ckey); |
| 48 | }*/ |
| 49 | |
| 50 | @Override |
| 51 | public NodeKey nodeKey() { |
| 52 | return this.key; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public ResourceIdentifier descendentIdentifier() { |
| 57 | return this.next; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public String getBase() { |
| 62 | return this.key.schemaId.name.concat("#").concat(this.key.schemaId.nameSpace); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public String asString() { |
| 67 | String base = getBase(); |
| 68 | ResourceIdentifier desc = next; |
| 69 | while (desc != null) { |
| 70 | base.concat(".").concat(desc.getBase()); |
| 71 | desc = desc.descendentIdentifier(); |
| 72 | } |
| 73 | return base; |
| 74 | } |
| 75 | } |