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.geronimo.management.geronimo; 018 019 import java.util.List; 020 import java.util.ArrayList; 021 import java.beans.PropertyEditor; 022 023 import org.apache.geronimo.gbean.AbstractName; 024 import org.apache.geronimo.common.propertyeditor.PropertyEditors; 025 026 /** 027 * Specialization of NetworkManager for web containers. 028 * 029 * @version $Rev: 562301 $ $Date: 2007-08-02 20:28:32 -0400 (Thu, 02 Aug 2007) $ 030 */ 031 public interface WebManager extends NetworkManager { 032 public final static String PROTOCOL_HTTP = "HTTP"; 033 public final static String PROTOCOL_HTTPS = "HTTPS"; 034 public final static String PROTOCOL_AJP = "AJP"; 035 036 /** 037 * Gets the WebAccessLog implementation for a web container. 038 * May be null if the access log cannot be managed. 039 * 040 * @param container The container whose access log is interesting 041 * 042 */ 043 public WebAccessLog getAccessLog(WebContainer container); 044 045 List<ConnectorType> getConnectorTypes(); 046 047 List<ConnectorAttribute> getConnectorAttributes(ConnectorType connectorType); 048 049 AbstractName getConnectorConfiguration(ConnectorType connectorType, List<ConnectorAttribute> connectorAttributes, WebContainer container, String uniqueName); 050 051 ConnectorType getConnectorType(AbstractName connectorName); 052 053 public class ConnectorType { 054 private final String description; 055 056 057 public ConnectorType(String description) { 058 this.description = description; 059 } 060 061 062 public String getDescription() { 063 return description; 064 } 065 066 067 @Override 068 public int hashCode() { 069 final int PRIME = 31; 070 int result = 1; 071 result = PRIME * result + ((description == null) ? 0 : description.hashCode()); 072 return result; 073 } 074 075 076 @Override 077 public boolean equals(Object obj) { 078 if (this == obj) 079 return true; 080 if (obj == null) 081 return false; 082 if (getClass() != obj.getClass()) 083 return false; 084 final ConnectorType other = (ConnectorType) obj; 085 if (description == null) { 086 if (other.description != null) 087 return false; 088 } else if (!description.equals(other.description)) 089 return false; 090 return true; 091 } 092 } 093 094 public class ConnectorAttribute<T> { 095 private final String attributeName; 096 private String stringValue; 097 private final Class<T> clazz; 098 private T value; 099 private final String description; 100 private boolean required; 101 102 public ConnectorAttribute(String attributeName, T value, String description, Class<T> clazz, boolean required) { 103 this.attributeName = attributeName; 104 this.value = value; 105 this.description = description; 106 this.clazz = clazz; 107 this.required = required; 108 } 109 110 public ConnectorAttribute(String attributeName, T value, String description, Class<T> clazz) { 111 this(attributeName, value, description, clazz, false); 112 } 113 114 public ConnectorAttribute(ConnectorAttribute<T> connectorAttribute) { 115 this.attributeName = connectorAttribute.attributeName; 116 this.value = connectorAttribute.value; 117 this.description = connectorAttribute.description; 118 this.clazz = connectorAttribute.clazz; 119 this.required = connectorAttribute.required; 120 } 121 122 public String getAttributeName() { 123 return attributeName; 124 } 125 126 public String getStringValue() { 127 // Class<T> clazz = getClass().getTypeParameters(); 128 if (value == null) return null; 129 PropertyEditor propertyEditor = PropertyEditors.getEditor(clazz); 130 propertyEditor.setValue(value); 131 return propertyEditor.getAsText(); 132 } 133 134 public void setStringValue(String stringValue) { 135 PropertyEditor propertyEditor = PropertyEditors.getEditor(clazz); 136 propertyEditor.setAsText(stringValue); 137 this.value = (T) propertyEditor.getValue(); 138 } 139 140 public T getValue() { 141 return value; 142 } 143 144 public void setValue(T value) { 145 this.value = value; 146 } 147 148 public String getDescription() { 149 return description; 150 } 151 152 public static List<ConnectorAttribute> copy(List<ConnectorAttribute> source) { 153 List<ConnectorAttribute> copy = new ArrayList<ConnectorAttribute>(source.size()); 154 for (ConnectorAttribute connectorAttribute: source) { 155 copy.add(new ConnectorAttribute(connectorAttribute)); 156 } 157 return copy; 158 } 159 160 public Class<T> getAttributeClass() { 161 return clazz; 162 } 163 164 public boolean isRequired() { 165 return required; 166 } 167 168 public void setRequired(boolean required) { 169 this.required = required; 170 } 171 172 } 173 }