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; 020 021 import java.awt.Color; 022 023 import net.dpml.logging.Logger; 024 025 /** 026 * Component implementation that demonstrates the use of a context inner-class. 027 * 028 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 029 * @version 1.2.0 030 */ 031 public class ExampleComponent implements ColorManager 032 { 033 //------------------------------------------------------------------ 034 // concerns 035 //------------------------------------------------------------------ 036 037 /** 038 * Component driven context criteria specification. 039 */ 040 public interface Context 041 { 042 /** 043 * Return a non-optional color value. 044 * @return the color 045 */ 046 Color getColor(); 047 } 048 049 //------------------------------------------------------------------ 050 // state 051 //------------------------------------------------------------------ 052 053 /** 054 * The logging channel. 055 */ 056 private final Logger m_logger; 057 058 /** 059 * The assigned context instance. 060 */ 061 private final Context m_context; 062 063 //------------------------------------------------------------------ 064 // constructor 065 //------------------------------------------------------------------ 066 067 /** 068 * Creation of a new <tt>ExampleComponent</tt> using a supplied 069 * logging channel and context. 070 * 071 * @param logger the assigned logging channel 072 * @param context the assigned context 073 */ 074 public ExampleComponent( final Logger logger, final Context context ) 075 { 076 m_context = context; 077 m_logger = logger; 078 079 getLogger().debug( "example component created" ); 080 } 081 082 //------------------------------------------------------------------ 083 // Example 084 //------------------------------------------------------------------ 085 086 /** 087 * Return the color value from the supplied context. 088 * @return the color value 089 */ 090 public Color getColor() 091 { 092 return m_context.getColor(); 093 } 094 095 //------------------------------------------------------------------ 096 // internal 097 //------------------------------------------------------------------ 098 099 /** 100 * Return the assigned logging channel. 101 * @return the logging channel 102 */ 103 private Logger getLogger() 104 { 105 return m_logger; 106 } 107 }