001 // Copyright 2011 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry5.internal.plastic;
016
017 import java.util.ArrayList;
018 import java.util.List;
019
020 /**
021 * Stores static context information needed by a transformed PlasticClass; this includes data such as
022 * injections.
023 */
024 public class StaticContext
025 {
026 private final List<Object> values;
027
028 public StaticContext()
029 {
030 this(new ArrayList<Object>());
031 }
032
033 private StaticContext(List<Object> values)
034 {
035 this.values = values;
036 }
037
038 /**
039 * Duplicates this StaticContext, which is used when creating a subclass
040 * of a transformed class.
041 *
042 * @return new StaticContext with the same values
043 */
044 public StaticContext dupe()
045 {
046 return new StaticContext(new ArrayList<Object>(values));
047 }
048
049 /** Store a context value and return its index. */
050 public int store(Object value)
051 {
052 values.add(value);
053
054 return values.size() - 1;
055 }
056
057 public Object get(int index)
058 {
059 return values.get(index);
060 }
061
062 }