001: /**
002: * $Id: CreateAttributeBean.java,v 1.4 2005/11/03 23:55:10 sorensen Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.console.ssoa;
014:
015: import java.util.*;
016: import java.util.logging.Level;
017: import com.sun.data.provider.impl.ObjectListDataProvider;
018: import com.sun.web.ui.model.Option;
019: import com.sun.web.ui.event.WizardEvent;
020: import com.sun.web.ui.event.WizardEventListener;
021:
022: import javax.faces.application.FacesMessage;
023: import javax.faces.component.UIComponent;
024: import javax.faces.context.FacesContext;
025: import javax.faces.event.ActionEvent;
026: import javax.faces.validator.ValidatorException;
027: import javax.management.MBeanServerConnection;
028: import javax.servlet.http.HttpServletRequest;
029:
030: public class CreateAttributeBean extends TemplateAttributesBean {
031:
032: private String type;
033: // private Option[] availableTypes;
034: private String name;
035: private String value;
036: private boolean encrypted = false;
037:
038: // protected Map rbMap;
039: // public static final String RB_NAME = "ssoa";
040:
041: // public CreateAttributeBean() {
042: // rbMap = getResourceStringMap(RB_NAME);
043: // }
044:
045: public String getType() {
046: //log(Level.FINEST, "CreateAttributeBean.getType start");
047: if (type == null) {
048: type = (String) getSessionAttribute(ATTR_TYPE);
049: }
050: return type;
051: }
052:
053: public void setType(String type) {
054: //log(Level.FINEST, "CreateAttributeBean.setType start");
055: this .type = type;
056: }
057:
058: public boolean getIsAdminType() {
059: //log(Level.FINEST, "CreateAttributeBean.getIsAdminType start");
060: return ADMIN_TYPE.equals(getType());
061: }
062:
063: // public Option[] getAvailableTypes() {
064: // log(Level.FINEST, "CreateAttributeBean.getAvailableTypes start");
065: // return availableTypes;
066: // }
067:
068: public String getValue() {
069: return value;
070: }
071:
072: public void setValue(String value) {
073: this .value = value;
074: }
075:
076: public String getName() {
077: return name;
078: }
079:
080: public void setName(String name) {
081: this .name = name;
082: }
083:
084: public boolean getEncrypted() {
085: return encrypted;
086: }
087:
088: public void setEncrypted(boolean encrypted) {
089: this .encrypted = encrypted;
090: }
091:
092: public String add() {
093: log(Level.FINEST, "CreatAttributeBean.add start");
094: log(Level.FINEST, "CreatAttributeBean.add bean is name:" + name
095: + " value:" + value + " encrypted:" + encrypted);
096: if (ADMIN_TYPE.equals(getType())) {
097: // if (value == null) value="";
098: AttributeBean ab = new AttributeBean(name, value, encrypted);
099: //List aal = adminAttributes.getList();
100: //aal.add(ab);
101: adminAttributes.addObject(ab);
102: adminAttributes.commitChanges();
103: saveTemplate();
104: } else if (USER_TYPE.equals(getType())) {
105: AttributeBean ab = new AttributeBean(name, value, encrypted);
106: //List ual = userAttributes.getList();
107: //ual.add(ab);
108: userAttributes.addObject(ab);
109: userAttributes.commitChanges();
110: saveTemplate();
111: } else {
112: log(Level.WARNING,
113: "CreatAttributeBean.add: Illegal attribute type "
114: + type);
115: }
116: setSessionAttribute("resetSSOA", "true");
117: return cancel();
118: }
119:
120: //============================================================
121: // validator for unique attribute name
122: //============================================================
123: public void validateName(FacesContext ctx, UIComponent comp,
124: Object value) {
125: log(Level.FINEST, "CreatAttributeBean.validateName start");
126: resetAttributes();
127: String sm = (String) rbMap.get("error.validation.summary");
128: String dmAdmin = (String) rbMap
129: .get("error.duplicate.admin.attribute");
130: String dmUser = (String) rbMap
131: .get("error.duplicate.user.attribute");
132: String cn = (String) value;
133: log(Level.FINEST,
134: "CreatAttributeBean.validateName Checking for duplicate of "
135: + cn);
136: // Make sure this isn't in the list of admin or user attributes
137: List aal = adminAttributes.getList();
138: for (int i = 0; i < aal.size(); i++) {
139: AttributeBean ab = (AttributeBean) aal.get(i);
140: if (ab.getName().equals(cn)) {
141: log(Level.FINEST,
142: "CreatAttributeBean.validateName Duplicate found "
143: + ab.getName());
144: throw new ValidatorException(new FacesMessage(sm,
145: dmAdmin));
146: }
147: }
148: List ual = userAttributes.getList();
149: for (int i = 0; i < ual.size(); i++) {
150: AttributeBean ab = (AttributeBean) ual.get(i);
151: if (ab.getName().equals(cn)) {
152: log(Level.FINEST,
153: "CreatAttributeBean.validateName Duplicate found "
154: + ab.getName());
155: throw new ValidatorException(new FacesMessage(sm,
156: dmUser));
157: }
158: }
159: }
160:
161: public String cancel() {
162: log(Level.FINEST, "CreateTemplateBean.cancel start");
163: // Reset the bean
164: name = null;
165: value = null;
166: type = null;
167: encrypted = false;
168: //adminAttributes = null;
169: //userAttributes = null;
170: return "cancel";
171: }
172:
173: }
|