servicegroupcontext.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 542 行 · 第 1/2 页
JAVA
542 行
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.axis2.context;
import org.apache.axiom.om.util.UUIDGenerator;
import org.apache.axis2.AxisFault;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.AxisServiceGroup;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.util.MetaDataEntry;
import org.apache.axis2.util.ObjectStateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class ServiceGroupContext extends AbstractContext implements Externalizable {
/*
* setup for logging
*/
private static final Log log = LogFactory.getLog(ServiceGroupContext.class);
private static final String myClassName = "ServiceGroupContext";
/**
* @serial The serialization version ID tracks the version of the class.
* If a class definition changes, then the serialization/externalization
* of the class is affected. If a change to the class is made which is
* not compatible with the serialization/externalization of the class,
* then the serialization version ID should be updated.
* Refer to the "serialVer" utility to compute a serialization
* version ID.
*/
private static final long serialVersionUID = 9014471144479928885L;
/**
* @serial Tracks the revision level of a class to identify changes to the
* class definition that are compatible to serialization/externalization.
* If a class definition changes, then the serialization/externalization
* of the class is affected.
* Refer to the writeExternal() and readExternal() methods.
*/
// supported revision levels, add a new level to manage compatible changes
private static final int REVISION_1 = 1;
// current revision level of this object
private static final int revisionID = REVISION_1;
private transient AxisServiceGroup axisServiceGroup;
private String id;
private Map serviceContextMap;
//----------------------------------------------------------------
// MetaData for data to be restored in activate after readExternal
//----------------------------------------------------------------
/**
* Indicates whether the message context has been reconstituted
* and needs to have its object references reconciled
*/
private transient boolean needsToBeReconciled = false;
/**
* The AxisServiceContext metadata will be used during
* activate to match up with an existing object
*/
private transient MetaDataEntry metaAxisServiceGroup = null;
//----------------------------------------------------------------
// end MetaData section
//----------------------------------------------------------------
// simple constructor
public ServiceGroupContext() {
super(null);
serviceContextMap = new HashMap();
}
public ServiceGroupContext(ConfigurationContext parent, AxisServiceGroup axisServiceGroup) {
super(parent);
this.axisServiceGroup = axisServiceGroup;
serviceContextMap = new HashMap();
// initially set the id to the axisServiceGroup
if (axisServiceGroup != null) {
setId(axisServiceGroup.getServiceGroupName());
}
}
public AxisServiceGroup getDescription() {
checkActivateWarning("getDescription");
return axisServiceGroup;
}
public String getId() {
return id;
}
/**
* Gets a service context. Creates a new one from AxisService.
* There is no need to store service context inside serviceGroup
* context as well.
*
* @param service the AxisService for which to get a context
* @return Returns ServiceContext.
* @throws AxisFault if something goes wrong
*/
public ServiceContext getServiceContext(AxisService service) throws AxisFault {
AxisService axisService = axisServiceGroup.getService(service.getName());
if (axisService == null) {
throw new AxisFault(Messages.getMessage("invalidserviceinagroup",
service.getName(),
axisServiceGroup.getServiceGroupName()));
}
if (serviceContextMap == null) {
serviceContextMap = new HashMap();
}
ServiceContext serviceContext = (ServiceContext) serviceContextMap.get(service.getName());
if (serviceContext == null) {
serviceContext = new ServiceContext(service, this);
getRootContext().contextCreated(serviceContext);
serviceContextMap.put(service.getName(), serviceContext);
}
return serviceContext;
}
public Iterator getServiceContexts() {
if (serviceContextMap == null) {
serviceContextMap = new HashMap();
}
if (serviceContextMap.isEmpty()) {
return null;
}
return serviceContextMap.values().iterator();
}
public void setId(String id) {
this.id = id;
}
/**
* Adds the specified service context object to the
* lists of service contexts for this service group
* context.
*
* @param srvctx The ServiceContext object to add
*/
public void addServiceContext(ServiceContext srvctx) {
if (srvctx == null) {
return;
}
AxisService axisService = srvctx.getAxisService();
if (axisService == null) {
return;
}
if (serviceContextMap == null) {
serviceContextMap = new HashMap();
}
serviceContextMap.put(axisService.getName(), srvctx);
}
/**
* Finds the service context object that corresponds
* to the specified name from the list
* of service contexts for this service group
* context.
*
* @param name The name associated with the ServiceContext
* @return The ServiceContext associated with the name,
* or null, if none can be found
*/
public ServiceContext findServiceContext(String name) {
if (serviceContextMap == null) {
return null;
}
return (ServiceContext) serviceContextMap.get(name);
}
/**
* Finds the service context object that corresponds
* to the specified AxisService from the list
* of service contexts for this service group
* context.
*
* @param axisSrv the AxisService whose context we're looking for
* @return The ServiceContext associated with the AxisService
* or null, if none can be found
*/
public ServiceContext findServiceContext(AxisService axisSrv) {
if (axisSrv == null) {
return null;
}
if (serviceContextMap == null) {
return null;
}
return (ServiceContext) serviceContextMap.get(axisSrv.getName());
}
/**
* This will do a copy of the properties from this context object
* to the properties of the specified context object.
*
* @param context The ServiceGroupContext object to hold the merged properties
*/
public void putContextProperties(ServiceGroupContext context) {
if (context != null) {
// get the current properties on this context object
Map props = getProperties();
// copy them to the specified context object
context.mergeProperties(props);
}
}
/* ===============================================================
* Externalizable support
* ===============================================================
*/
/**
* Save the contents of this object.
* <p/>
* NOTE: Transient fields and static fields are not saved.
* Also, objects that represent "static" data are
* not saved, except for enough information to be
* able to find matching objects when the message
* context is re-constituted.
*
* @param out The stream to write the object contents to
* @throws IOException
*/
public void writeExternal(ObjectOutput out) throws IOException {
// write out contents of this object
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?