[jboss-cvs] jboss-portal/portlet/src/main/org/jboss/portal/portlet ...
Julien Viet
julien at jboss.com
Sun Jul 30 20:39:29 EDT 2006
User: julien
Date: 06/07/30 20:39:29
Added: portlet/src/main/org/jboss/portal/portlet Properties.java
TransportGuarantee.java
Log:
package move of Properties and TransportGuarantee to org.jboss.portal.portlet
Revision Changes Path
1.1 date: 2006/07/31 00:39:29; author: julien; state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/Properties.java
Index: Properties.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.portal.portlet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Collections;
import java.util.Set;
/**
* A set of multi valued properties produced by a response.
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class Properties
{
private Map content;
public Properties()
{
}
/**
* @param name the property name
* @param value the property value
* @throws IllegalArgumentException if name or value is null
*/
public void addProperty(String name, String value)
{
if (name == null)
{
throw new IllegalArgumentException("Name cannot be null");
}
if (value == null)
{
throw new IllegalArgumentException("Value cannot be null");
}
if (content == null)
{
content = new HashMap();
}
Object o = content.get(name);
if (o == null)
{
content.put(name, value);
}
else if (o instanceof String)
{
ArrayList values = new ArrayList();
values.add(o);
values.add(value);
content.put(name, values);
}
else
{
ArrayList values = (ArrayList)o;
values.add(value);
}
}
/**
* @param name the property name
* @param value the property value
* @throws IllegalArgumentException if name or value is null
*/
public void setProperty(String name, String value)
{
if (name == null)
{
throw new IllegalArgumentException("Name cannot be null");
}
if (value == null)
{
throw new IllegalArgumentException("Value cannot be null");
}
if (content == null)
{
content = new HashMap();
}
content.put(name, value);
}
/**
* Clear the properties.
*/
public void clear()
{
if (content != null)
{
content.clear();
}
}
public String getProperty(String name)
{
if (name == null)
{
throw new IllegalArgumentException("Name cannot be null");
}
if (content == null)
{
return null;
}
Object o = content.get(name);
if (o == null)
{
return null;
}
else if (o instanceof String)
{
return (String)o;
}
else
{
return (String)((ArrayList)o).get(0);
}
}
/**
* @param name the property name
* @return the list of properties for the specified name or null if it does not exist
* @throws IllegalArgumentException if name is null
*/
public List getProperties(String name)
{
if (name == null)
{
throw new IllegalArgumentException("Name cannot be null");
}
if (content == null)
{
return null;
}
Object o = content.get(name);
if (o == null)
{
return null;
}
if (o instanceof String)
{
return Collections.singletonList(o);
}
else
{
return (List)o;
}
}
public Set getPropertyNames()
{
if (content == null)
{
return Collections.EMPTY_SET;
}
return content.keySet();
}
}
1.1 date: 2006/07/31 00:39:29; author: julien; state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/TransportGuarantee.java
Index: TransportGuarantee.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.portal.portlet;
/**
* Type safe enumeration class for transport guarantee.
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class TransportGuarantee
{
/**
*
*/
public static final TransportGuarantee NONE = new TransportGuarantee(0);
/**
*
*/
public static final TransportGuarantee INTEGRAL = new TransportGuarantee(1);
/**
*
*/
public static final TransportGuarantee CONFIDENTIAL = new TransportGuarantee(2);
/**
*
*/
private static final TransportGuarantee[] ALL = {NONE,INTEGRAL,CONFIDENTIAL};
/**
*
*/
// private static final boolean[][] IMPLIES =
// {
// { true, false, false },
// { true, true, true },
// { true, true, true }
// };
/**
*
*/
private static final String[] NAMES = {"NONE","INTEGRAL","CONFIDENTIAL"};
public static TransportGuarantee decode(String name)
{
for (int i = 0; i < NAMES.length; i++)
{
if (NAMES[i].equals(name))
{
return ALL[i];
}
}
throw new IllegalArgumentException();
}
private int ordinal;
private TransportGuarantee(int ordinal)
{
this.ordinal = ordinal;
}
public String getName()
{
return NAMES[ordinal];
}
// public boolean implies(TransportGuarantee that)
// {
// if (that == null)
// {
// throw new IllegalArgumentException();
// }
// return IMPLIES[this.ordinal][that.ordinal];
// }
public int hashCode()
{
return ordinal;
}
public boolean equals(Object obj)
{
if (obj == this)
{
return true;
}
if (obj instanceof TransportGuarantee)
{
TransportGuarantee that = (TransportGuarantee)obj;
return this.ordinal == that.ordinal;
}
return false;
}
}
More information about the jboss-cvs-commits
mailing list