[jboss-cvs] JBossAS SVN: r101200 - in projects/jboss-jca/trunk/deployers: src/main/java/org/jboss/jca/deployers/common and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Feb 20 04:41:46 EST 2010
Author: jeff.zhang
Date: 2010-02-20 04:41:46 -0500 (Sat, 20 Feb 2010)
New Revision: 101200
Added:
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/Annotations.java
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/Metadata.java
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/SecurityActions.java
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/ValidateException.java
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/package.html
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/Main.java
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/SecurityActions.java
projects/jboss-jca/trunk/deployers/src/main/resources/validator-manifest.mf
projects/jboss-jca/trunk/deployers/src/main/resources/validator.sh
Removed:
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Annotations.java
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Metadata.java
Modified:
projects/jboss-jca/trunk/deployers/build.xml
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/Validator.java
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java
projects/jboss-jca/trunk/deployers/src/main/resources/validator.properties
projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java
Log:
[JBJCA-272] Standalone tool - Validator
Modified: projects/jboss-jca/trunk/deployers/build.xml
===================================================================
--- projects/jboss-jca/trunk/deployers/build.xml 2010-02-20 06:08:46 UTC (rev 101199)
+++ projects/jboss-jca/trunk/deployers/build.xml 2010-02-20 09:41:46 UTC (rev 101200)
@@ -101,6 +101,22 @@
manifest="src/main/resources/fungal-ra-manifest.mf"
basedir="${build.deployers.dir}/jars/fungal"/>
+ <!-- Validator -->
+ <mkdir dir="${build.deployers.dir}/jars/validator" />
+
+ <copy todir="${build.deployers.dir}/jars/validator">
+ <fileset dir="${build.deployers.dir}/impl"
+ includes="**/common/**"/>
+ </copy>
+
+ <copy todir="${build.deployers.dir}/jars/validator">
+ <fileset dir="src/main/resources/"
+ includes="**/*.properties"/>
+ </copy>
+
+ <jar destfile="${target.dir}/jboss-jca-validator.jar"
+ manifest="src/main/resources/validator-manifest.mf"
+ basedir="${build.deployers.dir}/jars/validator"/>
</target>
Copied: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/Annotations.java (from rev 101199, projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Annotations.java)
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/Annotations.java (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/Annotations.java 2010-02-20 09:41:46 UTC (rev 101200)
@@ -0,0 +1,1121 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.deployers.common;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.resource.spi.Activation;
+import javax.resource.spi.AdministeredObject;
+import javax.resource.spi.AuthenticationMechanism;
+import javax.resource.spi.AuthenticationMechanism.CredentialInterface;
+import javax.resource.spi.ConfigProperty;
+import javax.resource.spi.ConnectionDefinition;
+import javax.resource.spi.ConnectionDefinitions;
+import javax.resource.spi.Connector;
+import javax.resource.spi.SecurityPermission;
+import javax.resource.spi.TransactionSupport;
+import javax.resource.spi.TransactionSupport.TransactionSupportLevel;
+import javax.resource.spi.work.WorkContext;
+
+import org.jboss.logging.Logger;
+
+import org.jboss.metadata.javaee.spec.DescriptionGroupMetaData;
+import org.jboss.metadata.javaee.spec.DescriptionImpl;
+import org.jboss.metadata.javaee.spec.DescriptionsImpl;
+import org.jboss.metadata.javaee.spec.DisplayNameImpl;
+import org.jboss.metadata.javaee.spec.DisplayNamesImpl;
+import org.jboss.metadata.javaee.spec.IconImpl;
+import org.jboss.metadata.javaee.spec.IconsImpl;
+
+import org.jboss.metadata.rar.spec.ActivationspecMetaData;
+import org.jboss.metadata.rar.spec.AdminObjectMetaData;
+import org.jboss.metadata.rar.spec.AuthenticationMechanismMetaData;
+import org.jboss.metadata.rar.spec.ConfigPropertyMetaData;
+import org.jboss.metadata.rar.spec.ConnectionDefinitionMetaData;
+import org.jboss.metadata.rar.spec.ConnectorMetaData;
+import org.jboss.metadata.rar.spec.InboundRaMetaData;
+import org.jboss.metadata.rar.spec.JCA16Base;
+import org.jboss.metadata.rar.spec.JCA16MetaData;
+import org.jboss.metadata.rar.spec.LicenseMetaData;
+import org.jboss.metadata.rar.spec.MessageAdapterMetaData;
+import org.jboss.metadata.rar.spec.MessageListenerMetaData;
+import org.jboss.metadata.rar.spec.OutboundRaMetaData;
+import org.jboss.metadata.rar.spec.ResourceAdapterMetaData;
+import org.jboss.metadata.rar.spec.SecurityPermissionMetaData;
+import org.jboss.metadata.rar.spec.TransactionSupportMetaData;
+
+import org.jboss.papaki.Annotation;
+import org.jboss.papaki.AnnotationRepository;
+import org.jboss.papaki.AnnotationScanner;
+import org.jboss.papaki.AnnotationScannerFactory;
+import org.jboss.papaki.AnnotationType;
+
+/**
+ * The annotation processor for JCA 1.6
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Annotations
+{
+ private static Logger log = Logger.getLogger(Annotations.class);
+ private static boolean trace = log.isTraceEnabled();
+
+ /**
+ * Constructor
+ */
+ public Annotations()
+ {
+ }
+
+ /**
+ * Scan for annotations in the URLs specified
+ * @param cmd The resource adapter metadata
+ * @param urls The URLs to be scanned
+ * @param cl The referenced classloader
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ public ConnectorMetaData scan(ConnectorMetaData cmd, URL[] urls, ClassLoader cl) throws Exception
+ {
+ // Process annotations
+ if (cmd == null || cmd.is16())
+ {
+ AnnotationScanner annotationScanner =
+ AnnotationScannerFactory.getStrategy(AnnotationScannerFactory.JAVASSIST_INPUT_STREAM);
+ annotationScanner.configure().constructorLevel(false).parameterLevel(false);
+ AnnotationRepository annotationRepository = annotationScanner.scan(urls, cl);
+
+ boolean isMetadataComplete = false;
+ if (cmd != null && cmd instanceof JCA16Base)
+ {
+ JCA16Base jmd = (JCA16Base)cmd;
+ isMetadataComplete = jmd.isMetadataComplete();
+ }
+
+ if (cmd == null || !isMetadataComplete)
+ {
+ cmd = process(cmd, annotationRepository);
+ }
+ }
+ return cmd;
+ }
+ /**
+ * Process annotations
+ * @param md The metadata
+ * @param annotationRepository The annotation repository
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ public ConnectorMetaData process(ConnectorMetaData md, AnnotationRepository annotationRepository)
+ throws Exception
+ {
+ if (annotationRepository == null)
+ throw new ValidateException("AnnotationRepository reference is null");
+ /* Process
+ -------
+ javax.resource.spi.Activation
+ javax.resource.spi.AdministeredObject
+ javax.resource.spi.AuthenticationMechanism
+ javax.resource.spi.ConfigProperty
+ javax.resource.spi.ConnectionDefinition
+ javax.resource.spi.ConnectionDefinitions
+ javax.resource.spi.Connector
+ javax.resource.spi.SecurityPermission
+ */
+
+ if (md == null)
+ {
+ JCA16MetaData jmd = new JCA16MetaData();
+ jmd.setMetadataComplete(false);
+ md = jmd;
+ }
+
+ // @Connector
+ md = processConnector(md, annotationRepository);
+
+ // @ConnectionDefinitions
+ md = processConnectionDefinitions(md, annotationRepository);
+
+ // @ConnectionDefinition (outside of @ConnectionDefinitions)
+ md = processConnectionDefinition(md, annotationRepository);
+
+ // @Activation
+ md = processActivation(md, annotationRepository);
+
+ // @AuthenticationMechanism
+ //md = processAuthenticationMechanism(md, annotationRepository);
+
+ // @AdministeredObject
+ md = processAdministeredObject(md, annotationRepository);
+
+ // @ConfigProperty handle at last
+ md = processConfigProperty(md, annotationRepository);
+
+ //log.debug("ConnectorMetadata " + md);
+
+ return md;
+ }
+
+ /**
+ * Process: @Connector
+ * @param md The metadata
+ * @param annotationRepository The annotation repository
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData processConnector(ConnectorMetaData md, AnnotationRepository annotationRepository)
+ throws Exception
+ {
+ Collection<Annotation> values = annotationRepository.getAnnotation(Connector.class);
+ if (values != null)
+ {
+ if (values.size() == 1)
+ {
+ Annotation annotation = values.iterator().next();
+ String raClass = annotation.getClassName();
+ Connector c = (Connector)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + c + " for " + raClass);
+
+ md = attachConnector(md, raClass, c);
+ }
+ else if (values.size() == 0)
+ {
+ // JBJCA-240
+ if (md.getRa().getRaClass() == null || md.getRa().getRaClass().equals(""))
+ {
+ log.fatal("No @Connector was found and no definition in the ra.xml metadata either");
+ throw new ValidateException("No @Connector defined");
+ }
+ }
+ else
+ {
+ // JBJCA-240
+ if (md.getRa().getRaClass() == null || md.getRa().getRaClass().equals(""))
+ {
+ log.fatal("More than one @Connector was found but the correct one " +
+ "wasn't defined in the ra.xml metadata");
+ throw new ValidateException("More than one @Connector defined");
+ }
+ }
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @Connector
+ * @param md The metadata
+ * @param raClass The class name for the resource adapter
+ * @param c The connector
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData attachConnector(ConnectorMetaData md, String raClass, Connector c)
+ throws Exception
+ {
+ // Class definition
+ if (md.getRa() == null)
+ md.setRa(new ResourceAdapterMetaData());
+
+ md.getRa().setRaClass(raClass);
+
+ // AuthenticationMechanism
+ AuthenticationMechanism[] authMechanisms = c.authMechanisms();
+ if (authMechanisms != null)
+ {
+ for (AuthenticationMechanism authMechanism : authMechanisms)
+ {
+ attachAuthenticationMechanism(md, authMechanism);
+ }
+ }
+
+ DescriptionGroupMetaData descGroup = new DescriptionGroupMetaData();
+ md.setDescriptionGroup(descGroup);
+
+ // Description
+ String[] description = c.description();
+ if (description != null)
+ {
+ if (descGroup.getDescriptions() == null)
+ {
+ DescriptionsImpl descsImpl = new DescriptionsImpl();
+ descGroup.setDescriptions(descsImpl);
+ }
+ for (String desc : description)
+ {
+ DescriptionImpl descImpl = new DescriptionImpl();
+ descImpl.setDescription(desc);
+ ((DescriptionsImpl)descGroup.getDescriptions()).add(descImpl);
+ }
+ }
+
+ // Display name
+ String[] displayName = c.displayName();
+ if (displayName != null)
+ {
+ if (descGroup.getDisplayNames() == null)
+ {
+ DisplayNamesImpl dnsImpl = new DisplayNamesImpl();
+ descGroup.setDisplayNames(dnsImpl);
+ }
+ for (String dn : displayName)
+ {
+ DisplayNameImpl dnImpl = new DisplayNameImpl();
+ dnImpl.setDisplayName(dn);
+ ((DisplayNamesImpl)descGroup.getDisplayNames()).add(dnImpl);
+ }
+ }
+
+ // EIS type
+ String eisType = c.eisType();
+ if (eisType != null)
+ {
+ if (md.getEISType() == null)
+ md.setEISType(eisType);
+ }
+
+ // Large icon
+ String[] largeIcon = c.largeIcon();
+ if (largeIcon != null)
+ {
+ if (descGroup.getIcons() == null)
+ {
+ IconsImpl icsImpl = new IconsImpl();
+ descGroup.setIcons(icsImpl);
+ }
+ for (String large : largeIcon)
+ {
+ IconImpl icImpl = new IconImpl();
+ icImpl.setLargeIcon(large);
+ ((IconsImpl)descGroup.getIcons()).add(icImpl);
+ }
+ }
+
+ // License description
+ String[] licenseDescription = c.licenseDescription();
+ if (licenseDescription != null)
+ {
+ if (md.getLicense() == null)
+ md.setLicense(new LicenseMetaData());
+
+ if (md.getLicense().getDescriptions() == null)
+ {
+ DescriptionsImpl descsImpl = new DescriptionsImpl();
+ md.getLicense().setDescriptions(descsImpl);
+ }
+ for (String desc : licenseDescription)
+ {
+ DescriptionImpl descImpl = new DescriptionImpl();
+ descImpl.setDescription(desc);
+ ((DescriptionsImpl)md.getLicense().getDescriptions()).add(descImpl);
+ }
+ }
+
+ // License required
+ boolean licenseRequired = c.licenseRequired();
+ if (md.getLicense() == null)
+ md.setLicense(new LicenseMetaData());
+ md.getLicense().setRequired(licenseRequired);
+
+ // Reauthentication support
+ boolean reauthenticationSupport = c.reauthenticationSupport();
+ if (md.getRa() != null && md.getRa().getOutboundRa() != null)
+ {
+ md.getRa().getOutboundRa().setReAuthSupport(reauthenticationSupport);
+ }
+
+ // RequiredWorkContext
+ Class<? extends WorkContext>[] requiredWorkContexts = c.requiredWorkContexts();
+ if (requiredWorkContexts != null)
+ {
+ for (Class<? extends WorkContext> requiredWorkContext : requiredWorkContexts)
+ {
+ if (md instanceof JCA16Base)
+ {
+ JCA16Base jmd = (JCA16Base)md;
+ if (jmd.getRequiredWorkContexts() == null)
+ jmd.setRequiredWorkContexts(new ArrayList<String>());
+
+ if (!jmd.getRequiredWorkContexts().contains(requiredWorkContext.getName()))
+ {
+ if (trace)
+ log.trace("RequiredWorkContext=" + requiredWorkContext.getName());
+
+ jmd.getRequiredWorkContexts().add(requiredWorkContext.getName());
+ }
+ }
+ }
+ }
+
+ // Security permission
+ SecurityPermission[] securityPermissions = c.securityPermissions();
+ if (securityPermissions != null)
+ {
+ if (md.getRa() == null)
+ md.setRa(new ResourceAdapterMetaData());
+
+ if (md.getRa().getSecurityPermissions() == null)
+ md.getRa().setSecurityPermissions(new ArrayList<SecurityPermissionMetaData>());
+
+ for (SecurityPermission securityPermission : securityPermissions)
+ {
+ SecurityPermissionMetaData spmd = new SecurityPermissionMetaData();
+ spmd.setSecurityPermissionSpec(securityPermission.permissionSpec());
+ md.getRa().getSecurityPermissions().add(spmd);
+ }
+ }
+
+ // Small icon
+ String[] smallIcon = c.smallIcon();
+ if (smallIcon != null)
+ {
+ IconsImpl icsImpl;
+ if (descGroup.getIcons() == null)
+ {
+ icsImpl = new IconsImpl();
+ descGroup.setIcons(icsImpl);
+ }
+ else
+ {
+ icsImpl = (IconsImpl)descGroup.getIcons();
+ }
+ IconImpl[] icArray = icsImpl.toArray(new IconImpl[icsImpl.size()]);
+ for (int i = 0; i < smallIcon.length; i++)
+ {
+ if (i < icArray.length)
+ icArray[i].setSmallIcon(smallIcon[i]);
+ else
+ {
+ IconImpl icImpl = new IconImpl();
+ icImpl.setLargeIcon(smallIcon[i]);
+ icsImpl.add(icImpl);
+ }
+ }
+ }
+
+ // Transaction support
+ TransactionSupport.TransactionSupportLevel transactionSupport = c.transactionSupport();
+ if (md.getRa() != null && md.getRa().getOutboundRa() != null)
+ {
+ if (transactionSupport.equals(TransactionSupportLevel.NoTransaction))
+ {
+ md.getRa().getOutboundRa().setTransSupport(TransactionSupportMetaData.NoTransaction);
+ }
+ else if (transactionSupport.equals(TransactionSupportLevel.XATransaction))
+ {
+ md.getRa().getOutboundRa().setTransSupport(TransactionSupportMetaData.XATransaction);
+ }
+ else if (transactionSupport.equals(TransactionSupportLevel.LocalTransaction))
+ {
+ md.getRa().getOutboundRa().setTransSupport(TransactionSupportMetaData.LocalTransaction);
+ }
+ }
+
+ // Vendor name
+ String vendorName = c.vendorName();
+ if (vendorName != null)
+ {
+ if (md.getVendorName() == null)
+ md.setVendorName(vendorName);
+ }
+
+ // Version
+ String version = c.version();
+ if (version != null)
+ {
+ if (md.getRAVersion() == null)
+ md.setRAVersion(version);
+ }
+
+ return md;
+ }
+
+ /**
+ * Process: @ConnectionDefinitions
+ * @param md The metadata
+ * @param annotationRepository The annotation repository
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData processConnectionDefinitions(ConnectorMetaData md,
+ AnnotationRepository annotationRepository)
+ throws Exception
+ {
+ Collection<Annotation> values = annotationRepository.getAnnotation(ConnectionDefinitions.class);
+ if (values != null)
+ {
+ if (values.size() == 1)
+ {
+ Annotation annotation = values.iterator().next();
+ ConnectionDefinitions c = (ConnectionDefinitions)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + c);
+
+ md = attachConnectionDefinitions(md , c, annotation.getClassName());
+ }
+ else
+ throw new ValidateException("More than one @ConnectionDefinitions defined");
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @ConnectionDefinitions
+ * @param md The metadata
+ * @param cds The connection definitions
+ * @param mcf The managed connection factory
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData attachConnectionDefinitions(ConnectorMetaData md,
+ ConnectionDefinitions cds,
+ String mcf)
+ throws Exception
+ {
+ createConDefs(md);
+
+ if (cds.value() != null)
+ {
+ for (ConnectionDefinition cd : cds.value())
+ {
+ md = attachConnectionDefinition(md, mcf, cd);
+ }
+ }
+
+ return md;
+ }
+
+ /**
+ * Process: @ConnectionDefinition
+ * @param md The metadata
+ * @param annotationRepository The annotation repository
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData processConnectionDefinition(ConnectorMetaData md,
+ AnnotationRepository annotationRepository)
+ throws Exception
+ {
+ Collection<Annotation> values = annotationRepository.getAnnotation(ConnectionDefinition.class);
+ if (values != null)
+ {
+ for (Annotation annotation : values)
+ {
+ md = attachConnectionDefinition(md, annotation);
+ }
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @ConnectionDefinition
+ * @param md The metadata
+ * @param cd The connection definition
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData attachConnectionDefinition(ConnectorMetaData md, Annotation annotation)
+ throws Exception
+ {
+ ConnectionDefinition cd = (ConnectionDefinition)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + annotation);
+
+ createConDefs(md);
+
+ for (ConnectionDefinitionMetaData cdMeta : md.getRa().getOutboundRa().getConDefs())
+ {
+ if (cdMeta.getManagedConnectionFactoryClass().equals(annotation.getClassName()))
+ {
+ //ra.xml define
+ return md;
+ }
+ }
+
+ return attachConnectionDefinition(md, annotation.getClassName(), cd);
+ }
+
+ /**
+ * Attach @ConnectionDefinition
+ * @param md The metadata
+ * @param mcf The managed connection factory
+ * @param cd The connection definition
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData attachConnectionDefinition(ConnectorMetaData md,
+ String mcf,
+ ConnectionDefinition cd)
+ throws Exception
+ {
+ if (trace)
+ log.trace("Processing: " + cd);
+
+ createConDefs(md);
+
+ ConnectionDefinitionMetaData cdMeta = new ConnectionDefinitionMetaData();
+ cdMeta.setManagedConnectionFactoryClass(mcf);
+ cdMeta.setConnectionFactoryInterfaceClass(cd.connectionFactory().getName());
+ cdMeta.setConnectionFactoryImplementationClass(cd.connectionFactoryImpl().getName());
+ cdMeta.setConnectionInterfaceClass(cd.connection().getName());
+ cdMeta.setConnectionImplementationClass(cd.connectionImpl().getName());
+ md.getRa().getOutboundRa().getConDefs().add(cdMeta);
+ return md;
+ }
+
+ /**
+ * Process: @ConfigProperty
+ * @param md The metadata
+ * @param annotationRepository The annotation repository
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData processConfigProperty(ConnectorMetaData md,
+ AnnotationRepository annotationRepository)
+ throws Exception
+ {
+ Collection<Annotation> values = annotationRepository.getAnnotation(ConfigProperty.class);
+ if (values != null)
+ {
+ for (Annotation annotation : values)
+ {
+ md = attachConfigProperty(md, annotation);
+ }
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @ConfigProperty
+ * @param md The metadata
+ * @param configProperty The config property
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData attachConfigProperty(ConnectorMetaData md, Annotation annotation)
+ throws Exception
+ {
+ ConfigProperty configProperty = (ConfigProperty)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + configProperty);
+
+ // Ignore config-property which has ignore=true
+ if (configProperty.ignore())
+ return md;
+
+ ConfigPropertyMetaData cfgMeta = new ConfigPropertyMetaData();
+ cfgMeta.setName(getConfigPropertyName(annotation));
+ cfgMeta.setValue(configProperty.defaultValue());
+ if (!Object.class.equals(configProperty.type()))
+ {
+ cfgMeta.setType(configProperty.type().getName());
+ }
+ else
+ {
+ cfgMeta.setType(getConfigPropertyType(annotation));
+ }
+ cfgMeta.setIgnore(configProperty.ignore());
+
+ String[] description = configProperty.description();
+ if (description != null)
+ {
+ if (cfgMeta.getDescriptions() == null)
+ {
+ DescriptionsImpl descsImpl = new DescriptionsImpl();
+ cfgMeta.setDescriptions(descsImpl);
+ }
+ for (String desc : description)
+ {
+ DescriptionImpl descImpl = new DescriptionImpl();
+ descImpl.setDescription(desc);
+ ((DescriptionsImpl)cfgMeta.getDescriptions()).add(descImpl);
+ }
+ }
+
+ String attachedClassName = annotation.getClassName();
+ ClassLoader cl = SecurityActions.getThreadContextClassLoader();
+ Class attachedClass = Class.forName(attachedClassName, true, cl);
+
+ if (hasInterface(attachedClass, "javax.resource.spi.ResourceAdapter"))
+ {
+ if (md.getRa() == null)
+ {
+ md.setRa(new ResourceAdapterMetaData());
+ }
+ if (md.getRa().getConfigProperty() == null)
+ {
+ md.getRa().setConfigProperty(new ArrayList<ConfigPropertyMetaData>());
+ }
+ for (ConfigPropertyMetaData cpMeta : md.getRa().getConfigProperty())
+ {
+ if (cpMeta.getName().equals(cfgMeta.getName()))
+ {
+ return md;
+ }
+ }
+ md.getRa().getConfigProperty().add(cfgMeta);
+ }
+ else if (hasInterface(attachedClass, "javax.resource.spi.ManagedConnectionFactory"))
+ {
+ createConDefs(md);
+ for (ConnectionDefinitionMetaData cdMeta : md.getRa().getOutboundRa().getConDefs())
+ {
+ if (attachedClassName.equals(cdMeta.getManagedConnectionFactoryClass()))
+ {
+ if (cdMeta.getConfigProps() == null)
+ {
+ cdMeta.setConfigProps(new ArrayList<ConfigPropertyMetaData>());
+ }
+ for (ConfigPropertyMetaData cpMeta : cdMeta.getConfigProps())
+ {
+ if (cpMeta.getName().equals(cfgMeta.getName()))
+ {
+ return md;
+ }
+ }
+ cdMeta.getConfigProps().add(cfgMeta);
+ }
+ }
+ }
+ else if (hasInterface(attachedClass, "javax.resource.spi.ActivationSpec"))
+ {
+ createMessageListeners(md);
+ for (MessageListenerMetaData mlMeta : md.getRa().getInboundRa().getMessageAdapter().getMessageListeners())
+ {
+ if (attachedClassName.equals(mlMeta.getActivationSpecType().getAsClass()))
+ {
+ if (mlMeta.getActivationSpecType().getConfigProps() == null)
+ {
+ mlMeta.getActivationSpecType().setConfigProps(new ArrayList<ConfigPropertyMetaData>());
+ }
+ for (ConfigPropertyMetaData cpMeta : mlMeta.getActivationSpecType().getConfigProps())
+ {
+ if (cpMeta.getName().equals(cfgMeta.getName()))
+ {
+ return md;
+ }
+ }
+ mlMeta.getActivationSpecType().getConfigProps().add(cfgMeta);
+ }
+ }
+ }
+
+ return md;
+ }
+
+ /**
+ * hasInterface
+ *
+ * @param c
+ * @param targetClassName
+ * @return
+ */
+ private boolean hasInterface(Class c, String targetClassName)
+ {
+ for (Class face : c.getInterfaces())
+ {
+ if (face.getName().equals(targetClassName))
+ {
+ return true;
+ }
+ else
+ {
+ for (Class face2 : face.getInterfaces())
+ {
+ if (face2.getName().equals(targetClassName))
+ {
+ return true;
+ }
+ else if (hasInterface(face2, targetClassName))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ if (null != c.getSuperclass())
+ {
+ return hasInterface(c.getSuperclass(), targetClassName);
+ }
+ return false;
+ }
+
+ /**
+ * Attach @AuthenticationMechanism
+ * @param md The metadata
+ * @param authenticationmechanism The authentication mechanism
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData attachAuthenticationMechanism(ConnectorMetaData md,
+ AuthenticationMechanism authenticationmechanism)
+ throws Exception
+ {
+ if (md.getRa() == null)
+ {
+ md.setRa(new ResourceAdapterMetaData());
+ }
+ if (md.getRa().getOutboundRa() == null)
+ {
+ md.getRa().setOutboundRa(new OutboundRaMetaData());
+ }
+ if (md.getRa().getOutboundRa().getAuthMechanisms() == null)
+ {
+ md.getRa().getOutboundRa().setAuthMechanisms(new ArrayList<AuthenticationMechanismMetaData>());
+ }
+ AuthenticationMechanismMetaData ammd = new AuthenticationMechanismMetaData();
+ ammd.setAuthenticationMechanismType(authenticationmechanism.authMechanism());
+
+ String credentialInterfaceClass = null;
+ if (authenticationmechanism.credentialInterface().equals(CredentialInterface.GenericCredential))
+ {
+ credentialInterfaceClass = "javax.resource.spi.security.GenericCredential";
+ }
+ else if (authenticationmechanism.credentialInterface().equals(CredentialInterface.GSSCredential))
+ {
+ credentialInterfaceClass = "org.ietf.jgss.GSSCredential";
+ }
+ else if (authenticationmechanism.credentialInterface().equals(CredentialInterface.PasswordCredential))
+ {
+ credentialInterfaceClass = "javax.resource.spi.security.PasswordCredential";
+ }
+ ammd.setCredentialInterfaceClass(credentialInterfaceClass);
+
+ String[] description = authenticationmechanism.description();
+ if (description != null)
+ {
+ if (ammd.getDescriptions() == null)
+ {
+ DescriptionsImpl descsImpl = new DescriptionsImpl();
+ ammd.setDescriptions(descsImpl);
+ }
+ for (String desc : description)
+ {
+ DescriptionImpl descImpl = new DescriptionImpl();
+ descImpl.setDescription(desc);
+ ((DescriptionsImpl)ammd.getDescriptions()).add(descImpl);
+ }
+ }
+
+ md.getRa().getOutboundRa().getAuthMechanisms().add(ammd);
+
+ return md;
+ }
+
+ /**
+ * Process: @AdministeredObject
+ * @param md The metadata
+ * @param annotationRepository The annotation repository
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData processAdministeredObject(ConnectorMetaData md,
+ AnnotationRepository annotationRepository)
+ throws Exception
+ {
+ Collection<Annotation> values = annotationRepository.getAnnotation(AdministeredObject.class);
+ if (values != null)
+ {
+ for (Annotation annotation : values)
+ {
+ AdministeredObject a = (AdministeredObject)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + a);
+
+ md = attachAdministeredObject(md, a);
+ }
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @AdministeredObject
+ * @param md The metadata
+ * @param a The administered object
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData attachAdministeredObject(ConnectorMetaData md, AdministeredObject a)
+ throws Exception
+ {
+ createAdminObject(md);
+ String aoName = null;
+ if (a.adminObjectInterfaces().length > 0)
+ {
+ aoName = ((Class)Array.get(a.adminObjectInterfaces(), 0)).getName();
+ }
+ AdminObjectMetaData aomd = new AdminObjectMetaData();
+ aomd.setAdminObjectInterfaceClass(aoName);
+ md.getRa().getAdminObjects().add(aomd);
+ return md;
+ }
+
+ /**
+ * Process: @Activation
+ * @param md The metadata
+ * @param annotationRepository The annotation repository
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData processActivation(ConnectorMetaData md,
+ AnnotationRepository annotationRepository)
+ throws Exception
+ {
+ Collection<Annotation> values = annotationRepository.getAnnotation(Activation.class);
+ if (values != null)
+ {
+ for (Annotation annotation : values)
+ {
+ md = attachActivation(md, annotation);
+ }
+ }
+
+ return md;
+ }
+
+ /**
+ * Attach @Activation
+ * @param md The metadata
+ * @param activation The activation
+ * @return The updated metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ private ConnectorMetaData attachActivation(ConnectorMetaData md, Annotation annotation)
+ throws Exception
+ {
+ Activation activation = (Activation)annotation.getAnnotation();
+
+ if (trace)
+ log.trace("Processing: " + activation);
+
+ createMessageListeners(md);
+ for (Class asClass : activation.messageListeners())
+ {
+ ActivationspecMetaData asMeta = new ActivationspecMetaData();
+ asMeta.setAsClass(annotation.getClassName());
+ MessageListenerMetaData mlMeta = new MessageListenerMetaData();
+ mlMeta.setActivationSpecType(asMeta);
+ mlMeta.setType(asClass.getName());
+ md.getRa().getInboundRa().getMessageAdapter().getMessageListeners().add(mlMeta);
+ }
+ return md;
+ }
+
+
+ /**
+ * createMessageListeners
+ * @param md
+ * @throws Exception
+ */
+ private void createMessageListeners(ConnectorMetaData md) throws Exception
+ {
+ if (md.getRa() == null)
+ {
+ md.setRa(new ResourceAdapterMetaData());
+ }
+ if (md.getRa().getInboundRa() == null)
+ {
+ md.getRa().setInboundRa(new InboundRaMetaData());
+ }
+ if (md.getRa().getInboundRa().getMessageAdapter() == null)
+ {
+ md.getRa().getInboundRa().setMessageAdapter(new MessageAdapterMetaData());
+ }
+ if (md.getRa().getInboundRa().getMessageAdapter().getMessageListeners() == null)
+ {
+ md.getRa().getInboundRa().getMessageAdapter().setMessageListeners(new ArrayList<MessageListenerMetaData>());
+ }
+ }
+
+ /**
+ * createAdminObject
+ * @param md
+ * @throws Exception
+ */
+ private void createAdminObject(ConnectorMetaData md) throws Exception
+ {
+ if (md.getRa() == null)
+ {
+ md.setRa(new ResourceAdapterMetaData());
+ }
+ if (md.getRa().getAdminObjects() == null)
+ {
+ md.getRa().setAdminObjects(new ArrayList<AdminObjectMetaData>());
+ }
+ }
+
+ /**
+ * createConDefs
+ * @param md
+ * @throws Exception
+ */
+ private void createConDefs(ConnectorMetaData md) throws Exception
+ {
+ if (md.getRa() == null)
+ {
+ md.setRa(new ResourceAdapterMetaData());
+ }
+ if (md.getRa().getOutboundRa() == null)
+ {
+ md.getRa().setOutboundRa(new OutboundRaMetaData());
+ }
+ if (md.getRa().getOutboundRa().getConDefs() == null)
+ {
+ md.getRa().getOutboundRa().setConDefs(new ArrayList<ConnectionDefinitionMetaData>());
+ }
+ }
+
+ /**
+ * Get the config-property-name for an annotation
+ * @param annotation The annotation
+ * @return The name
+ * @exception ClassNotFoundException Thrown if a class cannot be found
+ * @exception NoSuchFieldException Thrown if a field cannot be found
+ * @exception NoSuchMethodException Thrown if a method cannot be found
+ */
+ private String getConfigPropertyName(Annotation annotation)
+ throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException
+ {
+ if (AnnotationType.FIELD.equals(annotation.getType()))
+ {
+ return annotation.getMemberName();
+ }
+ else if (AnnotationType.METHOD.equals(annotation.getType()))
+ {
+ String name = annotation.getMemberName();
+
+ if (name.startsWith("set"))
+ {
+ name = name.substring(3);
+ }
+ else if (name.startsWith("get"))
+ {
+ name = name.substring(3);
+ }
+ else if (name.startsWith("is"))
+ {
+ name = name.substring(2);
+ }
+
+ if (name.length() > 1)
+ {
+ return Character.toLowerCase(name.charAt(0)) + name.substring(1);
+ }
+ else
+ {
+ return Character.toString(Character.toLowerCase(name.charAt(0)));
+ }
+ }
+
+ throw new IllegalArgumentException("Unknown annotation: " + annotation);
+ }
+
+ /**
+ * Get the config-property-type for an annotation
+ * @param annotation The annotation
+ * @return The fully qualified classname
+ * @exception ClassNotFoundException Thrown if a class cannot be found
+ */
+ @SuppressWarnings("unchecked")
+ private String getConfigPropertyType(Annotation annotation)
+ throws ClassNotFoundException
+ {
+ if (AnnotationType.FIELD.equals(annotation.getType()))
+ {
+ ClassLoader cl = SecurityActions.getThreadContextClassLoader();
+ Class clz = Class.forName(annotation.getClassName(), true, cl);
+
+ while (!Object.class.equals(clz))
+ {
+ try
+ {
+ Field field = clz.getDeclaredField(annotation.getMemberName());
+
+ return field.getType().getName();
+ }
+ catch (NoSuchFieldException nsfe)
+ {
+ clz = clz.getSuperclass();
+ }
+ }
+ }
+ else if (AnnotationType.METHOD.equals(annotation.getType()))
+ {
+ ClassLoader cl = SecurityActions.getThreadContextClassLoader();
+ Class clz = Class.forName(annotation.getClassName(), true, cl);
+
+ Class[] parameters = null;
+
+ if (annotation.getParameterTypes() != null)
+ {
+ parameters = new Class[annotation.getParameterTypes().length];
+
+ for (int i = 0; i < annotation.getParameterTypes().length; i++)
+ {
+ String parameter = annotation.getParameterTypes()[i];
+ parameters[i] = Class.forName(parameter, true, cl);
+ }
+ }
+
+ while (!Object.class.equals(clz))
+ {
+ try
+ {
+ Method method = clz.getDeclaredMethod(annotation.getMemberName(), parameters);
+
+ if (void.class.equals(method.getReturnType()))
+ {
+ if (parameters != null && parameters.length > 0)
+ {
+ return parameters[0].getName();
+ }
+ }
+ else
+ {
+ return method.getReturnType().getName();
+ }
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ clz = clz.getSuperclass();
+ }
+ }
+ }
+
+ throw new IllegalArgumentException("Unknown annotation: " + annotation);
+ }
+}
Copied: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/Metadata.java (from rev 101199, projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Metadata.java)
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/Metadata.java (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/Metadata.java 2010-02-20 09:41:46 UTC (rev 101200)
@@ -0,0 +1,366 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.deployers.common;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.logging.Logger;
+import org.jboss.metadata.rar.jboss.JBossRA10MetaData;
+import org.jboss.metadata.rar.jboss.JBossRA20DefaultNSMetaData;
+import org.jboss.metadata.rar.jboss.JBossRA20MetaData;
+import org.jboss.metadata.rar.jboss.JBossRAMetaData;
+import org.jboss.metadata.rar.jboss.RaConfigPropertyMetaData;
+import org.jboss.metadata.rar.spec.ConfigPropertyMetaData;
+import org.jboss.metadata.rar.spec.ConnectionDefinitionMetaData;
+import org.jboss.metadata.rar.spec.ConnectorMetaData;
+import org.jboss.metadata.rar.spec.InboundRaMetaData;
+import org.jboss.metadata.rar.spec.JCA10DTDMetaData;
+import org.jboss.metadata.rar.spec.JCA15DTDMetaData;
+import org.jboss.metadata.rar.spec.JCA15MetaData;
+import org.jboss.metadata.rar.spec.JCA16DTDMetaData;
+import org.jboss.metadata.rar.spec.JCA16DefaultNSMetaData;
+import org.jboss.metadata.rar.spec.JCA16MetaData;
+import org.jboss.metadata.rar.spec.MessageListenerMetaData;
+import org.jboss.metadata.rar.spec.OutboundRaMetaData;
+import org.jboss.metadata.rar.spec.RA10MetaData;
+
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.resolver.MutableSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
+
+/**
+ * The metadata processor for JCA 1.x
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @author <a href="mailto:jeff.zhang at redhat.com">Jeff Zhang</a>
+ */
+public class Metadata
+{
+ private static Logger log = Logger.getLogger(Metadata.class);
+ private static boolean trace = log.isTraceEnabled();
+
+ /**
+ * Constructor
+ */
+ public Metadata()
+ {
+ }
+
+ /**
+ * Get the JCA standard metadata
+ * @param root The root of the deployment
+ * @return The metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ public ConnectorMetaData getStandardMetaData(File root) throws Exception
+ {
+ ConnectorMetaData result = null;
+
+ UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
+ Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+
+ MutableSchemaResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+ resolver.mapLocationToClass("connector_1_6.xsd", JCA16MetaData.class);
+ resolver.mapLocationToClass("connector_1_5.xsd", JCA15MetaData.class);
+ resolver.mapLocationToClass("connector_1_5.dtd", JCA15DTDMetaData.class);
+ resolver.mapLocationToClass("connector_1_6.dtd", JCA16DTDMetaData.class);
+ resolver.mapLocationToClass("connector_1_0.dtd", JCA10DTDMetaData.class);
+ resolver.mapLocationToClass("connector", JCA16DefaultNSMetaData.class);
+
+ File metadataFile = new File(root, "/META-INF/ra.xml");
+
+ if (metadataFile.exists())
+ {
+ String url = metadataFile.getAbsolutePath();
+ try
+ {
+ long start = System.currentTimeMillis();
+
+ result = (ConnectorMetaData)unmarshaller.unmarshal(url, resolver);
+
+ log.debug("Total parse for " + url + " took " + (System.currentTimeMillis() - start) + "ms");
+
+ if (trace)
+ {
+ log.trace("successful parse " + result.getVersion() + " rar package " + result);
+ }
+
+ }
+ catch (Exception e)
+ {
+ log.error("Error during parsing: " + url, e);
+ throw e;
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Get the JBoss specific metadata
+ * @param root The root of the deployment
+ * @return The metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ public JBossRAMetaData getJBossMetaData(File root) throws Exception
+ {
+ JBossRAMetaData result = null;
+
+ UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
+ Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+
+ MutableSchemaResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+ resolver.mapLocationToClass("http://www.jboss.org/schema/jboss-ra_1_0.xsd", JBossRA10MetaData.class);
+ resolver.mapLocationToClass("http://www.jboss.org/schema/jboss-ra_2_0.xsd", JBossRA20MetaData.class);
+ resolver.mapLocationToClass("jboss-ra", JBossRA20DefaultNSMetaData.class);
+
+ File metadataFile = new File(root, "/META-INF/jboss-ra.xml");
+
+ if (metadataFile.exists())
+ {
+ String url = metadataFile.getAbsolutePath();
+ try
+ {
+ long start = System.currentTimeMillis();
+
+ result = (JBossRAMetaData)unmarshaller.unmarshal(url, resolver);
+
+ log.debug("Total parse for " + url + " took " + (System.currentTimeMillis() - start) + "ms");
+
+ if (trace)
+ log.trace(result);
+ }
+ catch (Exception e)
+ {
+ log.error("Error during parsing: " + url, e);
+ throw e;
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Merge specification metadata with vendor metadata
+ * @param cmd The specification metadata
+ * @param jmd The vendor metadata
+ * @return The merged metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ public ConnectorMetaData merge(ConnectorMetaData cmd, JBossRAMetaData jmd) throws Exception
+ {
+ if (cmd != null && jmd != null)
+ {
+ /*
+ <xs:restriction base="javaee:string">
+ <xs:enumeration value="connection-definition"/>
+ <xs:enumeration value="resourceadapter"/>
+ <xs:enumeration value="activationspec"/>
+ <xs:enumeration value="adminobject"/>
+ </xs:restriction>
+ */
+
+ List<RaConfigPropertyMetaData> props = jmd.getRaConfigProps();
+
+ List<ConfigPropertyMetaData> append = null;
+
+ if (props != null)
+ {
+ for (RaConfigPropertyMetaData rcmd : props)
+ {
+ List<ConfigPropertyMetaData> listConfigProp = null;
+ String override = rcmd.getOverride();
+ if (override == null || override.equals("resourceadapter"))
+ {
+ if (cmd.getRa() != null)
+ {
+ listConfigProp = cmd.getRa().getConfigProperty();
+ }
+ }
+ else if (override.equals("connection-definition"))
+ {
+ if (cmd.getRa() != null &&
+ cmd.getRa().getOutboundRa() != null &&
+ cmd.getRa().getOutboundRa().getConDefs() != null &&
+ cmd.getRa().getOutboundRa().getConDefs().size() > 0 &&
+ cmd.getRa().getOutboundRa().getConDefs().get(0) != null)
+ {
+ listConfigProp = cmd.getRa().getOutboundRa().getConDefs().get(0).getConfigProps();
+ }
+ }
+ else if (override.equals("activationspec"))
+ {
+ if (cmd.getRa() != null &&
+ cmd.getRa().getInboundRa() != null &&
+ cmd.getRa().getInboundRa().getMessageAdapter() != null &&
+ cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners() != null &&
+ cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners().size() > 0 &&
+ cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners().get(0) != null &&
+ cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners().get(0).
+ getActivationSpecType() != null)
+ {
+ listConfigProp = cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners().
+ get(0).getActivationSpecType().getConfigProps();
+ }
+ }
+ else if (override.equals("adminobject"))
+ {
+ if (cmd.getRa() != null &&
+ cmd.getRa().getAdminObjects() != null &&
+ cmd.getRa().getAdminObjects().size() > 0 &&
+ cmd.getRa().getAdminObjects().get(0) != null)
+ {
+ listConfigProp = cmd.getRa().getAdminObjects().get(0).getConfigProps();
+ }
+ }
+
+ boolean found = false;
+
+ if (listConfigProp != null)
+ {
+ Iterator<ConfigPropertyMetaData> it = listConfigProp.iterator();
+
+ while (!found && it.hasNext())
+ {
+ ConfigPropertyMetaData cpmd = it.next();
+ if (cpmd.getName().equals(rcmd.getName()) &&
+ cpmd.getType().equals(rcmd.getType()))
+ {
+ cpmd.setValue(rcmd.getValue());
+ found = true;
+ }
+ }
+ }
+
+ if (!found)
+ {
+ if (append == null)
+ append = new ArrayList<ConfigPropertyMetaData>();
+
+ ConfigPropertyMetaData cpmd = new ConfigPropertyMetaData();
+ cpmd.setName(rcmd.getName());
+ cpmd.setType(rcmd.getType());
+ cpmd.setValue(rcmd.getValue());
+
+ append.add(cpmd);
+ }
+ }
+
+ if (append != null)
+ {
+ if (cmd.getRa().getConfigProperty() == null)
+ cmd.getRa().setConfigProperty(new ArrayList<ConfigPropertyMetaData>());
+
+ for (ConfigPropertyMetaData cpmd : append)
+ {
+ cmd.getRa().getConfigProperty().add(cpmd);
+ }
+ }
+ }
+ }
+
+ return cmd;
+ }
+
+ /**
+ * Validate specification metadata
+ * @param cmd The specification metadata
+ * @return The merged metadata
+ * @exception Exception Thrown if an error occurs
+ */
+ public ConnectorMetaData validate(ConnectorMetaData cmd) throws Exception
+ {
+ if (cmd.is10())
+ {
+ RA10MetaData ra10 = ((JCA10DTDMetaData)cmd).getRa10();
+ if (ra10 == null
+ || ra10.getManagedConnectionFactoryClass() == null
+ || ra10.getManagedConnectionFactoryClass().equals(""))
+ {
+ throw new ValidateException("ManagedConnectionFactoryClass should be defined");
+ }
+ return cmd;
+ }
+ //make sure all need metadata parsered and processed after annotation handle
+ if (cmd.getRa() == null)
+ throw new ValidateException("ResourceAdapter metadata should be defined");
+
+ //make sure ra metadata contains inbound or outbound at least
+ boolean inboundOrOutbound = false;
+ if (validateOutbound(cmd.getRa().getOutboundRa()))
+ inboundOrOutbound = true;
+ if (validateInbound(cmd.getRa().getInboundRa()) && cmd.getRa().getRaClass() != null)
+ inboundOrOutbound = true;
+ if (!inboundOrOutbound)
+ throw new ValidateException("ResourceAdapter metadata should contains inbound or outbound at least");
+ return cmd;
+ }
+
+ /**
+ * Validate outbound metadata
+ * @param omd The specification metadata
+ * @return validate
+ * @exception Exception Thrown if an error occurs
+ */
+ private boolean validateOutbound(OutboundRaMetaData omd) throws Exception
+ {
+ if (omd == null)
+ return false;
+ if (omd.getConDefs() == null || omd.getConDefs().size() == 0)
+ return false;
+ ConnectionDefinitionMetaData cdm = omd.getConDefs().get(0);
+ if (cdm.getManagedConnectionFactoryClass() == null ||
+ cdm.getConnectionFactoryInterfaceClass() == null ||
+ cdm.getConnectionFactoryImplementationClass() == null ||
+ cdm.getConnectionInterfaceClass() == null ||
+ cdm.getConnectionImplementationClass() == null)
+ return false;
+
+ return true;
+ }
+
+ /**
+ * Validate inbound metadata
+ * @param cmd The specification metadata
+ * @return validate
+ * @exception Exception Thrown if an error occurs
+ */
+ private boolean validateInbound(InboundRaMetaData imd) throws Exception
+ {
+ if (imd == null)
+ return false;
+ if (imd.getMessageAdapter() == null ||
+ imd.getMessageAdapter().getMessageListeners() == null ||
+ imd.getMessageAdapter().getMessageListeners().size() == 0)
+ return false;
+ MessageListenerMetaData mlmd = imd.getMessageAdapter().getMessageListeners().get(0);
+ if (mlmd.getType() == null ||
+ mlmd.getActivationSpecType() == null ||
+ mlmd.getActivationSpecType().getAsClass() == null)
+ return false;
+ return true;
+ }
+}
Added: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/SecurityActions.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/SecurityActions.java (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/SecurityActions.java 2010-02-20 09:41:46 UTC (rev 101200)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.deployers.common;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged Blocks
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+class SecurityActions
+{
+ /**
+ * Constructor
+ */
+ private SecurityActions()
+ {
+ }
+
+ /**
+ * Get the thread context class loader
+ * @return The class loader
+ */
+ static ClassLoader getThreadContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+
+ /**
+ * Set the thread context class loader
+ * @param cl The class loader
+ */
+ static void setThreadContextClassLoader(final ClassLoader cl)
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(cl);
+ return null;
+ }
+ });
+ }
+
+ /**
+ * Get a system property
+ * @param name The property name
+ * @return The property value
+ */
+ static String getSystemProperty(final String name)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty(name);
+ }
+ });
+ }
+
+ /**
+ * Create an URLClassLoader
+ * @param urls The urls
+ * @param parent The parent class loader
+ * @return The class loader
+ */
+ static URLClassLoader createURLCLassLoader(final URL[] urls, final ClassLoader parent)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>()
+ {
+ public URLClassLoader run()
+ {
+ return new URLClassLoader(urls, parent);
+ }
+ });
+ }
+}
Added: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/ValidateException.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/ValidateException.java (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/ValidateException.java 2010-02-20 09:41:46 UTC (rev 101200)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.deployers.common;
+
+/**
+ * The validate exception
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class ValidateException extends Exception
+{
+ /** Serial version UID */
+ static final long serialVersionUID = 3820032266224196804L;
+
+ /**
+ * Constructs a new exception with the specified detail message.
+ * @param message The message
+ */
+ public ValidateException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and cause.
+ * @param message The message
+ * @param cause The cause
+ */
+ public ValidateException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Added: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/package.html
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/package.html (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/package.html 2010-02-20 09:41:46 UTC (rev 101200)
@@ -0,0 +1,3 @@
+<body>
+This package contains the common classes for the deployer
+</body>
Added: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/Main.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/Main.java (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/Main.java 2010-02-20 09:41:46 UTC (rev 101200)
@@ -0,0 +1,585 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.deployers.common.validator;
+
+import org.jboss.jca.deployers.common.Annotations;
+import org.jboss.jca.deployers.common.Metadata;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ResourceBundle;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.jboss.metadata.rar.spec.AdminObjectMetaData;
+import org.jboss.metadata.rar.spec.ConfigPropertyMetaData;
+import org.jboss.metadata.rar.spec.ConnectionDefinitionMetaData;
+import org.jboss.metadata.rar.spec.ConnectorMetaData;
+import org.jboss.metadata.rar.spec.MessageListenerMetaData;
+
+/**
+ * A Main.
+ *
+ * @author Jeff Zhang</a>
+ * @version $Revision: $
+ */
+public class Main
+{
+ private static final int SUCCESS = 0;
+ private static final int FAIL = 1;
+ private static final int OTHER = 2;
+
+ /**
+ * validate
+ * @param url The url
+ * @return The system exit code
+ */
+ private static int validate(URL url)
+ {
+ if (url == null || !(url.toExternalForm().endsWith(".rar") || url.toExternalForm().endsWith(".rar/")))
+ return FAIL;
+
+ int exitCode = SUCCESS;
+ File destination = null;
+
+ try
+ {
+ File f = new File(url.toURI());
+
+ if (!f.exists())
+ throw new IOException("Archive " + url.toExternalForm() + " doesnt exists");
+
+ File root = null;
+
+ if (f.isFile())
+ {
+ destination = new File(SecurityActions.getSystemProperty("java.io.tmpdir"), "/tmp/");
+ root = extract(f, destination);
+ }
+ else
+ {
+ root = f;
+ }
+
+ // Create classloader
+ URL[] urls = getUrls(root);
+ URLClassLoader cl = SecurityActions.createURLCLassLoader(urls, SecurityActions.getThreadContextClassLoader());
+ SecurityActions.setThreadContextClassLoader(cl);
+
+ // Parse metadata
+ Metadata metadataHandler = new Metadata();
+ ConnectorMetaData cmd = metadataHandler.getStandardMetaData(root);
+
+
+ // Annotation scanning
+ Annotations annotator = new Annotations();
+ cmd = annotator.scan(cmd, cl.getURLs(), cl);
+
+
+ List<Validate> validateClasses = new ArrayList<Validate>();
+ List<Failure> failures = new ArrayList<Failure>();
+
+ Validator validator = new Validator();
+ validateClasses.addAll(createResourceAdapter(cmd, failures, validator.getResourceBundle(), cl));
+ validateClasses.addAll(createManagedConnectionFactory(cmd, failures, validator.getResourceBundle(), cl));
+ validateClasses.addAll(createActivationSpec(cmd, failures, validator.getResourceBundle(), cl));
+ validateClasses.addAll(createAdminObject(cmd, failures, validator.getResourceBundle(), cl));
+
+ List<Failure> classFailures = validator.validate(validateClasses.
+ toArray(new Validate[validateClasses.size()]));
+ if (classFailures != null && classFailures.size() > 0)
+ failures.addAll(classFailures);
+
+ if (failures != null && failures.size() > 0)
+ {
+ FailureHelper fh = new FailureHelper(failures);
+ File reportDirectory = new File(".");
+
+ if (reportDirectory.exists())
+ {
+ String reportName = url.getFile();
+ int lastIndex = reportName.lastIndexOf(File.separator);
+ if (lastIndex != -1)
+ reportName = reportName.substring(lastIndex + 1);
+ reportName += ".log";
+
+ File report = new File(reportDirectory, reportName);
+ FileWriter fw = null;
+ try
+ {
+ fw = new FileWriter(report);
+ BufferedWriter bw = new BufferedWriter(fw, 8192);
+ bw.write(fh.asText(validator.getResourceBundle()));
+ bw.flush();
+ }
+ catch (IOException ioe)
+ {
+ ioe.printStackTrace();
+ }
+ finally
+ {
+ if (fw != null)
+ {
+ try
+ {
+ fw.close();
+ }
+ catch (IOException ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+ exitCode = FAIL;
+ }
+ exitCode = SUCCESS;
+ }
+ catch (Exception e)
+ {
+ exitCode = OTHER;
+ }
+
+ if (destination != null)
+ {
+ try
+ {
+ recursiveDelete(destination);
+ }
+ catch (IOException ioe)
+ {
+ // Ignore
+ }
+ }
+
+ return exitCode;
+ }
+
+ /**
+ * createResourceAdapter
+ * @param cmd connector metadata
+ * @param failures list of failures
+ * @param rb ResourceBundle
+ * @param cl classloador
+ * @return list of validate objects
+ */
+ private static List<Validate> createResourceAdapter(ConnectorMetaData cmd,
+ List<Failure> failures, ResourceBundle rb, ClassLoader cl)
+ {
+ List<Validate> result = new ArrayList<Validate>();
+
+ if (cmd.getRa() != null && cmd.getRa().getRaClass() != null)
+ {
+ try
+ {
+ Class<?> clazz = Class.forName(cmd.getRa().getRaClass(), true, cl);
+ List<ConfigPropertyMetaData> configProperties = cmd.getRa().getConfigProperty();
+
+ ValidateClass vc = new ValidateClass(Key.RESOURCE_ADAPTER, clazz, configProperties);
+ result.add(vc);
+ }
+ catch (ClassNotFoundException e)
+ {
+ Failure failure = new Failure(Severity.ERROR,
+ rb.getString("uncategorized"),
+ rb.getString("ra.cnfe"),
+ e.getMessage());
+ failures.add(failure);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * createManagedConnectionFactory
+ * @param cmd connector metadata
+ * @param failures list of failures
+ * @param rb ResourceBundle
+ * @param cl classloador
+ * @return list of validate objects
+ */
+ private static List<Validate> createManagedConnectionFactory(ConnectorMetaData cmd,
+ List<Failure> failures, ResourceBundle rb, ClassLoader cl)
+ {
+ List<Validate> result = new ArrayList<Validate>();
+
+ if (cmd.getRa() != null && cmd.getRa().getOutboundRa() != null
+ && cmd.getRa().getOutboundRa().getConDefs() != null)
+ {
+ List<ConnectionDefinitionMetaData> cdMetas = cmd.getRa().getOutboundRa().getConDefs();
+ if (cdMetas.size() > 0)
+ {
+ for (ConnectionDefinitionMetaData cdMeta : cdMetas)
+ {
+ if (cdMeta.getManagedConnectionFactoryClass() != null)
+ {
+ try
+ {
+ Class<?> clazz = Class.forName(cdMeta.getManagedConnectionFactoryClass(), true, cl);
+ List<ConfigPropertyMetaData> configProperties = cdMeta.getConfigProps();
+
+ ValidateClass vc = new ValidateClass(Key.MANAGED_CONNECTION_FACTORY, clazz, configProperties);
+ result.add(vc);
+ }
+ catch (ClassNotFoundException e)
+ {
+ Failure failure = new Failure(Severity.ERROR,
+ rb.getString("uncategorized"),
+ rb.getString("mcf.cnfe"),
+ e.getMessage());
+ failures.add(failure);
+ }
+ }
+
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * createActivationSpec
+ * @param cmd connector metadata
+ * @param failures list of failures
+ * @param rb ResourceBundle
+ * @param cl classloador
+ * @return list of validate objects
+ */
+ private static List<Validate> createActivationSpec(ConnectorMetaData cmd,
+ List<Failure> failures, ResourceBundle rb, ClassLoader cl)
+ {
+ List<Validate> result = new ArrayList<Validate>();
+
+ if (cmd.getRa() != null &&
+ cmd.getRa().getInboundRa() != null &&
+ cmd.getRa().getInboundRa().getMessageAdapter() != null &&
+ cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners() != null)
+ {
+ List<MessageListenerMetaData> mlMetas = cmd.getRa().getInboundRa().
+ getMessageAdapter().getMessageListeners();
+ if (mlMetas.size() > 0)
+ {
+ for (MessageListenerMetaData mlMeta : mlMetas)
+ {
+ if (mlMeta.getActivationSpecType() != null && mlMeta.getActivationSpecType().getAsClass() != null)
+ {
+
+ try
+ {
+ Class<?> clazz = Class.forName(mlMeta.getActivationSpecType().getAsClass(), true, cl);
+ List<ConfigPropertyMetaData> configProperties = mlMeta.getActivationSpecType().getConfigProps();
+
+ ValidateClass vc = new ValidateClass(Key.ACTIVATION_SPEC, clazz, configProperties);
+ result.add(vc);
+ }
+ catch (ClassNotFoundException e)
+ {
+ Failure failure = new Failure(Severity.ERROR,
+ rb.getString("uncategorized"),
+ rb.getString("as.cnfe"),
+ e.getMessage());
+ failures.add(failure);
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * createAdminObject
+ * @param cmd connector metadata
+ * @param failures list of failures
+ * @param rb ResourceBundle
+ * @param cl classloador
+ * @return list of validate objects
+ */
+ private static List<Validate> createAdminObject(ConnectorMetaData cmd,
+ List<Failure> failures, ResourceBundle rb, ClassLoader cl)
+ {
+ List<Validate> result = new ArrayList<Validate>();
+
+ if (cmd.getRa() != null &&
+ cmd.getRa().getAdminObjects() != null)
+ {
+ List<AdminObjectMetaData> aoMetas = cmd.getRa().getAdminObjects();
+ if (aoMetas.size() > 0)
+ {
+ for (AdminObjectMetaData aoMeta : aoMetas)
+ {
+ if (aoMeta.getAdminObjectImplementationClass() != null)
+ {
+
+ try
+ {
+ Class<?> clazz = Class.forName(aoMeta.getAdminObjectImplementationClass(), true, cl);
+ List<ConfigPropertyMetaData> configProperties = aoMeta.getConfigProps();
+
+ ValidateClass vc = new ValidateClass(Key.ADMIN_OBJECT, clazz, configProperties);
+ result.add(vc);
+ }
+ catch (ClassNotFoundException e)
+ {
+ Failure failure = new Failure(Severity.ERROR,
+ rb.getString("uncategorized"),
+ rb.getString("ao.cnfe"),
+ e.getMessage());
+ failures.add(failure);
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Validator standalone tool
+ *
+ * @param args command line arguments
+ */
+ public static void main(String[] args)
+ {
+ if (args.length == 1)
+ {
+ try
+ {
+ int systemExitCode = validate(new File(args[0]).toURI().toURL());
+
+ if (systemExitCode == FAIL)
+ {
+ System.out.println("Validation errors");
+ }
+ System.exit(systemExitCode);
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ else
+ {
+ usage();
+ }
+
+
+ }
+
+ /**
+ * Tool usage
+ */
+ private static void usage()
+ {
+ System.out.println("Usage: validator <file>");
+ }
+
+
+ /**
+ * Extract a JAR type file
+ * @param file The file
+ * @param directory The directory where the file should be extracted
+ * @return The root of the extracted JAR file
+ * @exception IOException Thrown if an error occurs
+ */
+ private static File extract(File file, File directory) throws IOException
+ {
+ if (file == null)
+ throw new IllegalArgumentException("File is null");
+
+ if (directory == null)
+ throw new IllegalArgumentException("Directory is null");
+
+ File target = new File(directory, file.getName());
+
+ if (target.exists())
+ recursiveDelete(target);
+
+ if (!target.mkdirs())
+ throw new IOException("Could not create " + target);
+
+ JarFile jar = new JarFile(file);
+ Enumeration<JarEntry> entries = jar.entries();
+
+ while (entries.hasMoreElements())
+ {
+ JarEntry je = entries.nextElement();
+ File copy = new File(target, je.getName());
+
+ if (!je.isDirectory())
+ {
+ InputStream in = null;
+ OutputStream out = null;
+
+ // Make sure that the directory is _really_ there
+ if (copy.getParentFile() != null && !copy.getParentFile().exists())
+ {
+ if (!copy.getParentFile().mkdirs())
+ throw new IOException("Could not create " + copy.getParentFile());
+ }
+
+ try
+ {
+ in = new BufferedInputStream(jar.getInputStream(je));
+ out = new BufferedOutputStream(new FileOutputStream(copy));
+
+ byte[] buffer = new byte[4096];
+ for (;;)
+ {
+ int nBytes = in.read(buffer);
+ if (nBytes <= 0)
+ break;
+
+ out.write(buffer, 0, nBytes);
+ }
+ out.flush();
+ }
+ finally
+ {
+ try
+ {
+ if (out != null)
+ out.close();
+ }
+ catch (IOException ignore)
+ {
+ // Ignore
+ }
+
+ try
+ {
+ if (in != null)
+ in.close();
+ }
+ catch (IOException ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+ else
+ {
+ if (!copy.exists())
+ {
+ if (!copy.mkdirs())
+ throw new IOException("Could not create " + copy);
+ }
+ else
+ {
+ if (!copy.isDirectory())
+ throw new IOException(copy + " isn't a directory");
+ }
+ }
+ }
+
+ return target;
+ }
+
+
+ /**
+ * Recursive delete
+ * @param f The file handler
+ * @exception IOException Thrown if a file could not be deleted
+ */
+ private static void recursiveDelete(File f) throws IOException
+ {
+ if (f != null && f.exists())
+ {
+ File[] files = f.listFiles();
+ if (files != null)
+ {
+ for (int i = 0; i < files.length; i++)
+ {
+ if (files[i].isDirectory())
+ {
+ recursiveDelete(files[i]);
+ }
+ else
+ {
+ if (!files[i].delete())
+ throw new IOException("Could not delete " + files[i]);
+ }
+ }
+ }
+ if (!f.delete())
+ throw new IOException("Could not delete " + f);
+ }
+ }
+
+ /**
+ * Get the URLs for the directory and all libraries located in the directory
+ * @param directory The directory
+ * @return The URLs
+ * @exception MalformedURLException MalformedURLException
+ * @exception IOException IOException
+ */
+ private static URL[] getUrls(File directory) throws MalformedURLException, IOException
+ {
+ List<URL> list = new LinkedList<URL>();
+
+ if (directory.exists() && directory.isDirectory())
+ {
+ // Add directory
+ list.add(directory.toURI().toURL());
+
+ // Add the contents of the directory too
+ File[] jars = directory.listFiles(new FilenameFilter()
+ {
+ /**
+ * Accept
+ * @param dir The directory
+ * @param name The name
+ * @return True if accepts; otherwise false
+ */
+ public boolean accept(File dir, String name)
+ {
+ return name.endsWith(".jar");
+ }
+ });
+
+ if (jars != null)
+ {
+ for (int j = 0; j < jars.length; j++)
+ {
+ list.add(jars[j].getCanonicalFile().toURI().toURL());
+ }
+ }
+ }
+ return list.toArray(new URL[list.size()]);
+ }
+}
Added: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/SecurityActions.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/SecurityActions.java (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/SecurityActions.java 2010-02-20 09:41:46 UTC (rev 101200)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.deployers.common.validator;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged Blocks
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+class SecurityActions
+{
+ /**
+ * Constructor
+ */
+ private SecurityActions()
+ {
+ }
+
+ /**
+ * Get the thread context class loader
+ * @return The class loader
+ */
+ static ClassLoader getThreadContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+
+ /**
+ * Set the thread context class loader
+ * @param cl The class loader
+ */
+ static void setThreadContextClassLoader(final ClassLoader cl)
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(cl);
+ return null;
+ }
+ });
+ }
+
+ /**
+ * Get a system property
+ * @param name The property name
+ * @return The property value
+ */
+ static String getSystemProperty(final String name)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty(name);
+ }
+ });
+ }
+
+ /**
+ * Create an URLClassLoader
+ * @param urls The urls
+ * @param parent The parent class loader
+ * @return The class loader
+ */
+ static URLClassLoader createURLCLassLoader(final URL[] urls, final ClassLoader parent)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>()
+ {
+ public URLClassLoader run()
+ {
+ return new URLClassLoader(urls, parent);
+ }
+ });
+ }
+}
Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/Validator.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/Validator.java 2010-02-20 06:08:46 UTC (rev 101199)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/Validator.java 2010-02-20 09:41:46 UTC (rev 101200)
@@ -91,7 +91,7 @@
* @param objects Objects that should be validated
* @return The list of failures; <code>null</code> if no errors
*/
- public List<Failure> validate(ValidateClass[] objects)
+ public List<Failure> validate(Validate[] objects)
{
if (objects == null || objects.length == 0)
return null;
@@ -119,7 +119,7 @@
for (Rule rule : rules)
{
- for (ValidateClass obj : objects)
+ for (Validate obj : objects)
{
List<Failure> failures = rule.validate(obj, resourceBundle);
Deleted: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Annotations.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Annotations.java 2010-02-20 06:08:46 UTC (rev 101199)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Annotations.java 2010-02-20 09:41:46 UTC (rev 101200)
@@ -1,1087 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.deployers.fungal;
-
-import org.jboss.jca.fungal.deployers.DeployException;
-
-import java.lang.reflect.Array;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-
-import javax.resource.spi.Activation;
-import javax.resource.spi.AdministeredObject;
-import javax.resource.spi.AuthenticationMechanism;
-import javax.resource.spi.AuthenticationMechanism.CredentialInterface;
-import javax.resource.spi.ConfigProperty;
-import javax.resource.spi.ConnectionDefinition;
-import javax.resource.spi.ConnectionDefinitions;
-import javax.resource.spi.Connector;
-import javax.resource.spi.SecurityPermission;
-import javax.resource.spi.TransactionSupport;
-import javax.resource.spi.TransactionSupport.TransactionSupportLevel;
-import javax.resource.spi.work.WorkContext;
-
-import org.jboss.logging.Logger;
-
-import org.jboss.metadata.javaee.spec.DescriptionGroupMetaData;
-import org.jboss.metadata.javaee.spec.DescriptionImpl;
-import org.jboss.metadata.javaee.spec.DescriptionsImpl;
-import org.jboss.metadata.javaee.spec.DisplayNameImpl;
-import org.jboss.metadata.javaee.spec.DisplayNamesImpl;
-import org.jboss.metadata.javaee.spec.IconImpl;
-import org.jboss.metadata.javaee.spec.IconsImpl;
-
-import org.jboss.metadata.rar.spec.ActivationspecMetaData;
-import org.jboss.metadata.rar.spec.AdminObjectMetaData;
-import org.jboss.metadata.rar.spec.AuthenticationMechanismMetaData;
-import org.jboss.metadata.rar.spec.ConfigPropertyMetaData;
-import org.jboss.metadata.rar.spec.ConnectionDefinitionMetaData;
-import org.jboss.metadata.rar.spec.ConnectorMetaData;
-import org.jboss.metadata.rar.spec.InboundRaMetaData;
-import org.jboss.metadata.rar.spec.JCA16Base;
-import org.jboss.metadata.rar.spec.JCA16MetaData;
-import org.jboss.metadata.rar.spec.LicenseMetaData;
-import org.jboss.metadata.rar.spec.MessageAdapterMetaData;
-import org.jboss.metadata.rar.spec.MessageListenerMetaData;
-import org.jboss.metadata.rar.spec.OutboundRaMetaData;
-import org.jboss.metadata.rar.spec.ResourceAdapterMetaData;
-import org.jboss.metadata.rar.spec.SecurityPermissionMetaData;
-import org.jboss.metadata.rar.spec.TransactionSupportMetaData;
-import org.jboss.papaki.Annotation;
-import org.jboss.papaki.AnnotationRepository;
-import org.jboss.papaki.AnnotationType;
-
-/**
- * The annotation processor for JCA 1.6
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- */
-public class Annotations
-{
- private static Logger log = Logger.getLogger(Annotations.class);
- private static boolean trace = log.isTraceEnabled();
-
- /**
- * Constructor
- */
- public Annotations()
- {
- }
-
- /**
- * Process annotations
- * @param md The metadata
- * @param annotationRepository The annotation repository
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- public ConnectorMetaData process(ConnectorMetaData md, AnnotationRepository annotationRepository)
- throws Exception
- {
- if (annotationRepository == null)
- throw new DeployException("AnnotationRepository reference is null");
- /* Process
- -------
- javax.resource.spi.Activation
- javax.resource.spi.AdministeredObject
- javax.resource.spi.AuthenticationMechanism
- javax.resource.spi.ConfigProperty
- javax.resource.spi.ConnectionDefinition
- javax.resource.spi.ConnectionDefinitions
- javax.resource.spi.Connector
- javax.resource.spi.SecurityPermission
- */
-
- if (md == null)
- {
- JCA16MetaData jmd = new JCA16MetaData();
- jmd.setMetadataComplete(false);
- md = jmd;
- }
-
- // @Connector
- md = processConnector(md, annotationRepository);
-
- // @ConnectionDefinitions
- md = processConnectionDefinitions(md, annotationRepository);
-
- // @ConnectionDefinition (outside of @ConnectionDefinitions)
- md = processConnectionDefinition(md, annotationRepository);
-
- // @Activation
- md = processActivation(md, annotationRepository);
-
- // @AuthenticationMechanism
- //md = processAuthenticationMechanism(md, annotationRepository);
-
- // @AdministeredObject
- md = processAdministeredObject(md, annotationRepository);
-
- // @ConfigProperty handle at last
- md = processConfigProperty(md, annotationRepository);
-
- //log.debug("ConnectorMetadata " + md);
-
- return md;
- }
-
- /**
- * Process: @Connector
- * @param md The metadata
- * @param annotationRepository The annotation repository
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData processConnector(ConnectorMetaData md, AnnotationRepository annotationRepository)
- throws Exception
- {
- Collection<Annotation> values = annotationRepository.getAnnotation(Connector.class);
- if (values != null)
- {
- if (values.size() == 1)
- {
- Annotation annotation = values.iterator().next();
- String raClass = annotation.getClassName();
- Connector c = (Connector)annotation.getAnnotation();
-
- if (trace)
- log.trace("Processing: " + c + " for " + raClass);
-
- md = attachConnector(md, raClass, c);
- }
- else if (values.size() == 0)
- {
- // JBJCA-240
- if (md.getRa().getRaClass() == null || md.getRa().getRaClass().equals(""))
- {
- log.fatal("No @Connector was found and no definition in the ra.xml metadata either");
- throw new DeployException("No @Connector defined");
- }
- }
- else
- {
- // JBJCA-240
- if (md.getRa().getRaClass() == null || md.getRa().getRaClass().equals(""))
- {
- log.fatal("More than one @Connector was found but the correct one " +
- "wasn't defined in the ra.xml metadata");
- throw new DeployException("More than one @Connector defined");
- }
- }
- }
-
- return md;
- }
-
- /**
- * Attach @Connector
- * @param md The metadata
- * @param raClass The class name for the resource adapter
- * @param c The connector
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData attachConnector(ConnectorMetaData md, String raClass, Connector c)
- throws Exception
- {
- // Class definition
- if (md.getRa() == null)
- md.setRa(new ResourceAdapterMetaData());
-
- md.getRa().setRaClass(raClass);
-
- // AuthenticationMechanism
- AuthenticationMechanism[] authMechanisms = c.authMechanisms();
- if (authMechanisms != null)
- {
- for (AuthenticationMechanism authMechanism : authMechanisms)
- {
- attachAuthenticationMechanism(md, authMechanism);
- }
- }
-
- DescriptionGroupMetaData descGroup = new DescriptionGroupMetaData();
- md.setDescriptionGroup(descGroup);
-
- // Description
- String[] description = c.description();
- if (description != null)
- {
- if (descGroup.getDescriptions() == null)
- {
- DescriptionsImpl descsImpl = new DescriptionsImpl();
- descGroup.setDescriptions(descsImpl);
- }
- for (String desc : description)
- {
- DescriptionImpl descImpl = new DescriptionImpl();
- descImpl.setDescription(desc);
- ((DescriptionsImpl)descGroup.getDescriptions()).add(descImpl);
- }
- }
-
- // Display name
- String[] displayName = c.displayName();
- if (displayName != null)
- {
- if (descGroup.getDisplayNames() == null)
- {
- DisplayNamesImpl dnsImpl = new DisplayNamesImpl();
- descGroup.setDisplayNames(dnsImpl);
- }
- for (String dn : displayName)
- {
- DisplayNameImpl dnImpl = new DisplayNameImpl();
- dnImpl.setDisplayName(dn);
- ((DisplayNamesImpl)descGroup.getDisplayNames()).add(dnImpl);
- }
- }
-
- // EIS type
- String eisType = c.eisType();
- if (eisType != null)
- {
- if (md.getEISType() == null)
- md.setEISType(eisType);
- }
-
- // Large icon
- String[] largeIcon = c.largeIcon();
- if (largeIcon != null)
- {
- if (descGroup.getIcons() == null)
- {
- IconsImpl icsImpl = new IconsImpl();
- descGroup.setIcons(icsImpl);
- }
- for (String large : largeIcon)
- {
- IconImpl icImpl = new IconImpl();
- icImpl.setLargeIcon(large);
- ((IconsImpl)descGroup.getIcons()).add(icImpl);
- }
- }
-
- // License description
- String[] licenseDescription = c.licenseDescription();
- if (licenseDescription != null)
- {
- if (md.getLicense() == null)
- md.setLicense(new LicenseMetaData());
-
- if (md.getLicense().getDescriptions() == null)
- {
- DescriptionsImpl descsImpl = new DescriptionsImpl();
- md.getLicense().setDescriptions(descsImpl);
- }
- for (String desc : licenseDescription)
- {
- DescriptionImpl descImpl = new DescriptionImpl();
- descImpl.setDescription(desc);
- ((DescriptionsImpl)md.getLicense().getDescriptions()).add(descImpl);
- }
- }
-
- // License required
- boolean licenseRequired = c.licenseRequired();
- if (md.getLicense() == null)
- md.setLicense(new LicenseMetaData());
- md.getLicense().setRequired(licenseRequired);
-
- // Reauthentication support
- boolean reauthenticationSupport = c.reauthenticationSupport();
- if (md.getRa() != null && md.getRa().getOutboundRa() != null)
- {
- md.getRa().getOutboundRa().setReAuthSupport(reauthenticationSupport);
- }
-
- // RequiredWorkContext
- Class<? extends WorkContext>[] requiredWorkContexts = c.requiredWorkContexts();
- if (requiredWorkContexts != null)
- {
- for (Class<? extends WorkContext> requiredWorkContext : requiredWorkContexts)
- {
- if (md instanceof JCA16Base)
- {
- JCA16Base jmd = (JCA16Base)md;
- if (jmd.getRequiredWorkContexts() == null)
- jmd.setRequiredWorkContexts(new ArrayList<String>());
-
- if (!jmd.getRequiredWorkContexts().contains(requiredWorkContext.getName()))
- {
- if (trace)
- log.trace("RequiredWorkContext=" + requiredWorkContext.getName());
-
- jmd.getRequiredWorkContexts().add(requiredWorkContext.getName());
- }
- }
- }
- }
-
- // Security permission
- SecurityPermission[] securityPermissions = c.securityPermissions();
- if (securityPermissions != null)
- {
- if (md.getRa() == null)
- md.setRa(new ResourceAdapterMetaData());
-
- if (md.getRa().getSecurityPermissions() == null)
- md.getRa().setSecurityPermissions(new ArrayList<SecurityPermissionMetaData>());
-
- for (SecurityPermission securityPermission : securityPermissions)
- {
- SecurityPermissionMetaData spmd = new SecurityPermissionMetaData();
- spmd.setSecurityPermissionSpec(securityPermission.permissionSpec());
- md.getRa().getSecurityPermissions().add(spmd);
- }
- }
-
- // Small icon
- String[] smallIcon = c.smallIcon();
- if (smallIcon != null)
- {
- IconsImpl icsImpl;
- if (descGroup.getIcons() == null)
- {
- icsImpl = new IconsImpl();
- descGroup.setIcons(icsImpl);
- }
- else
- {
- icsImpl = (IconsImpl)descGroup.getIcons();
- }
- IconImpl[] icArray = icsImpl.toArray(new IconImpl[icsImpl.size()]);
- for (int i = 0; i < smallIcon.length; i++)
- {
- if (i < icArray.length)
- icArray[i].setSmallIcon(smallIcon[i]);
- else
- {
- IconImpl icImpl = new IconImpl();
- icImpl.setLargeIcon(smallIcon[i]);
- icsImpl.add(icImpl);
- }
- }
- }
-
- // Transaction support
- TransactionSupport.TransactionSupportLevel transactionSupport = c.transactionSupport();
- if (md.getRa() != null && md.getRa().getOutboundRa() != null)
- {
- if (transactionSupport.equals(TransactionSupportLevel.NoTransaction))
- {
- md.getRa().getOutboundRa().setTransSupport(TransactionSupportMetaData.NoTransaction);
- }
- else if (transactionSupport.equals(TransactionSupportLevel.XATransaction))
- {
- md.getRa().getOutboundRa().setTransSupport(TransactionSupportMetaData.XATransaction);
- }
- else if (transactionSupport.equals(TransactionSupportLevel.LocalTransaction))
- {
- md.getRa().getOutboundRa().setTransSupport(TransactionSupportMetaData.LocalTransaction);
- }
- }
-
- // Vendor name
- String vendorName = c.vendorName();
- if (vendorName != null)
- {
- if (md.getVendorName() == null)
- md.setVendorName(vendorName);
- }
-
- // Version
- String version = c.version();
- if (version != null)
- {
- if (md.getRAVersion() == null)
- md.setRAVersion(version);
- }
-
- return md;
- }
-
- /**
- * Process: @ConnectionDefinitions
- * @param md The metadata
- * @param annotationRepository The annotation repository
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData processConnectionDefinitions(ConnectorMetaData md,
- AnnotationRepository annotationRepository)
- throws Exception
- {
- Collection<Annotation> values = annotationRepository.getAnnotation(ConnectionDefinitions.class);
- if (values != null)
- {
- if (values.size() == 1)
- {
- Annotation annotation = values.iterator().next();
- ConnectionDefinitions c = (ConnectionDefinitions)annotation.getAnnotation();
-
- if (trace)
- log.trace("Processing: " + c);
-
- md = attachConnectionDefinitions(md , c, annotation.getClassName());
- }
- else
- throw new DeployException("More than one @ConnectionDefinitions defined");
- }
-
- return md;
- }
-
- /**
- * Attach @ConnectionDefinitions
- * @param md The metadata
- * @param cds The connection definitions
- * @param mcf The managed connection factory
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData attachConnectionDefinitions(ConnectorMetaData md,
- ConnectionDefinitions cds,
- String mcf)
- throws Exception
- {
- createConDefs(md);
-
- if (cds.value() != null)
- {
- for (ConnectionDefinition cd : cds.value())
- {
- md = attachConnectionDefinition(md, mcf, cd);
- }
- }
-
- return md;
- }
-
- /**
- * Process: @ConnectionDefinition
- * @param md The metadata
- * @param annotationRepository The annotation repository
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData processConnectionDefinition(ConnectorMetaData md,
- AnnotationRepository annotationRepository)
- throws Exception
- {
- Collection<Annotation> values = annotationRepository.getAnnotation(ConnectionDefinition.class);
- if (values != null)
- {
- for (Annotation annotation : values)
- {
- md = attachConnectionDefinition(md, annotation);
- }
- }
-
- return md;
- }
-
- /**
- * Attach @ConnectionDefinition
- * @param md The metadata
- * @param cd The connection definition
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData attachConnectionDefinition(ConnectorMetaData md, Annotation annotation)
- throws Exception
- {
- ConnectionDefinition cd = (ConnectionDefinition)annotation.getAnnotation();
-
- if (trace)
- log.trace("Processing: " + annotation);
-
- createConDefs(md);
-
- for (ConnectionDefinitionMetaData cdMeta : md.getRa().getOutboundRa().getConDefs())
- {
- if (cdMeta.getManagedConnectionFactoryClass().equals(annotation.getClassName()))
- {
- //ra.xml define
- return md;
- }
- }
-
- return attachConnectionDefinition(md, annotation.getClassName(), cd);
- }
-
- /**
- * Attach @ConnectionDefinition
- * @param md The metadata
- * @param mcf The managed connection factory
- * @param cd The connection definition
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData attachConnectionDefinition(ConnectorMetaData md,
- String mcf,
- ConnectionDefinition cd)
- throws Exception
- {
- if (trace)
- log.trace("Processing: " + cd);
-
- createConDefs(md);
-
- ConnectionDefinitionMetaData cdMeta = new ConnectionDefinitionMetaData();
- cdMeta.setManagedConnectionFactoryClass(mcf);
- cdMeta.setConnectionFactoryInterfaceClass(cd.connectionFactory().getName());
- cdMeta.setConnectionFactoryImplementationClass(cd.connectionFactoryImpl().getName());
- cdMeta.setConnectionInterfaceClass(cd.connection().getName());
- cdMeta.setConnectionImplementationClass(cd.connectionImpl().getName());
- md.getRa().getOutboundRa().getConDefs().add(cdMeta);
- return md;
- }
-
- /**
- * Process: @ConfigProperty
- * @param md The metadata
- * @param annotationRepository The annotation repository
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData processConfigProperty(ConnectorMetaData md,
- AnnotationRepository annotationRepository)
- throws Exception
- {
- Collection<Annotation> values = annotationRepository.getAnnotation(ConfigProperty.class);
- if (values != null)
- {
- for (Annotation annotation : values)
- {
- md = attachConfigProperty(md, annotation);
- }
- }
-
- return md;
- }
-
- /**
- * Attach @ConfigProperty
- * @param md The metadata
- * @param configProperty The config property
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData attachConfigProperty(ConnectorMetaData md, Annotation annotation)
- throws Exception
- {
- ConfigProperty configProperty = (ConfigProperty)annotation.getAnnotation();
-
- if (trace)
- log.trace("Processing: " + configProperty);
-
- // Ignore config-property which has ignore=true
- if (configProperty.ignore())
- return md;
-
- ConfigPropertyMetaData cfgMeta = new ConfigPropertyMetaData();
- cfgMeta.setName(getConfigPropertyName(annotation));
- cfgMeta.setValue(configProperty.defaultValue());
- if (!Object.class.equals(configProperty.type()))
- {
- cfgMeta.setType(configProperty.type().getName());
- }
- else
- {
- cfgMeta.setType(getConfigPropertyType(annotation));
- }
- cfgMeta.setIgnore(configProperty.ignore());
-
- String[] description = configProperty.description();
- if (description != null)
- {
- if (cfgMeta.getDescriptions() == null)
- {
- DescriptionsImpl descsImpl = new DescriptionsImpl();
- cfgMeta.setDescriptions(descsImpl);
- }
- for (String desc : description)
- {
- DescriptionImpl descImpl = new DescriptionImpl();
- descImpl.setDescription(desc);
- ((DescriptionsImpl)cfgMeta.getDescriptions()).add(descImpl);
- }
- }
-
- String attachedClassName = annotation.getClassName();
- ClassLoader cl = SecurityActions.getThreadContextClassLoader();
- Class attachedClass = Class.forName(attachedClassName, true, cl);
-
- if (hasInterface(attachedClass, "javax.resource.spi.ResourceAdapter"))
- {
- if (md.getRa() == null)
- {
- md.setRa(new ResourceAdapterMetaData());
- }
- if (md.getRa().getConfigProperty() == null)
- {
- md.getRa().setConfigProperty(new ArrayList<ConfigPropertyMetaData>());
- }
- for (ConfigPropertyMetaData cpMeta : md.getRa().getConfigProperty())
- {
- if (cpMeta.getName().equals(cfgMeta.getName()))
- {
- return md;
- }
- }
- md.getRa().getConfigProperty().add(cfgMeta);
- }
- else if (hasInterface(attachedClass, "javax.resource.spi.ManagedConnectionFactory"))
- {
- createConDefs(md);
- for (ConnectionDefinitionMetaData cdMeta : md.getRa().getOutboundRa().getConDefs())
- {
- if (attachedClassName.equals(cdMeta.getManagedConnectionFactoryClass()))
- {
- if (cdMeta.getConfigProps() == null)
- {
- cdMeta.setConfigProps(new ArrayList<ConfigPropertyMetaData>());
- }
- for (ConfigPropertyMetaData cpMeta : cdMeta.getConfigProps())
- {
- if (cpMeta.getName().equals(cfgMeta.getName()))
- {
- return md;
- }
- }
- cdMeta.getConfigProps().add(cfgMeta);
- }
- }
- }
- else if (hasInterface(attachedClass, "javax.resource.spi.ActivationSpec"))
- {
- createMessageListeners(md);
- for (MessageListenerMetaData mlMeta : md.getRa().getInboundRa().getMessageAdapter().getMessageListeners())
- {
- if (attachedClassName.equals(mlMeta.getActivationSpecType().getAsClass()))
- {
- if (mlMeta.getActivationSpecType().getConfigProps() == null)
- {
- mlMeta.getActivationSpecType().setConfigProps(new ArrayList<ConfigPropertyMetaData>());
- }
- for (ConfigPropertyMetaData cpMeta : mlMeta.getActivationSpecType().getConfigProps())
- {
- if (cpMeta.getName().equals(cfgMeta.getName()))
- {
- return md;
- }
- }
- mlMeta.getActivationSpecType().getConfigProps().add(cfgMeta);
- }
- }
- }
-
- return md;
- }
-
- /**
- * hasInterface
- *
- * @param c
- * @param targetClassName
- * @return
- */
- private boolean hasInterface(Class c, String targetClassName)
- {
- for (Class face : c.getInterfaces())
- {
- if (face.getName().equals(targetClassName))
- {
- return true;
- }
- else
- {
- for (Class face2 : face.getInterfaces())
- {
- if (face2.getName().equals(targetClassName))
- {
- return true;
- }
- else if (hasInterface(face2, targetClassName))
- {
- return true;
- }
- }
- }
- }
- if (null != c.getSuperclass())
- {
- return hasInterface(c.getSuperclass(), targetClassName);
- }
- return false;
- }
-
- /**
- * Attach @AuthenticationMechanism
- * @param md The metadata
- * @param authenticationmechanism The authentication mechanism
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData attachAuthenticationMechanism(ConnectorMetaData md,
- AuthenticationMechanism authenticationmechanism)
- throws Exception
- {
- if (md.getRa() == null)
- {
- md.setRa(new ResourceAdapterMetaData());
- }
- if (md.getRa().getOutboundRa() == null)
- {
- md.getRa().setOutboundRa(new OutboundRaMetaData());
- }
- if (md.getRa().getOutboundRa().getAuthMechanisms() == null)
- {
- md.getRa().getOutboundRa().setAuthMechanisms(new ArrayList<AuthenticationMechanismMetaData>());
- }
- AuthenticationMechanismMetaData ammd = new AuthenticationMechanismMetaData();
- ammd.setAuthenticationMechanismType(authenticationmechanism.authMechanism());
-
- String credentialInterfaceClass = null;
- if (authenticationmechanism.credentialInterface().equals(CredentialInterface.GenericCredential))
- {
- credentialInterfaceClass = "javax.resource.spi.security.GenericCredential";
- }
- else if (authenticationmechanism.credentialInterface().equals(CredentialInterface.GSSCredential))
- {
- credentialInterfaceClass = "org.ietf.jgss.GSSCredential";
- }
- else if (authenticationmechanism.credentialInterface().equals(CredentialInterface.PasswordCredential))
- {
- credentialInterfaceClass = "javax.resource.spi.security.PasswordCredential";
- }
- ammd.setCredentialInterfaceClass(credentialInterfaceClass);
-
- String[] description = authenticationmechanism.description();
- if (description != null)
- {
- if (ammd.getDescriptions() == null)
- {
- DescriptionsImpl descsImpl = new DescriptionsImpl();
- ammd.setDescriptions(descsImpl);
- }
- for (String desc : description)
- {
- DescriptionImpl descImpl = new DescriptionImpl();
- descImpl.setDescription(desc);
- ((DescriptionsImpl)ammd.getDescriptions()).add(descImpl);
- }
- }
-
- md.getRa().getOutboundRa().getAuthMechanisms().add(ammd);
-
- return md;
- }
-
- /**
- * Process: @AdministeredObject
- * @param md The metadata
- * @param annotationRepository The annotation repository
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData processAdministeredObject(ConnectorMetaData md,
- AnnotationRepository annotationRepository)
- throws Exception
- {
- Collection<Annotation> values = annotationRepository.getAnnotation(AdministeredObject.class);
- if (values != null)
- {
- for (Annotation annotation : values)
- {
- AdministeredObject a = (AdministeredObject)annotation.getAnnotation();
-
- if (trace)
- log.trace("Processing: " + a);
-
- md = attachAdministeredObject(md, a);
- }
- }
-
- return md;
- }
-
- /**
- * Attach @AdministeredObject
- * @param md The metadata
- * @param a The administered object
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData attachAdministeredObject(ConnectorMetaData md, AdministeredObject a)
- throws Exception
- {
- createAdminObject(md);
- String aoName = null;
- if (a.adminObjectInterfaces().length > 0)
- {
- aoName = ((Class)Array.get(a.adminObjectInterfaces(), 0)).getName();
- }
- AdminObjectMetaData aomd = new AdminObjectMetaData();
- aomd.setAdminObjectInterfaceClass(aoName);
- md.getRa().getAdminObjects().add(aomd);
- return md;
- }
-
- /**
- * Process: @Activation
- * @param md The metadata
- * @param annotationRepository The annotation repository
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData processActivation(ConnectorMetaData md,
- AnnotationRepository annotationRepository)
- throws Exception
- {
- Collection<Annotation> values = annotationRepository.getAnnotation(Activation.class);
- if (values != null)
- {
- for (Annotation annotation : values)
- {
- md = attachActivation(md, annotation);
- }
- }
-
- return md;
- }
-
- /**
- * Attach @Activation
- * @param md The metadata
- * @param activation The activation
- * @return The updated metadata
- * @exception Exception Thrown if an error occurs
- */
- private ConnectorMetaData attachActivation(ConnectorMetaData md, Annotation annotation)
- throws Exception
- {
- Activation activation = (Activation)annotation.getAnnotation();
-
- if (trace)
- log.trace("Processing: " + activation);
-
- createMessageListeners(md);
- for (Class asClass : activation.messageListeners())
- {
- ActivationspecMetaData asMeta = new ActivationspecMetaData();
- asMeta.setAsClass(annotation.getClassName());
- MessageListenerMetaData mlMeta = new MessageListenerMetaData();
- mlMeta.setActivationSpecType(asMeta);
- mlMeta.setType(asClass.getName());
- md.getRa().getInboundRa().getMessageAdapter().getMessageListeners().add(mlMeta);
- }
- return md;
- }
-
-
- /**
- * createMessageListeners
- * @param md
- * @throws Exception
- */
- private void createMessageListeners(ConnectorMetaData md) throws Exception
- {
- if (md.getRa() == null)
- {
- md.setRa(new ResourceAdapterMetaData());
- }
- if (md.getRa().getInboundRa() == null)
- {
- md.getRa().setInboundRa(new InboundRaMetaData());
- }
- if (md.getRa().getInboundRa().getMessageAdapter() == null)
- {
- md.getRa().getInboundRa().setMessageAdapter(new MessageAdapterMetaData());
- }
- if (md.getRa().getInboundRa().getMessageAdapter().getMessageListeners() == null)
- {
- md.getRa().getInboundRa().getMessageAdapter().setMessageListeners(new ArrayList<MessageListenerMetaData>());
- }
- }
-
- /**
- * createAdminObject
- * @param md
- * @throws Exception
- */
- private void createAdminObject(ConnectorMetaData md) throws Exception
- {
- if (md.getRa() == null)
- {
- md.setRa(new ResourceAdapterMetaData());
- }
- if (md.getRa().getAdminObjects() == null)
- {
- md.getRa().setAdminObjects(new ArrayList<AdminObjectMetaData>());
- }
- }
-
- /**
- * createConDefs
- * @param md
- * @throws Exception
- */
- private void createConDefs(ConnectorMetaData md) throws Exception
- {
- if (md.getRa() == null)
- {
- md.setRa(new ResourceAdapterMetaData());
- }
- if (md.getRa().getOutboundRa() == null)
- {
- md.getRa().setOutboundRa(new OutboundRaMetaData());
- }
- if (md.getRa().getOutboundRa().getConDefs() == null)
- {
- md.getRa().getOutboundRa().setConDefs(new ArrayList<ConnectionDefinitionMetaData>());
- }
- }
-
- /**
- * Get the config-property-name for an annotation
- * @param annotation The annotation
- * @return The name
- * @exception ClassNotFoundException Thrown if a class cannot be found
- * @exception NoSuchFieldException Thrown if a field cannot be found
- * @exception NoSuchMethodException Thrown if a method cannot be found
- */
- private String getConfigPropertyName(Annotation annotation)
- throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException
- {
- if (AnnotationType.FIELD.equals(annotation.getType()))
- {
- return annotation.getMemberName();
- }
- else if (AnnotationType.METHOD.equals(annotation.getType()))
- {
- String name = annotation.getMemberName();
-
- if (name.startsWith("set"))
- {
- name = name.substring(3);
- }
- else if (name.startsWith("get"))
- {
- name = name.substring(3);
- }
- else if (name.startsWith("is"))
- {
- name = name.substring(2);
- }
-
- if (name.length() > 1)
- {
- return Character.toLowerCase(name.charAt(0)) + name.substring(1);
- }
- else
- {
- return Character.toString(Character.toLowerCase(name.charAt(0)));
- }
- }
-
- throw new IllegalArgumentException("Unknown annotation: " + annotation);
- }
-
- /**
- * Get the config-property-type for an annotation
- * @param annotation The annotation
- * @return The fully qualified classname
- * @exception ClassNotFoundException Thrown if a class cannot be found
- */
- @SuppressWarnings("unchecked")
- private String getConfigPropertyType(Annotation annotation)
- throws ClassNotFoundException
- {
- if (AnnotationType.FIELD.equals(annotation.getType()))
- {
- ClassLoader cl = SecurityActions.getThreadContextClassLoader();
- Class clz = Class.forName(annotation.getClassName(), true, cl);
-
- while (!Object.class.equals(clz))
- {
- try
- {
- Field field = clz.getDeclaredField(annotation.getMemberName());
-
- return field.getType().getName();
- }
- catch (NoSuchFieldException nsfe)
- {
- clz = clz.getSuperclass();
- }
- }
- }
- else if (AnnotationType.METHOD.equals(annotation.getType()))
- {
- ClassLoader cl = SecurityActions.getThreadContextClassLoader();
- Class clz = Class.forName(annotation.getClassName(), true, cl);
-
- Class[] parameters = null;
-
- if (annotation.getParameterTypes() != null)
- {
- parameters = new Class[annotation.getParameterTypes().length];
-
- for (int i = 0; i < annotation.getParameterTypes().length; i++)
- {
- String parameter = annotation.getParameterTypes()[i];
- parameters[i] = Class.forName(parameter, true, cl);
- }
- }
-
- while (!Object.class.equals(clz))
- {
- try
- {
- Method method = clz.getDeclaredMethod(annotation.getMemberName(), parameters);
-
- if (void.class.equals(method.getReturnType()))
- {
- if (parameters != null && parameters.length > 0)
- {
- return parameters[0].getName();
- }
- }
- else
- {
- return method.getReturnType().getName();
- }
- }
- catch (NoSuchMethodException nsme)
- {
- clz = clz.getSuperclass();
- }
- }
- }
-
- throw new IllegalArgumentException("Unknown annotation: " + annotation);
- }
-}
Deleted: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Metadata.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Metadata.java 2010-02-20 06:08:46 UTC (rev 101199)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/Metadata.java 2010-02-20 09:41:46 UTC (rev 101200)
@@ -1,367 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.jca.deployers.fungal;
-
-import org.jboss.jca.fungal.deployers.DeployException;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.jboss.logging.Logger;
-import org.jboss.metadata.rar.jboss.JBossRA10MetaData;
-import org.jboss.metadata.rar.jboss.JBossRA20DefaultNSMetaData;
-import org.jboss.metadata.rar.jboss.JBossRA20MetaData;
-import org.jboss.metadata.rar.jboss.JBossRAMetaData;
-import org.jboss.metadata.rar.jboss.RaConfigPropertyMetaData;
-import org.jboss.metadata.rar.spec.ConfigPropertyMetaData;
-import org.jboss.metadata.rar.spec.ConnectionDefinitionMetaData;
-import org.jboss.metadata.rar.spec.ConnectorMetaData;
-import org.jboss.metadata.rar.spec.InboundRaMetaData;
-import org.jboss.metadata.rar.spec.JCA10DTDMetaData;
-import org.jboss.metadata.rar.spec.JCA15DTDMetaData;
-import org.jboss.metadata.rar.spec.JCA15MetaData;
-import org.jboss.metadata.rar.spec.JCA16DTDMetaData;
-import org.jboss.metadata.rar.spec.JCA16DefaultNSMetaData;
-import org.jboss.metadata.rar.spec.JCA16MetaData;
-import org.jboss.metadata.rar.spec.MessageListenerMetaData;
-import org.jboss.metadata.rar.spec.OutboundRaMetaData;
-import org.jboss.metadata.rar.spec.RA10MetaData;
-import org.jboss.xb.binding.Unmarshaller;
-import org.jboss.xb.binding.UnmarshallerFactory;
-import org.jboss.xb.binding.resolver.MutableSchemaResolver;
-import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
-
-/**
- * The metadata processor for JCA 1.x
- * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
- * @author <a href="mailto:jeff.zhang at redhat.com">Jeff Zhang</a>
- */
-public class Metadata
-{
- private static Logger log = Logger.getLogger(Metadata.class);
- private static boolean trace = log.isTraceEnabled();
-
- /**
- * Constructor
- */
- public Metadata()
- {
- }
-
- /**
- * Get the JCA standard metadata
- * @param root The root of the deployment
- * @return The metadata
- * @exception Exception Thrown if an error occurs
- */
- public ConnectorMetaData getStandardMetaData(File root) throws Exception
- {
- ConnectorMetaData result = null;
-
- UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
- Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
-
- MutableSchemaResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
- resolver.mapLocationToClass("connector_1_6.xsd", JCA16MetaData.class);
- resolver.mapLocationToClass("connector_1_5.xsd", JCA15MetaData.class);
- resolver.mapLocationToClass("connector_1_5.dtd", JCA15DTDMetaData.class);
- resolver.mapLocationToClass("connector_1_6.dtd", JCA16DTDMetaData.class);
- resolver.mapLocationToClass("connector_1_0.dtd", JCA10DTDMetaData.class);
- resolver.mapLocationToClass("connector", JCA16DefaultNSMetaData.class);
-
- File metadataFile = new File(root, "/META-INF/ra.xml");
-
- if (metadataFile.exists())
- {
- String url = metadataFile.getAbsolutePath();
- try
- {
- long start = System.currentTimeMillis();
-
- result = (ConnectorMetaData)unmarshaller.unmarshal(url, resolver);
-
- log.debug("Total parse for " + url + " took " + (System.currentTimeMillis() - start) + "ms");
-
- if (trace)
- {
- log.trace("successful parse " + result.getVersion() + " rar package " + result);
- }
-
- }
- catch (Exception e)
- {
- log.error("Error during parsing: " + url, e);
- throw e;
- }
- }
-
- return result;
- }
-
- /**
- * Get the JBoss specific metadata
- * @param root The root of the deployment
- * @return The metadata
- * @exception Exception Thrown if an error occurs
- */
- public JBossRAMetaData getJBossMetaData(File root) throws Exception
- {
- JBossRAMetaData result = null;
-
- UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
- Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
-
- MutableSchemaResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
- resolver.mapLocationToClass("http://www.jboss.org/schema/jboss-ra_1_0.xsd", JBossRA10MetaData.class);
- resolver.mapLocationToClass("http://www.jboss.org/schema/jboss-ra_2_0.xsd", JBossRA20MetaData.class);
- resolver.mapLocationToClass("jboss-ra", JBossRA20DefaultNSMetaData.class);
-
- File metadataFile = new File(root, "/META-INF/jboss-ra.xml");
-
- if (metadataFile.exists())
- {
- String url = metadataFile.getAbsolutePath();
- try
- {
- long start = System.currentTimeMillis();
-
- result = (JBossRAMetaData)unmarshaller.unmarshal(url, resolver);
-
- log.debug("Total parse for " + url + " took " + (System.currentTimeMillis() - start) + "ms");
-
- if (trace)
- log.trace(result);
- }
- catch (Exception e)
- {
- log.error("Error during parsing: " + url, e);
- throw e;
- }
- }
-
- return result;
- }
-
- /**
- * Merge specification metadata with vendor metadata
- * @param cmd The specification metadata
- * @param jmd The vendor metadata
- * @return The merged metadata
- * @exception Exception Thrown if an error occurs
- */
- public ConnectorMetaData merge(ConnectorMetaData cmd, JBossRAMetaData jmd) throws Exception
- {
- if (cmd != null && jmd != null)
- {
- /*
- <xs:restriction base="javaee:string">
- <xs:enumeration value="connection-definition"/>
- <xs:enumeration value="resourceadapter"/>
- <xs:enumeration value="activationspec"/>
- <xs:enumeration value="adminobject"/>
- </xs:restriction>
- */
-
- List<RaConfigPropertyMetaData> props = jmd.getRaConfigProps();
-
- List<ConfigPropertyMetaData> append = null;
-
- if (props != null)
- {
- for (RaConfigPropertyMetaData rcmd : props)
- {
- List<ConfigPropertyMetaData> listConfigProp = null;
- String override = rcmd.getOverride();
- if (override == null || override.equals("resourceadapter"))
- {
- if (cmd.getRa() != null)
- {
- listConfigProp = cmd.getRa().getConfigProperty();
- }
- }
- else if (override.equals("connection-definition"))
- {
- if (cmd.getRa() != null &&
- cmd.getRa().getOutboundRa() != null &&
- cmd.getRa().getOutboundRa().getConDefs() != null &&
- cmd.getRa().getOutboundRa().getConDefs().size() > 0 &&
- cmd.getRa().getOutboundRa().getConDefs().get(0) != null)
- {
- listConfigProp = cmd.getRa().getOutboundRa().getConDefs().get(0).getConfigProps();
- }
- }
- else if (override.equals("activationspec"))
- {
- if (cmd.getRa() != null &&
- cmd.getRa().getInboundRa() != null &&
- cmd.getRa().getInboundRa().getMessageAdapter() != null &&
- cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners() != null &&
- cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners().size() > 0 &&
- cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners().get(0) != null &&
- cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners().get(0).
- getActivationSpecType() != null)
- {
- listConfigProp = cmd.getRa().getInboundRa().getMessageAdapter().getMessageListeners().
- get(0).getActivationSpecType().getConfigProps();
- }
- }
- else if (override.equals("adminobject"))
- {
- if (cmd.getRa() != null &&
- cmd.getRa().getAdminObjects() != null &&
- cmd.getRa().getAdminObjects().size() > 0 &&
- cmd.getRa().getAdminObjects().get(0) != null)
- {
- listConfigProp = cmd.getRa().getAdminObjects().get(0).getConfigProps();
- }
- }
-
- boolean found = false;
-
- if (listConfigProp != null)
- {
- Iterator<ConfigPropertyMetaData> it = listConfigProp.iterator();
-
- while (!found && it.hasNext())
- {
- ConfigPropertyMetaData cpmd = it.next();
- if (cpmd.getName().equals(rcmd.getName()) &&
- cpmd.getType().equals(rcmd.getType()))
- {
- cpmd.setValue(rcmd.getValue());
- found = true;
- }
- }
- }
-
- if (!found)
- {
- if (append == null)
- append = new ArrayList<ConfigPropertyMetaData>();
-
- ConfigPropertyMetaData cpmd = new ConfigPropertyMetaData();
- cpmd.setName(rcmd.getName());
- cpmd.setType(rcmd.getType());
- cpmd.setValue(rcmd.getValue());
-
- append.add(cpmd);
- }
- }
-
- if (append != null)
- {
- if (cmd.getRa().getConfigProperty() == null)
- cmd.getRa().setConfigProperty(new ArrayList<ConfigPropertyMetaData>());
-
- for (ConfigPropertyMetaData cpmd : append)
- {
- cmd.getRa().getConfigProperty().add(cpmd);
- }
- }
- }
- }
-
- return cmd;
- }
-
- /**
- * Validate specification metadata
- * @param cmd The specification metadata
- * @return The merged metadata
- * @exception Exception Thrown if an error occurs
- */
- public ConnectorMetaData validate(ConnectorMetaData cmd) throws Exception
- {
- if (cmd.is10())
- {
- RA10MetaData ra10 = ((JCA10DTDMetaData)cmd).getRa10();
- if (ra10 == null
- || ra10.getManagedConnectionFactoryClass() == null
- || ra10.getManagedConnectionFactoryClass().equals(""))
- {
- throw new DeployException("ManagedConnectionFactoryClass should be defined");
- }
- return cmd;
- }
- //make sure all need metadata parsered and processed after annotation handle
- if (cmd.getRa() == null)
- throw new DeployException("ResourceAdapter metadata should be defined");
-
- //make sure ra metadata contains inbound or outbound at least
- boolean inboundOrOutbound = false;
- if (validateOutbound(cmd.getRa().getOutboundRa()))
- inboundOrOutbound = true;
- if (validateInbound(cmd.getRa().getInboundRa()) && cmd.getRa().getRaClass() != null)
- inboundOrOutbound = true;
- if (!inboundOrOutbound)
- throw new DeployException("ResourceAdapter metadata should contains inbound or outbound at least");
- return cmd;
- }
-
- /**
- * Validate outbound metadata
- * @param omd The specification metadata
- * @return validate
- * @exception Exception Thrown if an error occurs
- */
- private boolean validateOutbound(OutboundRaMetaData omd) throws Exception
- {
- if (omd == null)
- return false;
- if (omd.getConDefs() == null || omd.getConDefs().size() == 0)
- return false;
- ConnectionDefinitionMetaData cdm = omd.getConDefs().get(0);
- if (cdm.getManagedConnectionFactoryClass() == null ||
- cdm.getConnectionFactoryInterfaceClass() == null ||
- cdm.getConnectionFactoryImplementationClass() == null ||
- cdm.getConnectionInterfaceClass() == null ||
- cdm.getConnectionImplementationClass() == null)
- return false;
-
- return true;
- }
-
- /**
- * Validate inbound metadata
- * @param cmd The specification metadata
- * @return validate
- * @exception Exception Thrown if an error occurs
- */
- private boolean validateInbound(InboundRaMetaData imd) throws Exception
- {
- if (imd == null)
- return false;
- if (imd.getMessageAdapter() == null ||
- imd.getMessageAdapter().getMessageListeners() == null ||
- imd.getMessageAdapter().getMessageListeners().size() == 0)
- return false;
- MessageListenerMetaData mlmd = imd.getMessageAdapter().getMessageListeners().get(0);
- if (mlmd.getType() == null ||
- mlmd.getActivationSpecType() == null ||
- mlmd.getActivationSpecType().getAsClass() == null)
- return false;
- return true;
- }
-}
Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java 2010-02-20 06:08:46 UTC (rev 101199)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java 2010-02-20 09:41:46 UTC (rev 101200)
@@ -28,6 +28,8 @@
import org.jboss.jca.core.connectionmanager.notx.NoTxConnectionManager;
import org.jboss.jca.core.connectionmanager.pool.PoolParams;
import org.jboss.jca.core.connectionmanager.pool.strategy.OnePool;
+import org.jboss.jca.deployers.common.Annotations;
+import org.jboss.jca.deployers.common.Metadata;
import org.jboss.jca.deployers.common.validator.Failure;
import org.jboss.jca.deployers.common.validator.FailureHelper;
import org.jboss.jca.deployers.common.validator.Key;
@@ -76,13 +78,7 @@
import org.jboss.metadata.rar.spec.ConfigPropertyMetaData;
import org.jboss.metadata.rar.spec.ConnectionDefinitionMetaData;
import org.jboss.metadata.rar.spec.ConnectorMetaData;
-import org.jboss.metadata.rar.spec.JCA16DTDMetaData;
-import org.jboss.metadata.rar.spec.JCA16DefaultNSMetaData;
-import org.jboss.metadata.rar.spec.JCA16MetaData;
import org.jboss.metadata.rar.spec.MessageListenerMetaData;
-import org.jboss.papaki.AnnotationRepository;
-import org.jboss.papaki.AnnotationScanner;
-import org.jboss.papaki.AnnotationScannerFactory;
import org.jboss.util.naming.Util;
/**
@@ -275,42 +271,10 @@
Metadata metadataHandler = new Metadata();
ConnectorMetaData cmd = metadataHandler.getStandardMetaData(root);
JBossRAMetaData jrmd = metadataHandler.getJBossMetaData(root);
- boolean isMetadataComplete = true;
- // Process annotations
- if (cmd == null || cmd.is16())
- {
- AnnotationScanner annotationScanner =
- AnnotationScannerFactory.getStrategy(AnnotationScannerFactory.JAVASSIST_INPUT_STREAM);
- annotationScanner.configure().constructorLevel(false).parameterLevel(false);
- AnnotationRepository annotationRepository = annotationScanner.scan(cl.getURLs(), cl);
-
- isMetadataComplete = false;
- if (cmd != null)
- {
- if (cmd instanceof JCA16MetaData)
- {
- JCA16MetaData jmd = (JCA16MetaData)cmd;
- isMetadataComplete = jmd.isMetadataComplete();
- }
- else if (cmd instanceof JCA16DefaultNSMetaData)
- {
- JCA16DefaultNSMetaData jmd = (JCA16DefaultNSMetaData)cmd;
- isMetadataComplete = jmd.isMetadataComplete();
- }
- else if (cmd instanceof JCA16DTDMetaData)
- {
- JCA16DTDMetaData jmd = (JCA16DTDMetaData)cmd;
- isMetadataComplete = jmd.isMetadataComplete();
- }
- }
-
- if (cmd == null || !isMetadataComplete)
- {
- Annotations annotator = new Annotations();
- cmd = annotator.process(cmd, annotationRepository);
- }
- }
+ // Annotation scanning
+ Annotations annotator = new Annotations();
+ cmd = annotator.scan(cmd, cl.getURLs(), cl);
// Validate metadata
metadataHandler.validate(cmd);
Added: projects/jboss-jca/trunk/deployers/src/main/resources/validator-manifest.mf
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/resources/validator-manifest.mf (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/resources/validator-manifest.mf 2010-02-20 09:41:46 UTC (rev 101200)
@@ -0,0 +1,6 @@
+Implementation-Title: JBoss JCA Validator
+Implementation-Vendor: Red Hat Middleware LLC
+Implementation-Vendor-Id: org.jboss
+Implementation-Version: 0.1
+Main-Class: org.jboss.jca.deployers.common.validator.Main
+Class-Path: jbossxb.jar jboss-logging-spi.jar jboss-common-core.jar jboss-metadata-rar.jar jboss-metadata-common.jar jboss-reflect.jar jboss-mdr.jar jboss-jca-spec-api.jar papaki-core.jar javassist.jar
Modified: projects/jboss-jca/trunk/deployers/src/main/resources/validator.properties
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/resources/validator.properties 2010-02-20 06:08:46 UTC (rev 101199)
+++ projects/jboss-jca/trunk/deployers/src/main/resources/validator.properties 2010-02-20 09:41:46 UTC (rev 101200)
@@ -4,12 +4,15 @@
section=Section
description=Description
code=Code
+uncategorized=Uncategorized
+mcf.cnfe=ClassNotFoundException during ManagedConnectionFactory creation
mcf.MCF=The class must implement the javax.resource.spi.ManagedConnectionFactory interface.
mcf.MCFHashCode=A ManagedConnectionFactory must implement a "public int hashCode()" method.
mcf.MCFEquals=A ManagedConnectionFactory must implement a "public boolean equals(Object)" method.
mcf.MCFConfigProperties=Invalid config-property-type for ManagedConnectionFactory.
mc.MC=The class must provide an implementation of the ManagedConnection interface.
mc.MCGetMetaData=ManagedConnection.getMetaData() must return a javax.resource.spi.ManagedConnectionMetaData instance
+ra.cnfe=ClassNotFoundException during ResourceAdapter creation
ra.RA=A ResourceAdapter must implement the javax.resource.spi.ResourceAdapter interface.
ra.RANull=A ResourceAdapter must be a non-null instance.
ra.RAHashCode=A ResourceAdapter must implement a "public int hashCode()" method.
@@ -18,5 +21,7 @@
cf.CFNull=ConnectionFactory must be a non-null value
cf.CFSerializable=ConnectionFactory must implement java.io.Serializable
cf.CFReferenceable=ConnectionFactory must implement javax.resource.Referenceable
+as.cnfe=ClassNotFoundException during ActivationSpec creation
as.ASConfigProperties=Invalid config-property-type for ActivationSpec.
+ao.cnfe=ClassNotFoundException during AdminObject creation
ao.AOConfigProperties=Invalid config-property-type for AdminObject.
Added: projects/jboss-jca/trunk/deployers/src/main/resources/validator.sh
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/resources/validator.sh (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/resources/validator.sh 2010-02-20 09:41:46 UTC (rev 101200)
@@ -0,0 +1,3 @@
+#!/bin/sh
+java -jar jboss-jca-validator.jar $*
+
Modified: projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java 2010-02-20 06:08:46 UTC (rev 101199)
+++ projects/jboss-jca/trunk/deployers/src/test/java/org/jboss/jca/test/deployers/annotations/AnnotationsTestCase.java 2010-02-20 09:41:46 UTC (rev 101200)
@@ -22,7 +22,7 @@
package org.jboss.jca.test.deployers.annotations;
-import org.jboss.jca.deployers.fungal.Annotations;
+import org.jboss.jca.deployers.common.Annotations;
import org.jboss.jca.embedded.EmbeddedJCA;
import org.jboss.jca.fungal.deployers.DeployException;
More information about the jboss-cvs-commits
mailing list