001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.workflow.spi.hibernate;
006:
007: import com.opensymphony.workflow.FactoryException;
008: import com.opensymphony.workflow.loader.WorkflowDescriptor;
009: import com.opensymphony.workflow.loader.WorkflowFactory;
010:
011: import org.springframework.context.ApplicationContext;
012: import org.springframework.context.ApplicationContextAware;
013:
014: import java.util.Properties;
015:
016: /**
017: * Spring-compliant implementation of {@link com.opensymphony.workflow.loader.AbstractWorkflowFactory}. This
018: * workflow factory retrieves {@link com.opensymphony.workflow.loader.WorkflowDescriptor}s from the Spring's
019: * {@link ApplicationContext}. The name of the WorkflowDescriptors is the name
020: * of the bean in the applicationContext. <br />
021: * Motivation: reduce number of external configuration files leaving only
022: * workflow definitions files. <br />
023: * <ul>
024: * <li>SpringConfiguration replaces osworkflow.xml</li>
025: * <li>WorkflowFactoryImpl replaces workflows.xml</li>
026: * </ul>
027: * Usage:
028: * <pre>
029: * <bean id="myworkflow" class="com.opensymphony.workflow.spi.hibernate.WorkflowDescriptorFactoryBean">
030: * <property name="descriptorResource">
031: * <value>classpath:/META-INF/workflow/myworkflow.xml</value>
032: * </property>
033: * </bean>
034: *
035: * <bean id="workflowFactory" class="com.opensymphony.workflow.spi.hibernate.BeanNameWorkflowFactory"/>
036: * </pre>
037: *
038: * @author xd
039: */
040: public class SpringBeanNameWorkflowFactory implements WorkflowFactory,
041: ApplicationContextAware {
042: //~ Instance fields ////////////////////////////////////////////////////////
043:
044: //////////////////////////////////////////////////~ Instance attributes. //
045:
046: /** The applicationContext. */
047: private ApplicationContext applicationContext;
048:
049: //~ Methods ////////////////////////////////////////////////////////////////
050:
051: public void setApplicationContext(
052: final ApplicationContext inApplicationContext) {
053: this .applicationContext = inApplicationContext;
054: }
055:
056: public void setLayout(String workflowName, Object layout) {
057: }
058:
059: public Object getLayout(String workflowName) {
060: return null;
061: }
062:
063: public boolean isModifiable(String name) {
064: return false;
065: }
066:
067: public String getName() {
068: return null;
069: }
070:
071: public Properties getProperties() {
072: return null;
073: }
074:
075: //////////////////////////~ AbstractWorkflowFactory implemented methods. //
076: public WorkflowDescriptor getWorkflow(final String inName) {
077: return (WorkflowDescriptor) this .applicationContext
078: .getBean(inName);
079: }
080:
081: public WorkflowDescriptor getWorkflow(String name, boolean validate)
082: throws FactoryException {
083: return getWorkflow(name);
084: }
085:
086: public String[] getWorkflowNames() {
087: return this .applicationContext
088: .getBeanDefinitionNames(WorkflowDescriptor.class);
089: }
090:
091: public void createWorkflow(String name) {
092: }
093:
094: public void init(Properties p) {
095: }
096:
097: public void initDone() throws FactoryException {
098: }
099:
100: public boolean removeWorkflow(final String inName)
101: throws FactoryException {
102: throw new FactoryException("Unsupported operation.");
103: }
104:
105: public void renameWorkflow(String oldName, String newName) {
106: }
107:
108: public void save() {
109: }
110:
111: public boolean saveWorkflow(final String inName,
112: final WorkflowDescriptor inDescriptor,
113: final boolean inReplace) throws FactoryException {
114: throw new FactoryException("Unsupported operation.");
115: }
116: }
|