KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > properties > attributes > wizards > actions > AttributeDefinitionFinishAction


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.properties.attributes.wizards.actions;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.struts.action.ActionForm;
31 import org.apache.struts.action.ActionForward;
32 import org.apache.struts.action.ActionMapping;
33
34 import com.sslexplorer.boot.PropertyClassManager;
35 import com.sslexplorer.core.CoreEvent;
36 import com.sslexplorer.core.CoreEventConstants;
37 import com.sslexplorer.core.CoreServlet;
38 import com.sslexplorer.properties.ProfilesFactory;
39 import com.sslexplorer.properties.attributes.AttributeDefinition;
40 import com.sslexplorer.properties.attributes.AttributesPropertyClass;
41 import com.sslexplorer.security.SessionInfo;
42 import com.sslexplorer.wizard.AbstractWizardSequence;
43 import com.sslexplorer.wizard.WizardActionStatus;
44 import com.sslexplorer.wizard.actions.AbstractWizardAction;
45 import com.sslexplorer.wizard.forms.AbstractWizardFinishForm;
46
47 /**
48  * <p>
49  * The final action in which the resource is created.
50  *
51  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
52  *
53  */

54 public class AttributeDefinitionFinishAction extends AbstractWizardAction {
55     final static Log log = LogFactory.getLog(AttributeDefinitionFinishAction.class);
56
57     /**
58      * Constructor.
59      */

60     public AttributeDefinitionFinishAction() {
61         super();
62     }
63
64     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
65         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
66     }
67     
68     public static AttributeDefinition createDefinition(AbstractWizardSequence seq) {
69
70         String JavaDoc name = (String JavaDoc) seq.getAttribute(AttributeDefinitionDetailsAction.ATTR_NAME, null);
71         String JavaDoc description = (String JavaDoc) seq.getAttribute(AttributeDefinitionDetailsAction.ATTR_DESCRIPTION, null);
72         String JavaDoc attributeClassName = (String JavaDoc) seq.getAttribute(AttributeDefinitionDetailsAction.ATTR_CLASS, null);
73         String JavaDoc typeMeta = (String JavaDoc) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_TYPE_META, null);
74         String JavaDoc label = (String JavaDoc) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_LABEL, null);
75         String JavaDoc category = (String JavaDoc) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_CATEGORY, null);
76         String JavaDoc defaultValue = (String JavaDoc) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_DEFAULT_VALUE, null);
77         String JavaDoc validationString = (String JavaDoc) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_VALIDATION_STRING, null);
78         int visibility = ((Integer JavaDoc) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_VISIBILITY, null)).intValue();
79         int sortOrder = ((Integer JavaDoc) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_SORT_ORDER, null)).intValue();
80         int type = ((Integer JavaDoc) seq.getAttribute(AttributeDefinitionOptionsAction.ATTR_TYPE, null)).intValue();
81         AttributesPropertyClass attributeClass = (AttributesPropertyClass) PropertyClassManager.getInstance()
82                         .getPropertyClass(attributeClassName);
83         AttributeDefinition def = attributeClass.createAttributeDefinition(type,
84                             name,
85                             typeMeta,
86                             -1,
87                             category,
88                             defaultValue,
89                             visibility,
90                             sortOrder,
91                             null,
92                             false,
93                             label,
94                             description,
95                             false,
96                             true,
97                             validationString);
98         return def;
99         
100     }
101
102     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
103                                      HttpServletResponse JavaDoc response) throws Exception JavaDoc {
104         List JavaDoc actionStatus = new ArrayList JavaDoc();
105         AbstractWizardSequence seq = getWizardSequence(request);
106         try {
107             try {
108                 AttributeDefinition def = createDefinition(seq);
109                 ProfilesFactory.getInstance().createAttributeDefinition(def);
110                 def.getPropertyClass().registerPropertyDefinition(def);
111                 CoreServlet.getServlet().fireCoreEvent(new CoreEvent(this,
112                                 CoreEventConstants.ATTRIBUTE_DEFINITION_CREATED,
113                                 def,
114                                 getSessionInfo(request),
115                                 CoreEvent.STATE_SUCCESSFUL));
116             } catch (Exception JavaDoc e) {
117                 CoreServlet.getServlet().fireCoreEvent(new CoreEvent(this,
118                                 CoreEventConstants.ATTRIBUTE_DEFINITION_CREATED,
119                                 null,
120                                 getSessionInfo(request),
121                                 e));
122                 throw e;
123             }
124             actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK,
125                             "attributeDefinitionWizard.attributeDefinitionFinish.status.attributeCreated"));
126         } catch (Exception JavaDoc e) {
127             log.error("Failed to create profile.", e);
128             actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
129                             "attributeDefinitionWizard.attributeDefinitionFinish.status.failedToCreateAttribute",
130                             e.getMessage()));
131         }
132         ((AbstractWizardFinishForm) form).setActionStatus(actionStatus);
133         return super.unspecified(mapping, form, request, response);
134     }
135
136     public ActionForward exit(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
137                     throws Exception JavaDoc {
138         return cancel(mapping, form, request, response);
139     }
140
141 }
142
Popular Tags