001 /* 002 * Copyright 2005 Stephen J. McConnell. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 013 * implied. 014 * 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package net.dpml.test.composite; 020 021 import java.awt.Color; 022 023 import net.dpml.test.ColorManager; 024 025 /** 026 * Arbitary component used in the testing of parent to child context management. 027 * The key features tested though this class is the assignment of a color value by 028 * the enclosing component (as opposed to a static directive). 029 * 030 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 031 * @version 1.2.0 032 */ 033 public class ChildComponent implements ColorManager 034 { 035 //------------------------------------------------------------------ 036 // concerns 037 //------------------------------------------------------------------ 038 039 /** 040 * The construction criteria. 041 */ 042 public interface Context 043 { 044 /** 045 * Return the assigned color. 046 * @return the color value 047 */ 048 Color getColor(); 049 } 050 051 //------------------------------------------------------------------ 052 // state 053 //------------------------------------------------------------------ 054 055 /** 056 * The assigned context instance. 057 */ 058 private final Context m_context; 059 060 //------------------------------------------------------------------ 061 // constructor 062 //------------------------------------------------------------------ 063 064 /** 065 * Creation of a new singleton component instance. 066 * @param context a context implementation fullfilling the context criteria 067 */ 068 public ChildComponent( final Context context ) 069 { 070 m_context = context; 071 } 072 073 //------------------------------------------------------------------ 074 // Example 075 //------------------------------------------------------------------ 076 077 /** 078 * Return the color value assigned to the component context. 079 * @return the color value 080 */ 081 public Color getColor() 082 { 083 return m_context.getColor(); 084 } 085 }