/*******************************************************************************
 * Mission Control Technologies, Copyright (c) 2009-2012, United States Government
 * as represented by the Administrator of the National Aeronautics and Space 
 * Administration. All rights reserved.
 *
 * The MCT platform is licensed under the Apache License, Version 2.0 (the 
 * "License"); you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
 * License for the specific language governing permissions and limitations under 
 * the License.
 *
 * MCT includes source code licensed under additional open source licenses. See 
 * the MCT Open Source Licenses file included with this distribution or the About 
 * MCT Licenses dialog available at runtime from the MCT Help menu for additional 
 * information. 
 *******************************************************************************/
package gov.nasa.arc.mct.scenario.component;

import gov.nasa.arc.mct.components.AbstractComponent;
import gov.nasa.arc.mct.components.JAXBModelStatePersistence;
import gov.nasa.arc.mct.components.ModelStatePersistence;

import java.util.concurrent.atomic.AtomicReference;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

public class TagRepositoryComponent extends AbstractComponent implements RepositoryCapability {
	private AtomicReference<TagRepositoryModel> model =
			new AtomicReference<TagRepositoryModel>(new TagRepositoryModel());

	@Override
	public <T> T handleGetCapability(Class<T> capabilityClass) {
		return (capabilityClass.isAssignableFrom(ModelStatePersistence.class)) ?
			capabilityClass.cast(persistence) :
			super.handleGetCapability(capabilityClass);
	}
	
	@Override
	public Class<?> getCapabilityClass() {
		return TagComponent.class;
	}

	@Override
	public String getUserScope() {
		return model.get().scope;
	}
	
	public void setUserScope(String scope) {
		model.get().scope = scope;
	}
	
	@XmlRootElement
	@XmlAccessorType(XmlAccessType.FIELD)
	public static class TagRepositoryModel {
		private String scope = "";
	}
	
	private final ModelStatePersistence persistence = 
			new JAXBModelStatePersistence<TagRepositoryModel>() {
		@Override
		protected TagRepositoryModel getStateToPersist() {
			return model.get();
		}

		@Override
		protected void setPersistentState(TagRepositoryModel modelState) {
			model.set(modelState);
		}

		@Override
		protected Class<TagRepositoryModel> getJAXBClass() {
			return TagRepositoryModel.class;
		}		
	};
}

@@ -1303,16 +1303,62 @@
 ponent;%0A
+import gov.nasa.arc.mct.components.Bootstrap;%0A
 import g
@@ -1411,16 +1411,16 @@
 stence;%0A
-
 import g
@@ -1764,16 +1764,27 @@
 pability
+, Bootstrap
  %7B%0A%09priv
@@ -1974,16 +1974,17 @@
 Class) %7B
+%09
 %0A%09%09retur
@@ -1984,18 +1984,105 @@
 %09%09return
- (
+%0A%09%09%09capabilityClass.isAssignableFrom(getClass()) ? %0A%09%09%09%09%09capabilityClass.cast(this) :%0A%09%09%09
 capabili
@@ -2138,12 +2138,14 @@
 ass)
-)
  ?
-%0A
+ %0A%09%09
 %09%09%09c
@@ -2315,16 +2315,67 @@
 ss;%0A%09%7D%0A%0A
+%09// TODO: Use this to support the Group capability%0A
 %09@Overri
@@ -3077,10 +3077,452 @@
 %7D%09%09%0A
-
 %09%7D;
+%0A%0A%09@Override%0A%09public boolean isGlobal() %7B%0A%09%09return getCreator().equals(%22*%22);%0A%09%7D%0A%0A%09@Override%0A%09public boolean isSandbox() %7B%0A%09%09return false;%0A%09%7D%0A%0A%09@Override%0A%09public int categoryIndex() %7B%0A%09%09// Categorize by package - %22somewhere in the middle%22,%0A%09%09// but grouped with other components from the same package.%0A%09%09return getClass().getPackage().getName().hashCode() & 0xFFFF;%0A%09%7D%0A%0A%09@Override%0A%09public int componentIndex() %7B%0A%09%09return isGlobal() ? 0 : 1;%0A%09%7D
 %0A%7D%0A

Implement Bootstrap for tag repository