Package org.apache.muse.core.descriptor

Source Code of org.apache.muse.core.descriptor.CapabilityDefinition

/*
* 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.muse.core.descriptor;

import java.util.Collection;
import java.util.Map;

import org.apache.muse.core.Capability;
import org.apache.muse.core.Persistence;
import org.apache.muse.util.ReflectUtils;
import org.apache.muse.util.messages.Messages;
import org.apache.muse.util.messages.MessagesFactory;

/**
*
* @author Dan Jemiolo (danj)
*
*/

public class CapabilityDefinition
{
    //
    // Used to lookup all exception messages
    //
    private static Messages _MESSAGES =
        MessagesFactory.get(SimpleRouterDescriptor.class);
   
    private Collection _handlers = null;
   
    private Class _implementationClass = null;
   
    private Map _parameters = null;
   
    private PersistenceDefinition _persistence = null;
   
    private String _uri = null;
   
    public Class getImplementationClass()
    {
        return _implementationClass;
    }
   
    public Map getInitializationParameters()
    {
        return _parameters;
    }
   
    public Collection getMessageHandlers()
    {
        return _handlers;
    }
   
    public PersistenceDefinition getPersistenceDefinition()
    {
        return _persistence;
    }
   
    public String getURI()
    {
        return _uri;
    }
   
    public Capability newInstance()
    {
        Class theClass = getImplementationClass();
       
        Capability capability = (Capability)ReflectUtils.newInstance(theClass);
        capability.setCapabilityURI(getURI());
        capability.setMessageHandlers(getMessageHandlers());
        capability.setInitializationParameters(getInitializationParameters());
       
        PersistenceDefinition persistenceDef = getPersistenceDefinition();
       
        if (persistenceDef != null)
        {
            Persistence persistence = persistenceDef.newInstance();
            capability.setPersistence(persistence);
        }
       
        return capability;
    }
   
    public void setImplementationClass(Class implementationClass)
    {       
        //
        // make sure this class is an instance of Capability
        //
        if (!Capability.class.isAssignableFrom(implementationClass))
        {
            Object[] filler = { implementationClass.getName(), Capability.class.getName() };
            String message = _MESSAGES.get("IncorrectCapabilityRoot", filler);
            throw new RuntimeException(message);
        }
       
        _implementationClass = implementationClass;
    }
   
    public void setInitializationParameters(Map parameters)
    {
        _parameters = parameters;
    }
   
    public void setMessageHandlers(Collection handlers)
    {
        _handlers = handlers;
    }

    public void setPersistenceDefinition(PersistenceDefinition persistence)
    {
        _persistence = persistence;
    }

    public void setURI(String uri)
    {
        _uri = uri;
    }
}
TOP

Related Classes of org.apache.muse.core.descriptor.CapabilityDefinition

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.