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 import java.rmi.RemoteException; 023 024 import net.dpml.logging.Logger; 025 026 import net.dpml.test.ColorManager; 027 028 import net.dpml.metro.PartsManager; 029 import net.dpml.metro.ComponentHandler; 030 031 import net.dpml.lang.UnknownKeyException; 032 033 /** 034 * This component declares an inner Parts interface through which 035 * it accesses a map of the context infomation of a subsidiary component 036 * named 'child'. The subsidiary component is defined and established 037 * within the component types definition (see build file for details). 038 * 039 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 040 * @version 1.2.0 041 */ 042 public class PartsComponent implements ColorManager 043 { 044 //------------------------------------------------------------------ 045 // concerns 046 //------------------------------------------------------------------ 047 048 /** 049 * The construction criteria. 050 */ 051 public interface Context 052 { 053 /** 054 * Return the assigned color. 055 * @return the color value 056 */ 057 Color getColor(); 058 } 059 060 //------------------------------------------------------------------ 061 // state 062 //------------------------------------------------------------------ 063 064 /** 065 * The logging channel. 066 */ 067 private final Logger m_logger; 068 069 /** 070 * The assigned context instance. 071 */ 072 private final Context m_context; 073 074 /** 075 * The assigned part manager. 076 */ 077 private final PartsManager m_parts; 078 079 //------------------------------------------------------------------ 080 // constructor 081 //------------------------------------------------------------------ 082 083 /** 084 * Creation of a new composite component instance. 085 * @param logger the assingned logging channel 086 * @param context a context implementation 087 * @param parts the parts manager 088 * @exception UnknownKeyException if the implementation uses a bad reference 089 * @exception RemoteException if a remote I/O error occurs 090 */ 091 public PartsComponent( 092 final Logger logger, final Context context, final PartsManager parts ) 093 throws UnknownKeyException, RemoteException 094 { 095 logger.debug( "instantiation" ); 096 097 m_context = context; 098 m_logger = logger; 099 m_parts = parts; 100 101 ComponentHandler handler = parts.getComponentHandler( "child" ); 102 handler.getContextMap().put( "color", context.getColor() ); 103 } 104 105 //------------------------------------------------------------------ 106 // Example 107 //------------------------------------------------------------------ 108 109 /** 110 * Return the color value assigned to the component context. 111 * @return the color value 112 */ 113 public Color getColor() 114 { 115 return m_context.getColor(); 116 } 117 118 //------------------------------------------------------------------ 119 // Validation 120 //------------------------------------------------------------------ 121 122 /** 123 * Return the child component for evaluation by the testcase. 124 * @return the child 125 * @exception Exception if an error occurs 126 */ 127 public ChildComponent getChild() throws Exception 128 { 129 ComponentHandler handler = m_parts.getComponentHandler( "child" ); 130 return (ChildComponent) handler.getProvider().getValue( false ); 131 } 132 133 //------------------------------------------------------------------ 134 // internal 135 //------------------------------------------------------------------ 136 137 /** 138 * Return the assigned logging channel. 139 * @return the logging channel 140 */ 141 private Logger getLogger() 142 { 143 return m_logger; 144 } 145 }