Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
//
// ========================================================================
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.plus.webapp;
import java.util.Iterator;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
import org.eclipse.jetty.jndi.NamingUtil;
import org.eclipse.jetty.plus.annotation.Injection;
import org.eclipse.jetty.plus.annotation.InjectionCollection;
import org.eclipse.jetty.plus.annotation.LifeCycleCallback;
import org.eclipse.jetty.plus.annotation.LifeCycleCallbackCollection;
import org.eclipse.jetty.plus.annotation.PostConstructCallback;
import org.eclipse.jetty.plus.annotation.PreDestroyCallback;
import org.eclipse.jetty.plus.annotation.RunAsCollection;
import org.eclipse.jetty.plus.jndi.EnvEntry;
import org.eclipse.jetty.plus.jndi.Link;
import org.eclipse.jetty.plus.jndi.NamingEntry;
import org.eclipse.jetty.plus.jndi.NamingEntryUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.webapp.Descriptor;
import org.eclipse.jetty.webapp.FragmentDescriptor;
import org.eclipse.jetty.webapp.IterativeDescriptorProcessor;
import org.eclipse.jetty.webapp.Origin;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.xml.XmlParser;
/**
* PlusDescriptorProcessor
*
*
*/
public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
{
private static final Logger LOG = Log.getLogger(PlusDescriptorProcessor.class);
public PlusDescriptorProcessor ()
{
try
{
registerVisitor("env-entry", getClass().getDeclaredMethod("visitEnvEntry", __signature));
registerVisitor("resource-ref", getClass().getDeclaredMethod("visitResourceRef", __signature));
registerVisitor("resource-env-ref", getClass().getDeclaredMethod("visitResourceEnvRef", __signature));
registerVisitor("message-destination-ref", getClass().getDeclaredMethod("visitMessageDestinationRef", __signature));
registerVisitor("post-construct", getClass().getDeclaredMethod("visitPostConstruct", __signature));
registerVisitor("pre-destroy", getClass().getDeclaredMethod("visitPreDestroy", __signature));
}
catch (Exception e)
{
throw new IllegalStateException(e);
}
}
/**
* @see org.eclipse.jetty.webapp.IterativeDescriptorProcessor#start(WebAppContext, org.eclipse.jetty.webapp.Descriptor)
*/
public void start(WebAppContext context, Descriptor descriptor)
{
InjectionCollection injections = (InjectionCollection)context.getAttribute(InjectionCollection.INJECTION_COLLECTION);
if (injections == null)
{
injections = new InjectionCollection();
context.setAttribute(InjectionCollection.INJECTION_COLLECTION, injections);
}
LifeCycleCallbackCollection callbacks = (LifeCycleCallbackCollection)context.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION);
if (callbacks == null)
{
callbacks = new LifeCycleCallbackCollection();
context.setAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION, callbacks);
}
RunAsCollection runAsCollection = (RunAsCollection)context.getAttribute(RunAsCollection.RUNAS_COLLECTION);
if (runAsCollection == null)
{
runAsCollection = new RunAsCollection();
context.setAttribute(RunAsCollection.RUNAS_COLLECTION, runAsCollection);
}
}
/**
* {@inheritDoc}
*/
public void end(WebAppContext context,Descriptor descriptor)
{
}
/**
* JavaEE 5.4.1.3
*
* @param node
* @throws Exception
*/
public void visitEnvEntry (WebAppContext context, Descriptor descriptor, XmlParser.Node node)
throws Exception
{
String name=node.getString("env-entry-name",false,true);
String type = node.getString("env-entry-type",false,true);
String valueStr = node.getString("env-entry-value",false,true);
//if there's no value there's no point in making a jndi entry
//nor processing injection entries
if (valueStr==null || valueStr.equals(""))
{
LOG.warn("No value for env-entry-name "+name);
return;
}
Origin o = context.getMetaData().getOrigin("env-entry."+name);
switch (o)
{
case NotSet:
{
//no descriptor has configured an env-entry of this name previously
context.getMetaData().setOrigin("env-entry."+name, descriptor);
//the javaee_5.xsd says that the env-entry-type is optional
//if there is an element, because you can get
//type from the element, but what to do if there is more
//than one element, do you just pick the type
//of the first one?
addInjections (context, descriptor, node, name, TypeUtil.fromName(type));
Object value = TypeUtil.valueOf(type,valueStr);
bindEnvEntry(name, value);
break;
}
case WebXml:
case WebDefaults:
case WebOverride:
{
//ServletSpec 3.0 p75. web.xml (or web-override/web-defaults) declared
//the env-entry. A fragment is not allowed to change that, except unless
//the web.xml did not declare any injections.
if (!(descriptor instanceof FragmentDescriptor))
{
//We're processing web-defaults, web.xml or web-override. Any of them can
//set or change the env-entry.
context.getMetaData().setOrigin("env-entry."+name, descriptor);
addInjections (context, descriptor, node, name, TypeUtil.fromName(type));
Object value = TypeUtil.valueOf(type,valueStr);
bindEnvEntry(name, value);
}
else
{
//A web.xml declared the env-entry. Check to see if any injections have been
//declared for it. If it was declared in web.xml then don't merge any injections.
//If it was declared in a web-fragment, then we can keep merging fragments.
Descriptor d = context.getMetaData().getOriginDescriptor("env-entry."+name+".injection");
if (d==null || d instanceof FragmentDescriptor)
addInjections(context, descriptor, node, name, TypeUtil.fromName(type));
}
break;
}
case WebFragment:
{
//ServletSpec p.75. No declaration in web.xml, but in multiple web-fragments. Error.
throw new IllegalStateException("Conflicting env-entry "+name+" in "+descriptor.getResource());
}
}
}
/**
* Common Annotations Spec section 2.3:
* resource-ref is for:
* - javax.sql.DataSource
* - javax.jms.ConnectionFactory
* - javax.jms.QueueConnectionFactory
* - javax.jms.TopicConnectionFactory
* - javax.mail.Session
* - java.net.URL
* - javax.resource.cci.ConnectionFactory
* - org.omg.CORBA_2_3.ORB
* - any other connection factory defined by a resource adapter
*
* TODO
* If web.xml contains a resource-ref with injection targets, all resource-ref entries
* of the same name are ignored in web fragments. If web.xml does not contain any
* injection-targets, then they are merged from all the fragments.
* If web.xml does not contain a resource-ref element of same name, but 2 fragments
* declare the same name it is an error.
* resource-ref entries are ONLY for connection factories
* the resource-ref says how the app will reference the jndi lookup relative
* to java:comp/env, but it is up to the deployer to map this reference to
* a real resource in the environment. At the moment, we insist that the
* jetty.xml file name of the resource has to be exactly the same as the
* name in web.xml deployment descriptor, but it shouldn't have to be
*
* Maintenance update 3.0a to spec:
* Update Section 8.2.3.h.ii with the following - If a resource reference
* element is specified in two fragments, while absent from the main web.xml,
* and all the attributes and child elements of the resource reference element
* are identical, the resource reference will be merged into the main web.xml.
* It is considered an error if a resource reference element has the same name
* specified in two fragments, while absent from the main web.xml and the attributes
* and child elements are not identical in the two fragments. For example, if two
* web fragments declare a with the same element
* but the type in one is specified as javax.sql.DataSource while the type in the
* other is that of a java mail resource, then an error must be reported and the
* application MUST fail to deploy.
*
* @param node
* @throws Exception
*/
public void visitResourceRef (WebAppContext context, Descriptor descriptor, XmlParser.Node node)
throws Exception
{
String jndiName = node.getString("res-ref-name",false,true);
String type = node.getString("res-type", false, true);
String auth = node.getString("res-auth", false, true);
String shared = node.getString("res-sharing-scope", false, true);
Origin o = context.getMetaData().getOrigin("resource-ref."+jndiName);
switch (o)
{
case NotSet:
{
//No descriptor or annotation previously declared a resource-ref of this name.
context.getMetaData().setOrigin("resource-ref."+jndiName, descriptor);
//check for elements
Class> typeClass = TypeUtil.fromName(type);
if (typeClass==null)
typeClass = context.loadClass(type);
addInjections(context, descriptor, node, jndiName, typeClass);
bindResourceRef(context,jndiName, typeClass);
break;
}
case WebXml:
case WebDefaults:
case WebOverride:
{
//A web xml previously declared the resource-ref.
if (!(descriptor instanceof FragmentDescriptor))
{
//We're processing web-defaults, web.xml or web-override. Any of them can
//set or change the resource-ref.
context.getMetaData().setOrigin("resource-ref."+jndiName, descriptor);
//check for elements
Class> typeClass = TypeUtil.fromName(type);
if (typeClass==null)
typeClass = context.loadClass(type);
addInjections(context, descriptor, node, jndiName, typeClass);
//bind the entry into jndi
bindResourceRef(context,jndiName, typeClass);
}
else
{
//A web xml declared the resource-ref and we're processing a
//web-fragment. Check to see if any injections were declared for it by web.xml.
//If any injection was declared in web.xml then don't merge any injections.
//If it was declared in a web-fragment, then we can keep merging fragments.
Descriptor d = context.getMetaData().getOriginDescriptor("resource-ref."+jndiName+".injection");
if (d==null || d instanceof FragmentDescriptor)
{
Class> typeClass = TypeUtil.fromName(type);
if (typeClass==null)
typeClass = context.loadClass(type);
addInjections(context, descriptor, node, jndiName, TypeUtil.fromName(type));
}
}
break;
}
case WebFragment:
{
Descriptor otherFragment = context.getMetaData().getOriginDescriptor("resource-ref."+jndiName);
XmlParser.Node otherFragmentRoot = otherFragment.getRoot();
Iterator