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.station; 020 021 import java.beans.Expression; 022 import java.beans.BeanDescriptor; 023 import java.beans.DefaultPersistenceDelegate; 024 import java.beans.SimpleBeanInfo; 025 import java.beans.Encoder; 026 027 /** 028 * Bean info for state encoding of the ProcessState enumeration. 029 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 030 * @version 1.0.5 031 */ 032 public final class ProcessStateBeanInfo extends SimpleBeanInfo 033 { 034 private static final BeanDescriptor BEAN_DESCRIPTOR = setupBeanDescriptor(); 035 036 /** 037 * Creation of a bean descriptor. 038 * @return the bean descriptor 039 */ 040 public BeanDescriptor getBeanDescriptor() 041 { 042 return BEAN_DESCRIPTOR; 043 } 044 045 private static BeanDescriptor setupBeanDescriptor() 046 { 047 BeanDescriptor descriptor = new BeanDescriptor( ProcessState.class ); 048 descriptor.setValue( 049 "persistenceDelegate", 050 new ScopePersistenceDelegate() ); 051 return descriptor; 052 } 053 054 /** 055 * Scope persitence delegate. 056 */ 057 private static class ScopePersistenceDelegate extends DefaultPersistenceDelegate 058 { 059 /** 060 * Return an expression. 061 * @param old the old value 062 * @param encoder the encoder 063 * @return an expression 064 */ 065 public Expression instantiate( Object old, Encoder encoder ) 066 { 067 ProcessState state = (ProcessState) old; 068 return new Expression( state, ProcessState.class, "parse", new Object[]{state.getName()} ); 069 } 070 } 071 }