001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.portlets.profiler;
018:
019: import java.io.Serializable;
020: import java.util.Collection;
021: import java.util.Map;
022:
023: import javax.faces.context.FacesContext;
024: import javax.faces.event.ActionEvent;
025: import javax.faces.model.SelectItem;
026:
027: import org.apache.jetspeed.CommonPortletServices;
028: import org.apache.jetspeed.profiler.Profiler;
029: import org.apache.jetspeed.profiler.ProfilerException;
030: import org.apache.jetspeed.profiler.rules.ProfilingRule;
031:
032: /**
033: * Profile state.
034: *
035: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
036: * @version $Id: ProfileRuleForm.java 348264 2005-11-22 22:06:45Z taylor $
037: */
038: public class ProfileRuleForm implements Serializable {
039: private boolean isNew = false;
040: private transient Profiler profiler = null;
041: private transient ProfilingRule rule = null;
042: private static final SelectItem[] CLASSNAMES = {
043: new SelectItem(
044: "org.apache.jetspeed.profiler.rules.impl.StandardProfilingRule"),
045: new SelectItem(
046: "org.apache.jetspeed.profiler.rules.impl.RoleFallbackProfilingRule") };
047:
048: public ProfileRuleForm() {
049: }
050:
051: public boolean getUpdating() {
052: return !isNew;
053: }
054:
055: public void listen(ActionEvent event) {
056: Map appMap = FacesContext.getCurrentInstance()
057: .getExternalContext().getApplicationMap();
058: profiler = (Profiler) appMap
059: .get(CommonPortletServices.CPS_PROFILER_COMPONENT);
060: Map params = FacesContext.getCurrentInstance()
061: .getExternalContext().getRequestParameterMap();
062: String selected = (String) params.get("selectedRule");
063: if (selected != null && profiler != null) {
064: rule = profiler.getRule(selected);
065: isNew = false;
066: }
067: }
068:
069: public SelectItem[] getClassnames() {
070: return CLASSNAMES;
071: }
072:
073: public String getTitle() {
074: if (rule == null) {
075: return "{empty}";
076: }
077: return rule.getTitle();
078: }
079:
080: public void setTitle(String title) {
081: if (rule != null) {
082: this .rule.setTitle(title);
083: }
084: }
085:
086: public String getClassname() {
087: if (rule == null) {
088: return "{empty}";
089: }
090: return rule.getClassname();
091: }
092:
093: public void setClassname(String classname) {
094: if (rule != null) {
095: this .rule.setClassname(classname);
096: }
097: }
098:
099: public String getId() {
100: if (rule == null) {
101: return "{empty}";
102: }
103: return rule.getId();
104: }
105:
106: public void setId(String id) {
107: if (rule != null) {
108: this .rule.setId(id);
109: }
110: }
111:
112: // actions
113:
114: public String saveProfile() {
115: try {
116: profiler.storeProfilingRule(this .rule);
117: isNew = false;
118: } catch (ProfilerException e) {
119: System.out.println("Failed to UPDATE: rule = "
120: + rule.getId());
121: // TODO: forward to an error page
122: }
123: return null;
124: }
125:
126: public String removeProfile() {
127: try {
128: profiler.deleteProfilingRule(rule);
129: } catch (ProfilerException e) {
130: System.out.println("Failed to REMOVE: rule = "
131: + rule.getId());
132: // TODO: forward to an error page
133: }
134: return null;
135: }
136:
137: public String createNewProfile() {
138: try {
139: Class defaultClass = profiler
140: .getClass()
141: .getClassLoader()
142: .loadClass(
143: "org.apache.jetspeed.profiler.rules.impl.StandardProfilingRule");
144: this .rule = (ProfilingRule) defaultClass.newInstance();
145: } catch (Exception e) {
146: System.out.println("Failed to CREATE NEW: rule = "
147: + rule.getId());
148: // TODO: forward to an error page
149: }
150: this .setId("");
151: this .setTitle("");
152: this
153: .setClassname("org.apache.jetspeed.profiler.rules.impl.StandardProfilingRule");
154: isNew = true;
155: return null;
156: }
157:
158: public Collection getCriteria() {
159: return rule.getRuleCriteria();
160: }
161: }
|