Home » rampart-dist-1.4-src » org.apache » rampart » policy » model » [javadoc | source]

    1   /*
    2    * Copyright 2001-2004 The Apache Software Foundation.
    3    * 
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    * 
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    * 
   10    * Unless required by applicable law or agreed to in writing, software
   11    * distributed under the License is distributed on an "AS IS" BASIS,
   12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13    * See the License for the specific language governing permissions and
   14    * limitations under the License.
   15    */
   16   
   17   package org.apache.rampart.policy.model;
   18   
   19   import java.util.HashMap;
   20   import java.util.Iterator;
   21   import java.util.Map;
   22   import java.util.Vector;
   23   
   24   import javax.xml.namespace.QName;
   25   import javax.xml.stream.XMLStreamException;
   26   import javax.xml.stream.XMLStreamWriter;
   27   
   28   import org.apache.neethi.Assertion;
   29   import org.apache.neethi.Constants;
   30   import org.apache.neethi.PolicyComponent;
   31   
   32   
   33   public class OptimizePartsConfig implements Assertion{
   34   
   35   	public final static String OPTIMIZE_PARTS_LN = RampartConfig.OPTIMISE_PARTS;
   36   	public final static String EXPRESSIONS_LN = "expressions";
   37   	public final static String EXPRESSION_LN = "expression";
   38   	public final static String NAMESPACES_LN = "namespaces";
   39   	public final static String NAMESPACE_LN = "namespace";
   40   	public final static String URI_ATTR = "uri";
   41   	public final static String PREFIX_ATTR = "prefix";
   42   	
   43   	private Map namespaces = null;
   44   	private Vector expressions = null;
   45   	
   46   	public OptimizePartsConfig(){
   47   		namespaces = new HashMap();
   48   		expressions = new Vector();
   49   	}
   50   	
   51   	public void addExpression(String expression){
   52   		expressions.add(expression);
   53   	}
   54   	
   55   	public void addNamespaces(String prefix, String ns){
   56   		namespaces.put(prefix, ns);
   57   	}
   58   	
   59   	public Vector getExpressions() {
   60   		return expressions;
   61   	}
   62   
   63   	public Map getNamespaces() {
   64   		return namespaces;
   65   	}
   66   	
   67   	public short getType() {
   68           return Constants.TYPE_ASSERTION;
   69   	}
   70   	
   71   	public QName getName() {
   72   		return new QName(RampartConfig.NS, OPTIMIZE_PARTS_LN);
   73   	}
   74   	
   75   	public void serialize(XMLStreamWriter writer) throws XMLStreamException {
   76   		String prefix = writer.getPrefix(RampartConfig.NS);
   77           
   78           if (prefix == null) {
   79               prefix = RampartConfig.NS;
   80               writer.setPrefix(prefix, RampartConfig.NS);
   81           }                
   82           
   83           writer.writeStartElement(RampartConfig.NS, OPTIMIZE_PARTS_LN);
   84           
   85           if((expressions != null) && (expressions.size()>0)){
   86           	  writer.writeStartElement(RampartConfig.NS, EXPRESSIONS_LN);
   87           	  Iterator ite = expressions.iterator();
   88           	  while(ite.hasNext()){
   89           		  writer.writeStartElement(RampartConfig.NS, EXPRESSION_LN);
   90           		  String exp = (String)ite.next();
   91           		  writer.writeCharacters(exp);
   92           		  writer.writeEndElement();
   93           	  }
   94                 writer.writeEndElement();
   95           }
   96           
   97           if((namespaces != null) && (namespaces.size()>0)){
   98           	  writer.writeStartElement(RampartConfig.NS, NAMESPACES_LN);
   99           	  Iterator ite = namespaces.keySet().iterator();
  100           	  while(ite.hasNext()){
  101           		  String strPrefix = (String)ite.next();
  102           		  String strURI = (String) namespaces.get(strPrefix);
  103           		  writer.writeAttribute(URI_ATTR , strURI);
  104           		  writer.writeAttribute(PREFIX_ATTR, strPrefix);
  105           		  writer.writeEndElement();
  106           	  }
  107                 writer.writeEndElement();
  108           }
  109           writer.writeEndElement();
  110   	}
  111   	
  112   	public PolicyComponent normalize() {
  113   		//TODO
  114   		throw new UnsupportedOperationException("TODO");
  115   	}
  116   	
  117   	public boolean isOptional() {
  118   		throw new UnsupportedOperationException("Not relevant");
  119   	}
  120   	
  121   	public boolean equal(PolicyComponent arg0) {
  122   		throw new UnsupportedOperationException("Not relevant");
  123   	}
  124   
  125   	
  126   
  127   
  128   }

Home » rampart-dist-1.4-src » org.apache » rampart » policy » model » [javadoc | source]