Save This Page
Home » axis2-1.5-src » org.apache » axis2 » description » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements. See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership. The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License. You may obtain a copy of the License at
    9    *
   10    * http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied. See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   
   20   
   21   package org.apache.axis2.description;
   22   
   23   import org.apache.axiom.om.OMAttribute;
   24   import org.apache.axiom.om.OMElement;
   25   import org.apache.axis2.AxisFault;
   26   import org.apache.axis2.context.externalize.ExternalizeConstants;
   27   import org.apache.axis2.context.externalize.SafeObjectInputStream;
   28   import org.apache.axis2.context.externalize.SafeObjectOutputStream;
   29   import org.apache.axis2.context.externalize.SafeSerializable;
   30   import org.apache.axis2.deployment.DeploymentConstants;
   31   import org.apache.axis2.util.JavaUtils;
   32   import org.apache.axis2.util.Utils;
   33   import org.apache.commons.logging.Log;
   34   import org.apache.commons.logging.LogFactory;
   35   
   36   import javax.xml.namespace.QName;
   37   import java.io.Externalizable;
   38   import java.io.IOException;
   39   import java.io.ObjectInput;
   40   import java.io.ObjectOutput;
   41   import java.util.ArrayList;
   42   import java.util.Collection;
   43   import java.util.HashMap;
   44   import java.util.Iterator;
   45   
   46   /**
   47    * Class ParameterIncludeImpl
   48    */
   49   public class ParameterIncludeImpl 
   50       implements ParameterInclude, Externalizable, SafeSerializable {
   51   
   52       /*
   53        * setup for logging
   54        */
   55       private static final Log log = LogFactory.getLog(ParameterIncludeImpl.class);
   56       private static boolean DEBUG_ENABLED = log.isTraceEnabled();
   57       private static boolean DEBUG_PROPERTY_SET = log.isDebugEnabled();
   58   
   59       private static final String myClassName = "ParameterIncludeImpl";
   60   
   61       /**
   62        * @serial The serialization version ID tracks the version of the class.
   63        * If a class definition changes, then the serialization/externalization
   64        * of the class is affected. If a change to the class is made which is
   65        * not compatible with the serialization/externalization of the class,
   66        * then the serialization version ID should be updated.
   67        * Refer to the "serialVer" utility to compute a serialization
   68        * version ID.
   69        */
   70       private static final long serialVersionUID = 8153736719090126891L;
   71   
   72       /**
   73        * @serial Tracks the revision level of a class to identify changes to the
   74        * class definition that are compatible to serialization/externalization.
   75        * If a class definition changes, then the serialization/externalization
   76        * of the class is affected.
   77        * Refer to the writeExternal() and readExternal() methods.
   78        */
   79       // supported revision levels, add a new level to manage compatible changes
   80       private static final int REVISION_2 = 2;
   81       // current revision level of this object
   82       private static final int revisionID = REVISION_2;
   83   
   84   
   85       /**
   86        * Field parmeters
   87        */
   88       protected final HashMap<String, Parameter> parameters;
   89   
   90       /**
   91        * Constructor ParameterIncludeImpl.
   92        */
   93       public ParameterIncludeImpl() {
   94           parameters = new HashMap<String, Parameter>();
   95       }
   96   
   97       /**
   98        * Method addParameter
   99        *
  100        * @param param
  101        */
  102       public void addParameter(Parameter param) {
  103           if (param != null) {
  104               parameters.put(param.getName(), param);
  105               if (DEBUG_ENABLED) {
  106                   this.debugParameterAdd(param);
  107               }
  108           }
  109       }
  110   
  111       public void removeParameter(Parameter param) throws AxisFault {
  112           parameters.remove(param.getName());
  113       }
  114   
  115       /**
  116        * Since at runtime it parameters may be modified
  117        * to get the original state this method can be used
  118        *
  119        * @param parameters <code>OMElement</code>
  120        * @throws AxisFault
  121        */
  122       public void deserializeParameters(OMElement parameters) throws AxisFault {
  123           Iterator iterator =
  124                   parameters.getChildrenWithName(new QName(DeploymentConstants.TAG_PARAMETER));
  125   
  126           while (iterator.hasNext()) {
  127   
  128               // this is to check whether some one has locked the parmeter at the top level
  129               OMElement parameterElement = (OMElement) iterator.next();
  130               Parameter parameter = new Parameter();
  131   
  132               // setting parameterElement
  133               parameter.setParameterElement(parameterElement);
  134   
  135               // setting parameter Name
  136               OMAttribute paraName =
  137                       parameterElement.getAttribute(new QName(DeploymentConstants.ATTRIBUTE_NAME));
  138   
  139               parameter.setName(paraName.getAttributeValue());
  140   
  141               // setting parameter Value (the child element of the parameter)
  142               OMElement paraValue = parameterElement.getFirstElement();
  143   
  144               if (paraValue != null) {
  145                   parameter.setValue(parameterElement);
  146                   parameter.setParameterType(Parameter.OM_PARAMETER);
  147               } else {
  148                   String paratextValue = parameterElement.getText();
  149   
  150                   parameter.setValue(paratextValue);
  151                   parameter.setParameterType(Parameter.TEXT_PARAMETER);
  152               }
  153   
  154               // setting locking attribute
  155               OMAttribute paraLocked =
  156                       parameterElement.getAttribute(new QName(DeploymentConstants.ATTRIBUTE_LOCKED));
  157   
  158               if (paraLocked != null) {
  159                   String lockedValue = paraLocked.getAttributeValue();
  160   
  161                   if ("true".equals(lockedValue)) {
  162                       parameter.setLocked(true);
  163                   } else {
  164                       parameter.setLocked(false);
  165                   }
  166               }
  167   
  168               addParameter(parameter);
  169           }
  170       }
  171   
  172       /**
  173        * Method getParameter.
  174        *
  175        * @param name
  176        * @return Returns parameter.
  177        */
  178       public Parameter getParameter(String name) {
  179           return (Parameter) parameters.get(name);
  180       }
  181   
  182       public ArrayList<Parameter> getParameters() {
  183           Collection<Parameter> col = parameters.values();
  184           ArrayList<Parameter> para_list = new ArrayList<Parameter>();
  185   
  186           for (Iterator<Parameter> iterator = col.iterator(); iterator.hasNext();) {
  187               Parameter parameter = (Parameter) iterator.next();
  188   
  189               para_list.add(parameter);
  190           }
  191   
  192           return para_list;
  193       }
  194   
  195       // to check whether the parameter is locked at any level
  196       public boolean isParameterLocked(String parameterName) {
  197           return false;
  198       }
  199   
  200       /* ===============================================================
  201        * Externalizable support 
  202        * ===============================================================
  203        */
  204   
  205   
  206       /**
  207        * Save the contents of this object.
  208        * <p/>
  209        * NOTE: Transient fields and static fields are not saved.
  210        * Also, objects that represent "static" data are
  211        * not saved, except for enough information to be
  212        * able to find matching objects when the message
  213        * context is re-constituted.
  214        *
  215        * @param out The stream to write the object contents to
  216        * @throws IOException
  217        */
  218       public void writeExternal(ObjectOutput o) throws IOException {
  219           SafeObjectOutputStream out = SafeObjectOutputStream.install(o);
  220           // write out contents of this object
  221   
  222           //---------------------------------------------------------
  223           // in order to handle future changes to the message 
  224           // context definition, be sure to maintain the 
  225           // object level identifiers
  226           //---------------------------------------------------------
  227           // serialization version ID
  228           out.writeLong(serialVersionUID);
  229   
  230           // revision ID
  231           out.writeInt(revisionID);
  232   
  233           //---------------------------------------------------------
  234           // collection of parameters
  235           //---------------------------------------------------------
  236           out.writeMap(parameters);
  237   
  238       }
  239   
  240   
  241       /**
  242        * Restore the contents of the object that was previously saved.
  243        * <p/>
  244        * NOTE: The field data must read back in the same order and type
  245        * as it was written.  Some data will need to be validated when
  246        * resurrected.
  247        *
  248        * @param in The stream to read the object contents from
  249        * @throws IOException
  250        * @throws ClassNotFoundException
  251        */
  252       public void readExternal(ObjectInput inObject) throws IOException, ClassNotFoundException {
  253           SafeObjectInputStream in = SafeObjectInputStream.install(inObject);
  254           // trace point
  255           if (log.isTraceEnabled()) {
  256               log.trace(myClassName + ":readExternal():  BEGIN  bytes available in stream [" +
  257                       in.available() + "]  ");
  258           }
  259   
  260           // serialization version ID
  261           long suid = in.readLong();
  262   
  263           // revision ID
  264           int revID = in.readInt();
  265   
  266           // make sure the object data is in a version we can handle
  267           if (suid != serialVersionUID) {
  268               throw new ClassNotFoundException(ExternalizeConstants.UNSUPPORTED_SUID);
  269           }
  270   
  271           // make sure the object data is in a revision level we can handle
  272           if (revID != REVISION_2) {
  273               throw new ClassNotFoundException(ExternalizeConstants.UNSUPPORTED_REVID);
  274           }
  275   
  276           //---------------------------------------------------------
  277           // collection of parameters
  278           //---------------------------------------------------------
  279           in.readMap(parameters);
  280   
  281           //---------------------------------------------------------
  282           // done
  283           //---------------------------------------------------------
  284       }
  285   
  286       /**
  287        * Debug for for property key and value.
  288        * @param key
  289        * @param value
  290        */
  291       private void debugParameterAdd(Parameter parameter) {
  292           if (DEBUG_PROPERTY_SET) {
  293               String key = parameter.getName();
  294               Object value = parameter.getValue();
  295               String className = (value == null) ? "null" : value.getClass().getName();
  296               String classloader = "null";
  297               if(value != null) {
  298                   ClassLoader cl = Utils.getObjectClassLoader(value);
  299                   if(cl != null) {
  300                       classloader = cl.toString();
  301                   }
  302               }
  303               String valueText = (value instanceof String) ? value.toString() : null;
  304               String identity = getClass().getName() + '@' + 
  305                   Integer.toHexString(System.identityHashCode(this));
  306               
  307               log.debug("==================");
  308               log.debug(" Parameter add on object " + identity);
  309               log.debug("  Key =" + key);
  310               if (valueText != null) {
  311                   log.debug("  Value =" + valueText);
  312               }
  313               log.debug("  Value Class = " + className);
  314               log.debug("  Value Classloader = " + classloader);
  315               log.debug(  "Call Stack = " + JavaUtils.callStackToString());
  316               log.debug("==================");
  317           }
  318       }
  319   }

Save This Page
Home » axis2-1.5-src » org.apache » axis2 » description » [javadoc | source]