text
stringlengths
30
1.67M
<s> package com . datastax . tutorial ; import me . prettyprint . hector . api . Keyspace ; import me . prettyprint . hector . api . beans . ColumnSlice ; import me . prettyprint . hector . api . factory . HFactory ; import me . prettyprint . hector . api . query . QueryResult ; import me . prettyprint . hector . api . query . SliceQuery ; public class GetSliceForAreaCodeCity extends TutorialCommand { public GetSliceForAreaCodeCity ( Keyspace keyspace ) { super ( keyspace ) ; } @ Override public QueryResult < ColumnSlice < String , String > > execute ( ) { SliceQuery < String , String , String > sliceQuery = HFactory . createSliceQuery ( keyspace , stringSerializer , stringSerializer , stringSerializer ) ; sliceQuery . setColumnFamily ( "<STR_LIT>" ) ; sliceQuery . setKey ( "<STR_LIT>" ) ; sliceQuery . setRange ( "<STR_LIT>" , "<STR_LIT>" , false , <NUM_LIT:5> ) ; QueryResult < ColumnSlice < String , String > > result = sliceQuery . execute ( ) ; return result ; } } </s>
<s> package com . datastax . tutorial ; import me . prettyprint . hector . api . Keyspace ; import me . prettyprint . hector . api . beans . ColumnSlice ; import me . prettyprint . hector . api . factory . HFactory ; import me . prettyprint . hector . api . query . QueryResult ; import me . prettyprint . hector . api . query . SliceQuery ; public class GetSliceForStateCity extends TutorialCommand { public GetSliceForStateCity ( Keyspace keyspace ) { super ( keyspace ) ; } @ Override public QueryResult < ColumnSlice < Long , String > > execute ( ) { SliceQuery < String , Long , String > sliceQuery = HFactory . createSliceQuery ( keyspace , stringSerializer , longSerializer , stringSerializer ) ; sliceQuery . setColumnFamily ( "<STR_LIT>" ) ; sliceQuery . setKey ( "<STR_LIT>" ) ; sliceQuery . setRange ( <NUM_LIT> , <NUM_LIT> , false , <NUM_LIT:5> ) ; QueryResult < ColumnSlice < Long , String > > result = sliceQuery . execute ( ) ; return result ; } } </s>
<s> package com . datastax . tutorial ; import junit . framework . Test ; import junit . framework . TestCase ; import junit . framework . TestSuite ; public class AppTest extends TestCase { public AppTest ( String testName ) { super ( testName ) ; } public static Test suite ( ) { return new TestSuite ( AppTest . class ) ; } public void testApp ( ) { assertTrue ( true ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . util ; import com . lowagie . text . pdf . codec . Base64 ; import net . sf . jasperreports . engine . JRExporterParameter ; import br . com . caelum . vraptor . ioc . Component ; import br . com . caelum . vraptor . jasperreports . Report ; import br . com . caelum . vraptor . jasperreports . ReportFormatResolver ; import br . com . caelum . vraptor . jasperreports . exporter . ReportExporter ; import br . com . caelum . vraptor . jasperreports . formats . ExportFormat ; @ Component public class DefaultReportDataURIBuilder implements ReportDataURIBuilder { private final ReportExporter exporter ; private final ReportFormatResolver resolver ; public DefaultReportDataURIBuilder ( ReportExporter exporter , ReportFormatResolver resolver ) { this . exporter = exporter ; this . resolver = resolver ; } public String build ( Report report , ExportFormat format ) { String charset = extractCharset ( format ) . toLowerCase ( ) ; byte [ ] content = exporter . export ( report ) . to ( format ) ; StringBuilder URI = new StringBuilder ( "<STR_LIT>" ) ; URI . append ( format . getContentType ( ) ) ; URI . append ( "<STR_LIT>" ) . append ( charset ) ; URI . append ( "<STR_LIT>" ) . append ( Base64 . encodeBytes ( content ) ) ; return URI . toString ( ) ; } public String build ( Report report ) { return build ( report , resolver . getExportFormat ( ) ) ; } private String extractCharset ( ExportFormat format ) { return ( String ) format . getParameters ( ) . get ( JRExporterParameter . CHARACTER_ENCODING ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . util ; import br . com . caelum . vraptor . jasperreports . Report ; import br . com . caelum . vraptor . jasperreports . formats . ExportFormat ; public interface ReportDataURIBuilder { String build ( Report report , ExportFormat format ) ; String build ( Report report ) ; } </s>
<s> package br . com . caelum . vraptor . jasperreports ; import java . util . HashMap ; import java . util . Map ; import net . sf . jasperreports . engine . JasperReport ; import br . com . caelum . vraptor . ioc . ApplicationScoped ; import br . com . caelum . vraptor . ioc . Component ; @ Component @ ApplicationScoped public class ReportCache { private Map < String , JasperReport > cache = new HashMap < String , JasperReport > ( ) ; public JasperReport get ( String template ) { return cache . get ( template ) ; } public void put ( String template , JasperReport report ) { cache . put ( template , report ) ; } public boolean contains ( String template ) { return cache . containsKey ( template ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . download ; import java . io . IOException ; import javax . servlet . http . HttpServletResponse ; import br . com . caelum . vraptor . interceptor . download . ByteArrayDownload ; import br . com . caelum . vraptor . interceptor . download . Download ; import br . com . caelum . vraptor . jasperreports . Report ; import br . com . caelum . vraptor . jasperreports . exporter . ReportExporter ; import br . com . caelum . vraptor . jasperreports . formats . ExportFormat ; public class ReportDownload implements Download { private ReportExporter exporter ; private final Report report ; private final ExportFormat format ; private final boolean doDownload ; public ReportDownload ( Report report , ExportFormat format , boolean doDownload ) { this . report = report ; this . format = format ; this . doDownload = doDownload ; } public ReportDownload ( Report report , ExportFormat format ) { this ( report , format , true ) ; } public void setExporter ( ReportExporter exporter ) { this . exporter = exporter ; } public void write ( HttpServletResponse response ) throws IOException { new ByteArrayDownload ( getContent ( ) , getContentType ( ) , getFileName ( ) , doDownload ) . write ( response ) ; } private byte [ ] getContent ( ) { return exporter . export ( report ) . to ( format ) ; } public byte [ ] getContent ( ReportExporter exporter ) { return exporter . export ( report ) . to ( format ) ; } public String getContentType ( ) { return format . getContentType ( ) ; } public String getFileName ( ) { return report . getFileName ( ) + "<STR_LIT:.>" + format . getExtension ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . download ; import java . util . Collection ; import br . com . caelum . vraptor . jasperreports . Report ; import br . com . caelum . vraptor . jasperreports . exporter . ReportExporter ; import br . com . caelum . vraptor . jasperreports . formats . ExportFormat ; import com . google . common . collect . Lists ; public class ReportItem { private final Collection < Report > reports = Lists . newArrayList ( ) ; private final ExportFormat format ; private final String filename ; public ReportItem ( Report report , ExportFormat format ) { this . reports . add ( report ) ; this . format = format ; this . filename = report . getFileName ( ) + "<STR_LIT:.>" + format . getExtension ( ) ; } public ReportItem ( String filename , Collection < Report > reports , ExportFormat format ) { this . reports . addAll ( reports ) ; this . format = format ; this . filename = filename + "<STR_LIT:.>" + format . getExtension ( ) ; } public Collection < Report > getReports ( ) { return reports ; } public byte [ ] getContent ( ReportExporter exporter ) { return exporter . export ( reports ) . to ( format ) ; } public ExportFormat getFormat ( ) { return format ; } public String getFilename ( ) { return filename ; } public String getContentType ( ) { return format . getContentType ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . download ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; import java . util . Collection ; import java . util . List ; import java . util . zip . ZipEntry ; import java . util . zip . ZipOutputStream ; import br . com . caelum . vraptor . jasperreports . Report ; import br . com . caelum . vraptor . jasperreports . exporter . ReportExporter ; import br . com . caelum . vraptor . jasperreports . formats . ExportFormat ; import com . google . common . collect . Lists ; import com . google . common . io . Closeables ; import com . google . common . io . Flushables ; public class ReportZipFile { private ByteArrayOutputStream output = new ByteArrayOutputStream ( ) ; private ZipOutputStream zip = new ZipOutputStream ( output ) ; private List < ReportItem > items = Lists . newArrayList ( ) ; private String filename ; public ReportZipFile ( String filename ) { this . filename = filename ; } public ReportZipFile add ( Report report , ExportFormat format ) { this . items . add ( new ReportItem ( report , format ) ) ; return this ; } public ReportZipFile add ( String filename , Collection < Report > reports , ExportFormat format ) { this . items . add ( new ReportItem ( filename , reports , format ) ) ; return this ; } public ReportZipFile add ( Collection < Report > reports , ExportFormat format ) { return add ( "<STR_LIT>" , reports , format ) ; } public ReportZipFile addAll ( Collection < ReportItem > entries ) { this . items . addAll ( entries ) ; return this ; } public byte [ ] getContent ( ReportExporter exporter ) { for ( ReportItem item : items ) { write ( item . getFilename ( ) , item . getContent ( exporter ) ) ; } Flushables . flushQuietly ( zip ) ; Closeables . closeQuietly ( zip ) ; return output . toByteArray ( ) ; } public String getContentType ( ) { return "<STR_LIT>" ; } public String getName ( ) { return filename ; } public void setName ( String filename ) { this . filename = filename ; } private void write ( String name , byte [ ] content ) { try { ZipEntry entry = new ZipEntry ( name ) ; entry . setSize ( content . length ) ; entry . setMethod ( ZipEntry . DEFLATED ) ; zip . putNextEntry ( entry ) ; zip . write ( content ) ; zip . closeEntry ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } } </s>
<s> package br . com . caelum . vraptor . jasperreports . download ; import java . io . IOException ; import java . util . List ; import javax . servlet . http . HttpServletResponse ; import br . com . caelum . vraptor . interceptor . download . ByteArrayDownload ; import br . com . caelum . vraptor . interceptor . download . Download ; import br . com . caelum . vraptor . jasperreports . Report ; import br . com . caelum . vraptor . jasperreports . exporter . ReportExporter ; import br . com . caelum . vraptor . jasperreports . formats . ExportFormat ; public class ReportsDownload implements Download { private ReportExporter exporter ; private ReportZipFile file ; public ReportsDownload ( ) { this ( "<STR_LIT>" ) ; } public ReportsDownload ( String filename ) { this . file = new ReportZipFile ( filename ) ; } public void setExporter ( ReportExporter exporter ) { this . exporter = exporter ; } public ReportsDownload add ( Report report , ExportFormat format ) { this . file . add ( report , format ) ; return this ; } public ReportsDownload add ( String filename , List < Report > reports , ExportFormat format ) { this . file . add ( filename , reports , format ) ; return this ; } public void write ( HttpServletResponse response ) throws IOException { new ByteArrayDownload ( getContent ( ) , file . getContentType ( ) , file . getName ( ) , true ) . write ( response ) ; } private byte [ ] getContent ( ) { return file . getContent ( exporter ) ; } public byte [ ] getContent ( ReportExporter exporter ) { return file . getContent ( exporter ) ; } public String getContentType ( ) { return file . getContentType ( ) ; } public String getFileName ( ) { return file . getName ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . download ; import java . io . IOException ; import java . util . List ; import javax . servlet . http . HttpServletResponse ; import br . com . caelum . vraptor . interceptor . download . ByteArrayDownload ; import br . com . caelum . vraptor . interceptor . download . Download ; import br . com . caelum . vraptor . jasperreports . Report ; import br . com . caelum . vraptor . jasperreports . exporter . ReportExporter ; import br . com . caelum . vraptor . jasperreports . formats . ExportFormat ; import com . google . common . collect . Lists ; public class BatchReportsDownload implements Download { private ReportExporter exporter ; private List < Report > reports = Lists . newArrayList ( ) ; private final ExportFormat format ; private final boolean doDownload ; private String filename ; public BatchReportsDownload ( ExportFormat format , String filename , boolean doDownload ) { if ( ! format . supportsBatchMode ( ) ) throw new IllegalArgumentException ( "<STR_LIT>" ) ; this . format = format ; this . filename = filename ; this . doDownload = doDownload ; } public BatchReportsDownload ( ExportFormat format ) { this ( format , "<STR_LIT>" , true ) ; } public void setExporter ( ReportExporter exporter ) { this . exporter = exporter ; } public BatchReportsDownload add ( List < Report > reports ) { reports . addAll ( reports ) ; return this ; } public BatchReportsDownload add ( Report ... reports ) { for ( Report report : reports ) { this . reports . add ( report ) ; } return this ; } public void write ( HttpServletResponse response ) throws IOException { new ByteArrayDownload ( getContent ( ) , getContentType ( ) , getFileName ( ) , doDownload ) . write ( response ) ; } private byte [ ] getContent ( ) { return exporter . export ( reports ) . to ( format ) ; } public byte [ ] getContent ( ReportExporter exporter ) { return exporter . export ( reports ) . to ( format ) ; } public String getContentType ( ) { return format . getContentType ( ) ; } public String getFileName ( ) { return filename + "<STR_LIT:.>" + format . getExtension ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . download ; import java . io . IOException ; import java . io . OutputStream ; import javax . servlet . http . HttpServletResponse ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import br . com . caelum . vraptor . InterceptionException ; import br . com . caelum . vraptor . Intercepts ; import br . com . caelum . vraptor . Lazy ; import br . com . caelum . vraptor . Result ; import br . com . caelum . vraptor . core . InterceptorStack ; import br . com . caelum . vraptor . core . MethodInfo ; import br . com . caelum . vraptor . interceptor . ExecuteMethodInterceptor ; import br . com . caelum . vraptor . interceptor . ForwardToDefaultViewInterceptor ; import br . com . caelum . vraptor . interceptor . Interceptor ; import br . com . caelum . vraptor . jasperreports . Report ; import br . com . caelum . vraptor . jasperreports . ReportFormatResolver ; import br . com . caelum . vraptor . jasperreports . exporter . ReportExporter ; import br . com . caelum . vraptor . resource . ResourceMethod ; @ Intercepts ( after = ExecuteMethodInterceptor . class , before = ForwardToDefaultViewInterceptor . class ) @ Lazy public class ReportDownloadInterceptor implements Interceptor { private final ReportExporter exporter ; private final HttpServletResponse response ; private final ReportFormatResolver resolver ; private final MethodInfo methodInfo ; private final Result result ; private final Logger logger = LoggerFactory . getLogger ( getClass ( ) ) ; public ReportDownloadInterceptor ( ReportExporter exporter , HttpServletResponse response , ReportFormatResolver resolver , MethodInfo methodInfo , Result result ) { this . exporter = exporter ; this . response = response ; this . resolver = resolver ; this . methodInfo = methodInfo ; this . result = result ; } public boolean accepts ( ResourceMethod method ) { return Report . class . isAssignableFrom ( method . getMethod ( ) . getReturnType ( ) ) ; } public void intercept ( InterceptorStack stack , ResourceMethod method , Object instance ) throws InterceptionException { Report report = ( Report ) methodInfo . getResult ( ) ; if ( report == null ) { if ( result . used ( ) ) { stack . next ( method , instance ) ; return ; } else throw new NullPointerException ( "<STR_LIT>" ) ; } ReportDownload download = new ReportDownload ( report , resolver . getExportFormat ( ) , resolver . doDownload ( ) ) ; download . setExporter ( exporter ) ; logger . debug ( "<STR_LIT>" , exporter . getClass ( ) . getName ( ) , download . getClass ( ) . getName ( ) ) ; try { OutputStream output = response . getOutputStream ( ) ; download . write ( response ) ; output . flush ( ) ; output . close ( ) ; } catch ( IOException e ) { throw new InterceptionException ( e ) ; } } } </s>
<s> package br . com . caelum . vraptor . jasperreports ; import java . util . Collection ; import java . util . Map ; public interface Report { String getTemplate ( ) ; Map < String , Object > getParameters ( ) ; Collection getData ( ) ; String getFileName ( ) ; Report addParameter ( String parameter , Object value ) ; boolean isCacheable ( ) ; } </s>
<s> package br . com . caelum . vraptor . jasperreports . exporter ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import br . com . caelum . vraptor . InterceptionException ; import br . com . caelum . vraptor . Intercepts ; import br . com . caelum . vraptor . Lazy ; import br . com . caelum . vraptor . core . InterceptorStack ; import br . com . caelum . vraptor . core . MethodInfo ; import br . com . caelum . vraptor . interceptor . ExecuteMethodInterceptor ; import br . com . caelum . vraptor . interceptor . Interceptor ; import br . com . caelum . vraptor . interceptor . download . Download ; import br . com . caelum . vraptor . interceptor . download . DownloadInterceptor ; import br . com . caelum . vraptor . jasperreports . download . BatchReportsDownload ; import br . com . caelum . vraptor . jasperreports . download . ReportDownload ; import br . com . caelum . vraptor . jasperreports . download . ReportsDownload ; import br . com . caelum . vraptor . resource . ResourceMethod ; @ Intercepts ( after = ExecuteMethodInterceptor . class , before = DownloadInterceptor . class ) @ Lazy public class ExporterInjector implements Interceptor { private final ReportExporter exporter ; private final MethodInfo methodInfo ; private final Logger logger = LoggerFactory . getLogger ( getClass ( ) ) ; public ExporterInjector ( ReportExporter exporter , MethodInfo methodInfo ) { this . exporter = exporter ; this . methodInfo = methodInfo ; } public boolean accepts ( ResourceMethod method ) { Class < ? > type = method . getMethod ( ) . getReturnType ( ) ; return Download . class . isAssignableFrom ( type ) || type == ReportDownload . class || type == ReportsDownload . class || type == BatchReportsDownload . class ; } public void intercept ( InterceptorStack stack , ResourceMethod method , Object instance ) throws InterceptionException { Object result = methodInfo . getResult ( ) ; if ( result instanceof ReportDownload ) { ReportDownload download = ( ReportDownload ) result ; download . setExporter ( exporter ) ; } if ( result instanceof ReportsDownload ) { ReportsDownload download = ( ReportsDownload ) result ; download . setExporter ( exporter ) ; } if ( result instanceof BatchReportsDownload ) { BatchReportsDownload download = ( BatchReportsDownload ) result ; download . setExporter ( exporter ) ; } logger . debug ( "<STR_LIT>" , exporter . getClass ( ) . getName ( ) , result . getClass ( ) . getName ( ) ) ; stack . next ( method , instance ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . exporter ; import java . util . ArrayList ; import java . util . Collection ; import java . util . List ; import java . util . Map ; import javax . servlet . http . HttpSession ; import net . sf . jasperreports . engine . JRException ; import net . sf . jasperreports . engine . JasperFillManager ; import net . sf . jasperreports . engine . JasperPrint ; import net . sf . jasperreports . engine . JasperReport ; import net . sf . jasperreports . engine . data . JRBeanCollectionDataSource ; import net . sf . jasperreports . j2ee . servlets . ImageServlet ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import br . com . caelum . vraptor . ioc . Component ; import br . com . caelum . vraptor . jasperreports . Report ; import br . com . caelum . vraptor . jasperreports . ReportLoader ; import br . com . caelum . vraptor . jasperreports . decorator . ReportDecorator ; import br . com . caelum . vraptor . jasperreports . formats . ExportFormat ; import br . com . caelum . vraptor . jasperreports . formats . Html ; import com . google . common . collect . Lists ; import com . google . common . collect . Maps ; @ Component public class DefaultExporter implements ReportExporter { private Collection < Report > reports = Lists . newArrayList ( ) ; private final ReportLoader loader ; private final List < ReportDecorator > decorators ; private final HttpSession session ; private final Logger logger = LoggerFactory . getLogger ( DefaultExporter . class ) ; public DefaultExporter ( ReportLoader loader , List < ReportDecorator > decorators , HttpSession session ) { this . loader = loader ; this . decorators = decorators ; this . session = session ; } public ReportExporter export ( Report report ) { this . reports . add ( report ) ; return this ; } public ReportExporter export ( Collection < Report > reports ) { this . reports = reports ; return this ; } public byte [ ] to ( ExportFormat format ) { try { List < JasperPrint > print = fillAll ( format ) ; return format . toByteArray ( print ) ; } catch ( JRException e ) { throw new RuntimeException ( e ) ; } } private List < JasperPrint > fillAll ( ExportFormat format ) throws JRException { List < JasperPrint > printList = new ArrayList < JasperPrint > ( ) ; for ( Report report : reports ) { printList . add ( fill ( report ) ) ; } configImageServlet ( format , printList . get ( <NUM_LIT:0> ) ) ; return printList ; } private JasperPrint fill ( Report report ) throws JRException { for ( ReportDecorator decorator : decorators ) { decorator . decorate ( report ) ; } JasperReport jr = loader . load ( report ) ; JRBeanCollectionDataSource data = new JRBeanCollectionDataSource ( report . getData ( ) , false ) ; Map < String , Object > parameters = report . getParameters ( ) ; if ( parameters == null ) { parameters = Maps . newHashMap ( ) ; logger . warn ( "<STR_LIT>" ) ; } JasperPrint print = JasperFillManager . fillReport ( jr , parameters , data ) ; return print ; } private void configImageServlet ( ExportFormat format , JasperPrint print ) { if ( format . getClass ( ) . equals ( Html . class ) && print != null ) session . setAttribute ( ImageServlet . DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE , print ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . exporter ; import java . util . Collection ; import br . com . caelum . vraptor . jasperreports . Report ; import br . com . caelum . vraptor . jasperreports . formats . ExportFormat ; public interface ReportExporter { ReportExporter export ( Report report ) ; ReportExporter export ( Collection < Report > reports ) ; byte [ ] to ( ExportFormat format ) ; } </s>
<s> package br . com . caelum . vraptor . jasperreports ; import java . io . File ; import java . util . Locale ; import javax . servlet . ServletContext ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import br . com . caelum . vraptor . ioc . ApplicationScoped ; import br . com . caelum . vraptor . ioc . Component ; @ Component @ ApplicationScoped public class ReportPathResolver { private final ServletContext context ; public static final String DEFAULT_REPORTS_PATH = "<STR_LIT>" ; public static final String DEFAULT_SUBREPORTS_PATH = "<STR_LIT>" ; public static final String DEFAULT_IMAGES_PATH = "<STR_LIT>" ; private static final String DEFAULT_BUNDLE_NAME = "<STR_LIT>" ; private static final String SEPARATOR = File . separator ; private final Logger logger = LoggerFactory . getLogger ( ReportPathResolver . class ) ; public ReportPathResolver ( ServletContext context ) { this . context = context ; logger . debug ( "<STR_LIT>" + getReportsPath ( ) ) ; logger . debug ( "<STR_LIT>" + getSubReportsPath ( ) ) ; logger . debug ( "<STR_LIT>" + getImagesPath ( ) ) ; } public String getPathFor ( Report report ) { return getReportsPath ( ) + report . getTemplate ( ) ; } public String getReportsPath ( ) { return context . getRealPath ( getRelativeReportsPath ( ) ) + SEPARATOR ; } public String getSubReportsPath ( ) { return context . getRealPath ( getRelativeSubReportsPath ( ) ) + SEPARATOR ; } public String getImagesPath ( ) { return context . getRealPath ( getRelativeImagesPath ( ) ) + SEPARATOR ; } public String getResourceBundleFor ( Locale locale ) { return getReportsPath ( ) + getBundleName ( ) + locale . toString ( ) + "<STR_LIT>" ; } private String getRelativeImagesPath ( ) { String param = context . getInitParameter ( "<STR_LIT>" ) ; return param != null ? param . trim ( ) : DEFAULT_IMAGES_PATH ; } private String getRelativeSubReportsPath ( ) { String param = context . getInitParameter ( "<STR_LIT>" ) ; return param != null ? param . trim ( ) : DEFAULT_SUBREPORTS_PATH ; } private String getRelativeReportsPath ( ) { String param = context . getInitParameter ( "<STR_LIT>" ) ; return param != null ? param . trim ( ) : DEFAULT_REPORTS_PATH ; } private String getBundleName ( ) { String param = context . getInitParameter ( "<STR_LIT>" ) ; return param != null ? param . trim ( ) : DEFAULT_BUNDLE_NAME ; } public String getImagesURI ( ) { return context . getContextPath ( ) + "<STR_LIT>" ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports ; import net . sf . jasperreports . engine . JRException ; import net . sf . jasperreports . engine . JasperCompileManager ; import net . sf . jasperreports . engine . JasperReport ; import net . sf . jasperreports . engine . util . JRLoader ; import br . com . caelum . vraptor . ioc . ApplicationScoped ; import br . com . caelum . vraptor . ioc . Component ; @ Component @ ApplicationScoped public class ReportLoader { private final ReportCache cache ; private final ReportPathResolver resolver ; public ReportLoader ( ReportCache cache , ReportPathResolver resolver ) { this . cache = cache ; this . resolver = resolver ; } public JasperReport load ( Report report ) throws JRException { if ( report . isCacheable ( ) ) return loadFromCache ( report ) ; else return loadFromDisk ( report ) ; } private JasperReport loadFromCache ( Report report ) throws JRException { if ( ! cache . contains ( report . getTemplate ( ) ) ) cache . put ( report . getTemplate ( ) , loadFromDisk ( report ) ) ; return cache . get ( report . getTemplate ( ) ) ; } private JasperReport loadFromDisk ( Report report ) throws JRException { String template = resolver . getPathFor ( report ) ; if ( template . endsWith ( "<STR_LIT>" ) ) return JasperCompileManager . compileReport ( template ) ; else return ( JasperReport ) JRLoader . loadObjectFromFile ( template ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . decorator ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . util . Enumeration ; import java . util . Locale ; import java . util . MissingResourceException ; import java . util . PropertyResourceBundle ; import java . util . ResourceBundle ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import br . com . caelum . vraptor . core . Localization ; import br . com . caelum . vraptor . ioc . Component ; import br . com . caelum . vraptor . jasperreports . ReportPathResolver ; import br . com . caelum . vraptor . util . EmptyBundle ; @ Component public class ReportsResourceBundle extends ResourceBundle { private ResourceBundle delegate ; private Locale locale ; private static final Logger logger = LoggerFactory . getLogger ( ReportsResourceBundle . class ) ; public ReportsResourceBundle ( Localization localization , ReportPathResolver resolver ) { this . locale = localization . getLocale ( ) ; buildBundle ( resolver . getResourceBundleFor ( locale ) ) ; } public Locale getLocale ( ) { return locale ; } private void buildBundle ( String path ) { File bundle = new File ( path ) ; try { this . delegate = new PropertyResourceBundle ( new FileInputStream ( bundle ) ) ; logger . debug ( "<STR_LIT>" + locale ) ; logger . debug ( "<STR_LIT>" + bundle . getAbsolutePath ( ) ) ; } catch ( FileNotFoundException e ) { logger . debug ( "<STR_LIT>" + bundle . getAbsolutePath ( ) + "<STR_LIT>" ) ; this . delegate = new EmptyBundle ( ) ; } catch ( IOException e ) { logger . debug ( "<STR_LIT>" + bundle . getAbsolutePath ( ) + "<STR_LIT>" ) ; this . delegate = new EmptyBundle ( ) ; } } public Enumeration < String > getKeys ( ) { return delegate . getKeys ( ) ; } protected Object handleGetObject ( String key ) { try { return delegate . getString ( key ) ; } catch ( MissingResourceException e ) { return "<STR_LIT>" + key + "<STR_LIT>" ; } } } </s>
<s> package br . com . caelum . vraptor . jasperreports . decorator ; import java . util . Map ; import net . sf . jasperreports . engine . JRParameter ; import br . com . caelum . vraptor . Result ; import br . com . caelum . vraptor . ioc . Component ; import br . com . caelum . vraptor . jasperreports . Report ; import br . com . caelum . vraptor . jasperreports . ReportPathResolver ; @ Component public class DefaultDecorator implements ReportDecorator { private final ReportPathResolver resolver ; private final ReportsResourceBundle bundle ; private final Result result ; public DefaultDecorator ( ReportPathResolver resolver , ReportsResourceBundle bundle , Result result ) { this . resolver = resolver ; this . bundle = bundle ; this . result = result ; } public void decorate ( Report report ) { if ( report . getParameters ( ) != null ) { report . addParameter ( "<STR_LIT>" , resolver . getReportsPath ( ) ) ; report . addParameter ( "<STR_LIT>" , resolver . getSubReportsPath ( ) ) ; report . addParameter ( "<STR_LIT>" , resolver . getImagesPath ( ) ) ; report . addParameter ( JRParameter . REPORT_LOCALE , bundle . getLocale ( ) ) ; report . addParameter ( JRParameter . REPORT_RESOURCE_BUNDLE , bundle ) ; includeRequestParameters ( report ) ; } } private void includeRequestParameters ( Report report ) { for ( Map . Entry < String , Object > entry : result . included ( ) . entrySet ( ) ) { report . addParameter ( entry . getKey ( ) , entry . getValue ( ) ) ; } } } </s>
<s> package br . com . caelum . vraptor . jasperreports . decorator ; import br . com . caelum . vraptor . jasperreports . Report ; public interface ReportDecorator { void decorate ( Report report ) ; } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import java . io . ByteArrayOutputStream ; import java . util . List ; import java . util . Map ; import net . sf . jasperreports . engine . JRException ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . JRExporterParameter ; import net . sf . jasperreports . engine . JasperPrint ; import com . google . common . collect . Maps ; import com . google . common . io . Closeables ; import com . google . common . io . Flushables ; public abstract class AbstractExporter implements ExportFormat { protected Map < JRExporterParameter , Object > parameters = Maps . newHashMap ( ) ; public AbstractExporter ( ) { defaultParameters ( ) ; } public ExportFormat configure ( JRExporterParameter parameter , Object value ) { parameters . put ( parameter , value ) ; return this ; } public Map < JRExporterParameter , Object > getParameters ( ) { return this . parameters ; } protected void defaultParameters ( ) { configure ( JRExporterParameter . CHARACTER_ENCODING , "<STR_LIT:UTF-8>" ) ; } protected abstract JRExporter setup ( ) ; public boolean supportsBatchMode ( ) { return true ; } public byte [ ] toByteArray ( List < JasperPrint > print ) { ByteArrayOutputStream output = new ByteArrayOutputStream ( ) ; try { JRExporter exporter = setup ( ) ; exporter . setParameters ( getParameters ( ) ) ; if ( print . size ( ) > <NUM_LIT:1> ) exporter . setParameter ( JRExporterParameter . JASPER_PRINT_LIST , print ) ; else exporter . setParameter ( JRExporterParameter . JASPER_PRINT , print . get ( <NUM_LIT:0> ) ) ; exporter . setParameter ( JRExporterParameter . OUTPUT_STREAM , output ) ; exporter . exportReport ( ) ; Flushables . flushQuietly ( output ) ; return output . toByteArray ( ) ; } catch ( JRException e ) { throw new RuntimeException ( e ) ; } finally { Closeables . closeQuietly ( output ) ; parameters . clear ( ) ; } } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import java . awt . image . BufferedImage ; import java . io . ByteArrayOutputStream ; import java . io . IOException ; import java . util . List ; import javax . imageio . ImageIO ; import net . sf . jasperreports . engine . JRException ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . JRExporterParameter ; import net . sf . jasperreports . engine . JasperPrint ; import net . sf . jasperreports . engine . export . JRGraphics2DExporter ; import net . sf . jasperreports . engine . export . JRGraphics2DExporterParameter ; import br . com . caelum . vraptor . ioc . Component ; import com . google . common . io . Closeables ; @ Component public class Image extends AbstractExporter { private Float zoom = <NUM_LIT> ; private Integer page = <NUM_LIT:0> ; private String format = "<STR_LIT>" ; public String getContentType ( ) { return "<STR_LIT>" + format ; } public String getExtension ( ) { return format ; } public JRExporter setup ( ) { try { return new JRGraphics2DExporter ( ) ; } catch ( JRException e ) { throw new RuntimeException ( e ) ; } } public Image zoom ( Float zoom ) { this . zoom = zoom ; return this ; } public Image page ( Integer page ) { this . page = page ; return this ; } public Image png ( ) { this . format = "<STR_LIT>" ; return this ; } public Image jpeg ( ) { this . format = "<STR_LIT>" ; return this ; } public boolean supportsBatchMode ( ) { return false ; } public byte [ ] toByteArray ( List < JasperPrint > print ) { ByteArrayOutputStream output = new ByteArrayOutputStream ( ) ; try { JRExporter exporter = setup ( ) ; exporter . setParameters ( parameters ) ; exporter . setParameter ( JRExporterParameter . JASPER_PRINT , print . get ( <NUM_LIT:0> ) ) ; BufferedImage image = getPageImage ( print . get ( <NUM_LIT:0> ) ) ; exporter . setParameter ( JRGraphics2DExporterParameter . GRAPHICS_2D , image . getGraphics ( ) ) ; exporter . setParameter ( JRGraphics2DExporterParameter . ZOOM_RATIO , zoom ) ; exporter . setParameter ( JRExporterParameter . PAGE_INDEX , page ) ; exporter . exportReport ( ) ; ImageIO . write ( image , format , output ) ; return output . toByteArray ( ) ; } catch ( JRException e ) { throw new RuntimeException ( e ) ; } catch ( IOException e ) { throw new RuntimeException ( "<STR_LIT>" , e ) ; } finally { Closeables . closeQuietly ( output ) ; parameters . clear ( ) ; } } private BufferedImage getPageImage ( JasperPrint print ) { int width = ( int ) ( print . getPageWidth ( ) * zoom ) ; int height = ( int ) ( print . getPageHeight ( ) * zoom ) ; return new BufferedImage ( width , height , BufferedImage . TYPE_INT_RGB ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . export . JRHtmlExporter ; import net . sf . jasperreports . engine . export . JRHtmlExporterParameter ; import br . com . caelum . vraptor . ioc . Component ; import br . com . caelum . vraptor . jasperreports . ReportPathResolver ; @ Component public class Html extends AbstractExporter { private final ReportPathResolver resolver ; public Html ( ReportPathResolver resolver ) { this . resolver = resolver ; } public String getContentType ( ) { return "<STR_LIT:text/html>" ; } public String getExtension ( ) { return "<STR_LIT>" ; } public JRExporter setup ( ) { configure ( JRHtmlExporterParameter . IS_USING_IMAGES_TO_ALIGN , Boolean . FALSE ) ; configure ( JRHtmlExporterParameter . IMAGES_DIR_NAME , resolver . getImagesPath ( ) ) ; configure ( JRHtmlExporterParameter . IMAGES_URI , resolver . getImagesURI ( ) ) ; return new JRHtmlExporter ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . export . oasis . JROdsExporter ; import br . com . caelum . vraptor . ioc . Component ; @ Component public class Ods extends AbstractExporter { public String getContentType ( ) { return "<STR_LIT>" ; } public String getExtension ( ) { return "<STR_LIT>" ; } public JRExporter setup ( ) { return new JROdsExporter ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . export . JRXlsExporterParameter ; import net . sf . jasperreports . engine . export . ooxml . JRXlsxExporter ; import br . com . caelum . vraptor . ioc . Component ; @ Component public class Xlsx extends AbstractExporter { public String getContentType ( ) { return "<STR_LIT>" ; } public String getExtension ( ) { return "<STR_LIT>" ; } public JRExporter setup ( ) { configure ( JRXlsExporterParameter . IS_ONE_PAGE_PER_SHEET , Boolean . TRUE ) ; return new JRXlsxExporter ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . export . JRCsvExporter ; import br . com . caelum . vraptor . ioc . Component ; @ Component public class Csv extends AbstractExporter { public String getContentType ( ) { return "<STR_LIT>" ; } public String getExtension ( ) { return "<STR_LIT>" ; } public JRExporter setup ( ) { return new JRCsvExporter ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . export . JRTextExporter ; import net . sf . jasperreports . engine . export . JRTextExporterParameter ; import br . com . caelum . vraptor . ioc . Component ; @ Component public class Rtf extends AbstractExporter { public JRExporter setup ( ) { configure ( JRTextExporterParameter . CHARACTER_WIDTH , <NUM_LIT> ) ; configure ( JRTextExporterParameter . CHARACTER_HEIGHT , <NUM_LIT> ) ; return new JRTextExporter ( ) ; } public String getContentType ( ) { return "<STR_LIT>" ; } public String getExtension ( ) { return "<STR_LIT>" ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . export . JRXhtmlExporter ; import br . com . caelum . vraptor . ioc . Component ; @ Component public class Xhtml extends AbstractExporter { public String getContentType ( ) { return "<STR_LIT:text/html>" ; } public String getExtension ( ) { return "<STR_LIT>" ; } public JRExporter setup ( ) { return new JRXhtmlExporter ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . export . oasis . JROdtExporter ; import br . com . caelum . vraptor . ioc . Component ; @ Component public class Odt extends AbstractExporter { public String getContentType ( ) { return "<STR_LIT>" ; } public String getExtension ( ) { return "<STR_LIT>" ; } public JRExporter setup ( ) { return new JROdtExporter ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import java . util . List ; import java . util . Map ; import net . sf . jasperreports . engine . JRExporterParameter ; import net . sf . jasperreports . engine . JasperPrint ; public interface ExportFormat { String getContentType ( ) ; String getExtension ( ) ; ExportFormat configure ( JRExporterParameter parameter , Object value ) ; Map < JRExporterParameter , Object > getParameters ( ) ; boolean supportsBatchMode ( ) ; byte [ ] toByteArray ( List < JasperPrint > print ) ; } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import br . com . caelum . vraptor . ioc . Component ; @ Component public class ExportFormats { private Map < String , ExportFormat > exporters = new HashMap < String , ExportFormat > ( ) ; public ExportFormats ( List < ExportFormat > formats ) { for ( ExportFormat format : formats ) { exporters . put ( format . getExtension ( ) , format ) ; } } public static Pdf pdf ( ) { return new Pdf ( ) ; } public static Csv csv ( ) { return new Csv ( ) ; } public static Xls xls ( ) { return new Xls ( ) ; } public static Rtf rtf ( ) { return new Rtf ( ) ; } public static Docx docx ( ) { return new Docx ( ) ; } public static Odt odt ( ) { return new Odt ( ) ; } public static Txt txt ( ) { return new Txt ( ) ; } public Html html ( ) { return ( Html ) byExtension ( "<STR_LIT>" ) ; } public static Ods ods ( ) { return new Ods ( ) ; } public static Pptx pptx ( ) { return new Pptx ( ) ; } public static Xhtml xhtml ( ) { return new Xhtml ( ) ; } public static Xlsx xlsx ( ) { return new Xlsx ( ) ; } public static Image png ( ) { return new Image ( ) ; } public static Image png ( Integer page , Float zoom ) { Image image = new Image ( ) ; image . page ( page ) ; image . zoom ( zoom ) ; return image ; } public static Image jpeg ( ) { Image image = new Image ( ) ; image . jpeg ( ) ; return image ; } public static Image jpeg ( Integer page , Float zoom ) { Image image = new Image ( ) ; image . jpeg ( ) ; image . page ( page ) ; image . zoom ( zoom ) ; return image ; } public ExportFormat byExtension ( String extension ) { if ( supports ( extension ) ) return exporters . get ( extension . toLowerCase ( ) ) ; return pdf ( ) ; } public boolean supports ( String format ) { return exporters . containsKey ( format . toLowerCase ( ) ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . export . ooxml . JRPptxExporter ; import br . com . caelum . vraptor . ioc . Component ; @ Component public class Pptx extends AbstractExporter { public String getContentType ( ) { return "<STR_LIT>" ; } public String getExtension ( ) { return "<STR_LIT>" ; } public JRExporter setup ( ) { return new JRPptxExporter ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . export . ooxml . JRDocxExporter ; import net . sf . jasperreports . engine . export . ooxml . JRDocxExporterParameter ; import br . com . caelum . vraptor . ioc . Component ; @ Component public class Docx extends AbstractExporter { public String getContentType ( ) { return "<STR_LIT>" ; } public String getExtension ( ) { return "<STR_LIT>" ; } public JRExporter setup ( ) { configure ( JRDocxExporterParameter . FLEXIBLE_ROW_HEIGHT , Boolean . TRUE ) ; return new JRDocxExporter ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . export . JRPdfExporter ; import net . sf . jasperreports . engine . export . JRPdfExporterParameter ; import br . com . caelum . vraptor . ioc . Component ; @ Component public class Pdf extends AbstractExporter { private Integer permissions = <NUM_LIT:0> ; public String getContentType ( ) { return "<STR_LIT>" ; } public String getExtension ( ) { return "<STR_LIT>" ; } public JRExporter setup ( ) { configure ( JRPdfExporterParameter . IS_COMPRESSED , Boolean . TRUE ) ; return new JRPdfExporter ( ) ; } public void encrypt ( String password ) { configure ( JRPdfExporterParameter . IS_ENCRYPTED , Boolean . TRUE ) ; configure ( JRPdfExporterParameter . IS_128_BIT_KEY , Boolean . TRUE ) ; configure ( JRPdfExporterParameter . USER_PASSWORD , password ) ; configure ( JRPdfExporterParameter . OWNER_PASSWORD , password ) ; } public Pdf addPermission ( Integer permission ) { this . permissions |= permission ; configure ( JRPdfExporterParameter . PERMISSIONS , permissions ) ; return this ; } public void setAuthor ( String author ) { configure ( JRPdfExporterParameter . METADATA_AUTHOR , author ) ; } public void setTitle ( String title ) { configure ( JRPdfExporterParameter . METADATA_TITLE , title ) ; } public void setCreator ( String creator ) { configure ( JRPdfExporterParameter . METADATA_CREATOR , creator ) ; } public void setSubject ( String subject ) { configure ( JRPdfExporterParameter . METADATA_SUBJECT , subject ) ; } public void setKeywords ( String keywords ) { configure ( JRPdfExporterParameter . METADATA_KEYWORDS , keywords ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . export . JRXlsExporter ; import net . sf . jasperreports . engine . export . JRXlsExporterParameter ; import br . com . caelum . vraptor . ioc . Component ; @ Component public class Xls extends AbstractExporter { public String getContentType ( ) { return "<STR_LIT>" ; } public String getExtension ( ) { return "<STR_LIT>" ; } public JRExporter setup ( ) { configure ( JRXlsExporterParameter . IS_ONE_PAGE_PER_SHEET , Boolean . TRUE ) ; configure ( JRXlsExporterParameter . IS_WHITE_PAGE_BACKGROUND , Boolean . FALSE ) ; configure ( JRXlsExporterParameter . IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS , Boolean . TRUE ) ; configure ( JRXlsExporterParameter . IS_DETECT_CELL_TYPE , Boolean . FALSE ) ; return new JRXlsExporter ( ) ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports . formats ; import net . sf . jasperreports . engine . JRExporter ; import net . sf . jasperreports . engine . export . JRTextExporter ; import net . sf . jasperreports . engine . export . JRTextExporterParameter ; import br . com . caelum . vraptor . ioc . Component ; @ Component public class Txt extends AbstractExporter { public String getContentType ( ) { return "<STR_LIT:text/plain>" ; } public String getExtension ( ) { return "<STR_LIT>" ; } public JRExporter setup ( ) { configure ( JRTextExporterParameter . CHARACTER_WIDTH , <NUM_LIT> ) ; configure ( JRTextExporterParameter . CHARACTER_HEIGHT , <NUM_LIT> ) ; return new JRTextExporter ( ) ; } public boolean supportsBatchMode ( ) { return false ; } } </s>
<s> package br . com . caelum . vraptor . jasperreports ; import br . com . caelum . vraptor . http . FormatResolver ; import br . com . caelum . vraptor . ioc . Component ; import br . com . caelum . vraptor . jasperreports . formats . ExportFormat ; import br . com . caelum . vraptor . jasperreports . formats . ExportFormats ; @ Component public class ReportFormatResolver { private final ExportFormats formats ; private final FormatResolver formatResolver ; public ReportFormatResolver ( ExportFormats formats , FormatResolver formatResolver ) { this . formats = formats ; this . formatResolver = formatResolver ; } public ExportFormat getExportFormat ( ) { return formats . byExtension ( formatResolver . getAcceptFormat ( ) ) ; } public boolean doDownload ( ) { return ! "<STR_LIT>" . equals ( formatResolver . getAcceptFormat ( ) ) ; } } </s>
<s> package org . nju . artemis . aejb . component ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Set ; import org . jboss . as . ejb3 . component . session . SessionBeanComponentDescription . SessionBeanType ; import org . jboss . invocation . Interceptor ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . interceptors . DispatcherInterceptor ; import org . nju . artemis . aejb . component . interceptors . InvocationFilterInterceptor ; import org . nju . artemis . aejb . component . interceptors . InvocationDirectInterceptor ; import org . nju . artemis . aejb . component . interceptors . TransactionSecurityInterceptor ; import org . nju . artemis . aejb . deployment . processors . TransactionManager ; import org . nju . artemis . aejb . evolution . handlers . InterfaceCompareHandler ; import org . nju . artemis . aejb . management . client . AEjbClientImpl . AEjbStatus ; public class AcContainer { Logger log = Logger . getLogger ( AcContainer . class ) ; final private String appName ; final private String aejbName ; final private String moduleName ; final private String beanName ; final private String distinctName ; final private SessionBeanType beanType ; private List < Interceptor > interceptors ; private int running ; private Set < String > originDepndencies ; private Set < String > runtimeDepndencies ; private Map < String , TransactionManager > transactionManagers ; private Set < Class < ? > > localViews = new HashSet < Class < ? > > ( ) ; private Set < Class < ? > > remoteViews = new HashSet < Class < ? > > ( ) ; final private EvolutionStatistics evolutionStatistics = new EvolutionStatistics ( ) ; public AcContainer ( String appName , String moduleName , String beanName , String distinctName , SessionBeanType beanType ) { this . appName = appName == null ? "<STR_LIT>" : appName ; this . moduleName = moduleName ; this . beanName = beanName ; this . aejbName = moduleName + "<STR_LIT:/>" + beanName ; this . distinctName = distinctName ; this . beanType = beanType ; } public String getAEJBName ( ) { return aejbName ; } public String getBeanName ( ) { return beanName ; } public String getDistinctName ( ) { return distinctName ; } public SessionBeanType getBeanType ( ) { return beanType ; } public String getApplicationName ( ) { return appName ; } public String getModuleName ( ) { return moduleName ; } public EvolutionStatistics getEvolutionStatistics ( ) { return evolutionStatistics ; } public void start ( ) { interceptors = new ArrayList < Interceptor > ( ) ; interceptors . add ( new TransactionSecurityInterceptor ( this ) ) ; interceptors . add ( new InvocationFilterInterceptor ( this ) ) ; interceptors . add ( new InvocationDirectInterceptor ( this ) ) ; interceptors . add ( new DispatcherInterceptor ( ) ) ; log . info ( "<STR_LIT>" + appName + "<STR_LIT>" + moduleName + "<STR_LIT>" + distinctName + "<STR_LIT>" + beanName + "<STR_LIT>" + beanType + "<STR_LIT>" + aejbName ) ; } public void stop ( ) { evolutionStatistics . clear ( ) ; interceptors . clear ( ) ; originDepndencies = null ; runtimeDepndencies = null ; localViews . clear ( ) ; remoteViews . clear ( ) ; transactionManagers = null ; log . info ( "<STR_LIT>" + aejbName ) ; } public List < Interceptor > getInterceptors ( ) { return interceptors ; } public void addOriginDepndencies ( String aejbName ) { if ( originDepndencies == null ) originDepndencies = new HashSet < String > ( ) ; originDepndencies . add ( aejbName ) ; } public void changeRuntimeDependencies ( String oldD , String newD ) { if ( runtimeDepndencies == null ) runtimeDepndencies = new HashSet < String > ( originDepndencies ) ; if ( oldD . equals ( newD ) == false ) { runtimeDepndencies . add ( newD ) ; runtimeDepndencies . remove ( oldD ) ; } } public void addRunning ( ) { synchronized ( this ) { running ++ ; } } public void removeRunning ( ) { synchronized ( this ) { running -- ; } } public boolean isActive ( ) { synchronized ( this ) { if ( running < <NUM_LIT:0> ) { log . warn ( "<STR_LIT>" + getAEJBName ( ) + "<STR_LIT>" + running ) ; running = <NUM_LIT:0> ; } return running != <NUM_LIT:0> ; } } public Set < String > getRuntimeDependencies ( ) { if ( runtimeDepndencies == null && originDepndencies == null ) return null ; if ( runtimeDepndencies == null ) runtimeDepndencies = new HashSet < String > ( originDepndencies ) ; return runtimeDepndencies ; } public void setTransactionManager ( TransactionManager tm ) { if ( transactionManagers == null ) transactionManagers = new HashMap < String , TransactionManager > ( ) ; transactionManagers . put ( tm . getName ( ) , tm ) ; } public TransactionManager getTransactionManager ( String transactionName ) { if ( transactionManagers == null ) return null ; return transactionManagers . get ( transactionName ) ; } public Set < Class < ? > > getLocalView ( ) { return localViews ; } public void setLocalView ( Class < ? > localView ) { this . localViews . add ( localView ) ; } public Set < Class < ? > > getRemoteView ( ) { return remoteViews ; } public void setRemoteView ( Class < ? > remoteView ) { this . remoteViews . add ( remoteView ) ; } public Class < ? > getViewByClass ( Class < ? > viewClass ) { if ( viewClass . isInterface ( ) == false ) return null ; for ( Class < ? > remoteView : remoteViews ) { if ( InterfaceCompareHandler . equals ( remoteView , viewClass ) ) return remoteView ; } for ( Class < ? > localView : localViews ) { if ( InterfaceCompareHandler . equals ( localView , viewClass ) ) return localView ; } return null ; } public class EvolutionStatistics { private Map < String , AEjbStatus > aejbStatus = new HashMap < String , AEjbStatus > ( ) ; private Set < Listener < Map < String , AEjbStatus > > > aejbStatusListeners = new HashSet < Listener < Map < String , AEjbStatus > > > ( ) ; ; private Map < String , AcContainer > directionalMap = new HashMap < String , AcContainer > ( ) ; private Map < String , String > tempMap = new HashMap < String , String > ( ) ; private Map < String , String > protocols = new HashMap < String , String > ( ) ; public void clear ( ) { aejbStatus . clear ( ) ; aejbStatusListeners . clear ( ) ; directionalMap . clear ( ) ; protocols . clear ( ) ; } public void setAEjbStatus ( Map < String , AEjbStatus > aejbStatus ) { this . aejbStatus . putAll ( aejbStatus ) ; for ( Listener < Map < String , AEjbStatus > > aejbStatusListener : aejbStatusListeners ) { aejbStatusListener . transition ( aejbStatus ) ; } } public void setAEjbStatus ( String name , AEjbStatus aejbStatus ) { this . aejbStatus . put ( name , aejbStatus ) ; for ( Listener < Map < String , AEjbStatus > > aejbStatusListener : aejbStatusListeners ) { aejbStatusListener . transition ( this . aejbStatus ) ; } } public Map < String , AEjbStatus > getAEjbStatus ( ) { return aejbStatus ; } public void addStatusListener ( Listener < Map < String , AEjbStatus > > aejbStatusListener ) { aejbStatusListeners . add ( aejbStatusListener ) ; } public Map < String , AcContainer > getDirectionalMap ( ) { return directionalMap ; } public void addToDirectionalMap ( String from , AcContainer toContainer ) { if ( ( originDepndencies == null || originDepndencies . contains ( from ) == false ) && tempMap . containsKey ( from ) == false ) return ; if ( originDepndencies != null && originDepndencies . contains ( from ) ) { if ( tempMap . containsValue ( from ) && tempMap . containsKey ( from ) == false ) return ; directionalMap . put ( from , toContainer ) ; tempMap . put ( toContainer . getAEJBName ( ) , from ) ; if ( tempMap . containsKey ( from ) ) tempMap . remove ( from ) ; } else if ( tempMap . containsKey ( from ) ) { String dependency = tempMap . remove ( from ) ; directionalMap . put ( dependency , toContainer ) ; tempMap . put ( toContainer . getAEJBName ( ) , dependency ) ; } if ( directionalMap . size ( ) != tempMap . size ( ) ) log . info ( "<STR_LIT>" ) ; } public Map < String , String > getProtocols ( ) { return protocols ; } public void addProtocol ( String name , String protocol ) { protocols . put ( name , protocol ) ; } public String getProtocolByBeanName ( String name ) { return protocols . get ( name ) ; } } } </s>
<s> package org . nju . artemis . aejb . component . interceptors ; import org . jboss . invocation . Interceptor ; import org . jboss . invocation . InterceptorContext ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AcContainer ; import org . nju . artemis . aejb . deployment . processors . TransactionManager ; import org . nju . artemis . aejb . evolution . DuService ; import org . nju . artemis . aejb . evolution . protocols . Protocol ; public class TransactionSecurityInterceptor implements Interceptor { Logger log = Logger . getLogger ( TransactionSecurityInterceptor . class ) ; private final AcContainer container ; public TransactionSecurityInterceptor ( AcContainer container ) { this . container = container ; } @ Override public Object processInvocation ( InterceptorContext context ) throws Exception { log . debug ( "<STR_LIT>" ) ; Object [ ] params = context . getParameters ( ) ; if ( params == null || ! ( params [ <NUM_LIT:0> ] instanceof String ) ) { return context . proceed ( ) ; } String param0 = ( String ) params [ <NUM_LIT:0> ] ; String [ ] splits = param0 . split ( "<STR_LIT:/>" ) ; if ( splits . length != <NUM_LIT:2> ) { return context . proceed ( ) ; } final String transactionName = splits [ <NUM_LIT:0> ] ; final String objectId = splits [ <NUM_LIT:1> ] ; final String targetName = ( String ) context . getContextData ( ) . get ( "<STR_LIT>" ) ; final String protocol = container . getEvolutionStatistics ( ) . getProtocolByBeanName ( targetName ) ; log . debug ( "<STR_LIT>" + transactionName + "<STR_LIT>" + objectId + "<STR_LIT>" + protocol ) ; if ( protocol == null || isValidProtocolName ( protocol ) == false ) return context . proceed ( ) ; boolean ts = checkTransactionSecurity ( targetName , objectId , container . getTransactionManager ( transactionName ) , protocol ) ; log . debug ( "<STR_LIT>" + ts ) ; context . putPrivateData ( Boolean . class , ts ) ; log . debug ( "<STR_LIT>" ) ; return context . proceed ( ) ; } private boolean checkTransactionSecurity ( String targetName , String objectId , TransactionManager transactionManager , String protocolName ) { Protocol protocol = DuService . getProtocol ( protocolName ) ; if ( protocol != null ) { return protocol . checkTransactionSecurity ( targetName , objectId , transactionManager ) ; } return false ; } private boolean isValidProtocolName ( String protocol ) { return protocol . equals ( "<STR_LIT>" ) || protocol . equals ( "<STR_LIT>" ) ; } } </s>
<s> package org . nju . artemis . aejb . component . interceptors ; import java . lang . reflect . Proxy ; import java . util . HashMap ; import java . util . Map ; import javax . ejb . EJBHome ; import javax . ejb . EJBLocalHome ; import org . jboss . ejb . client . EJBClient ; import org . jboss . ejb . client . EJBHomeLocator ; import org . jboss . ejb . client . EJBLocator ; import org . jboss . ejb . client . StatelessEJBLocator ; import org . jboss . invocation . Interceptor ; import org . jboss . invocation . InterceptorContext ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AEjbUtilities ; public class DispatcherInterceptor implements Interceptor { Logger log = Logger . getLogger ( DispatcherInterceptor . class ) ; private Map < String , Object > contextData ; private Map < String , Object > proxyMap = new HashMap < String , Object > ( ) ; ; @ Override public Object processInvocation ( InterceptorContext context ) throws Exception { log . info ( "<STR_LIT>" ) ; contextData = context . getContextData ( ) ; String appName = ( String ) contextData . get ( "<STR_LIT>" ) ; String moduleName = ( String ) contextData . get ( "<STR_LIT>" ) ; String distinctName = ( String ) contextData . get ( "<STR_LIT>" ) ; String beanName = ( String ) contextData . get ( "<STR_LIT>" ) ; Class < ? > viewClass = ( Class < ? > ) contextData . get ( "<STR_LIT>" ) ; boolean stateful = ( Boolean ) contextData . get ( "<STR_LIT>" ) ; return dispatch ( context , appName , moduleName , distinctName , beanName , viewClass , stateful ) ; } @ SuppressWarnings ( { "<STR_LIT:rawtypes>" , "<STR_LIT:unchecked>" , "<STR_LIT>" } ) private Object dispatch ( InterceptorContext context , String appName , String moduleName , String distinctName , String beanName , Class < ? > viewClass , boolean stateful ) { EJBLocator ejbLocator = null ; Object result = null ; final String proxyName = "<STR_LIT>" + appName + "<STR_LIT:/>" + moduleName + "<STR_LIT:/>" + beanName + "<STR_LIT:/>" + distinctName + "<STR_LIT:/>" + viewClass + "<STR_LIT:/>" + stateful ; final String aejbName = moduleName + "<STR_LIT:/>" + beanName ; log . info ( proxyName ) ; if ( proxyMap . containsKey ( proxyName ) ) { final Proxy proxy = ( Proxy ) proxyMap . get ( proxyName ) ; try { AEjbUtilities . getContainer ( aejbName ) . addRunning ( ) ; result = proxy . getInvocationHandler ( proxy ) . invoke ( proxy , context . getMethod ( ) , context . getParameters ( ) ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( Throwable e ) { e . printStackTrace ( ) ; } finally { AEjbUtilities . getContainer ( aejbName ) . removeRunning ( ) ; } log . info ( "<STR_LIT>" ) ; return result ; } if ( EJBHome . class . isAssignableFrom ( viewClass ) || EJBLocalHome . class . isAssignableFrom ( viewClass ) ) { ejbLocator = new EJBHomeLocator ( viewClass , appName , moduleName , beanName , distinctName ) ; } else if ( stateful ) { try { ejbLocator = EJBClient . createSession ( viewClass , appName , moduleName , beanName , distinctName ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } else { ejbLocator = new StatelessEJBLocator ( viewClass , appName , moduleName , beanName , distinctName ) ; } final Proxy proxy = ( Proxy ) EJBClient . createProxy ( ejbLocator ) ; try { AEjbUtilities . getContainer ( aejbName ) . addRunning ( ) ; result = proxy . getInvocationHandler ( proxy ) . invoke ( proxy , context . getMethod ( ) , context . getParameters ( ) ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( Throwable e ) { e . printStackTrace ( ) ; } finally { AEjbUtilities . getContainer ( aejbName ) . removeRunning ( ) ; } proxyMap . put ( proxyName , proxy ) ; log . info ( "<STR_LIT>" ) ; return result ; } } </s>
<s> package org . nju . artemis . aejb . component . interceptors ; import java . util . Map ; import org . jboss . as . ejb3 . component . session . SessionBeanComponentDescription . SessionBeanType ; import org . jboss . invocation . Interceptor ; import org . jboss . invocation . InterceptorContext ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AcContainer ; public class InvocationDirectInterceptor implements Interceptor { Logger log = Logger . getLogger ( InvocationDirectInterceptor . class ) ; private final AcContainer container ; private InvocationContext lastInvocation ; public InvocationDirectInterceptor ( AcContainer container ) { this . container = container ; } @ Override public Object processInvocation ( InterceptorContext context ) throws Exception { log . info ( "<STR_LIT>" ) ; Map < String , Object > contextData = context . getContextData ( ) ; final String aejbName = ( String ) contextData . get ( "<STR_LIT>" ) ; AcContainer con = container . getEvolutionStatistics ( ) . getDirectionalMap ( ) . get ( aejbName ) ; if ( lastInvocation != null ) { contextData . put ( "<STR_LIT>" , lastInvocation . appName ( ) ) ; contextData . put ( "<STR_LIT>" , lastInvocation . moduleName ( ) ) ; contextData . put ( "<STR_LIT>" , lastInvocation . beanName ( ) ) ; contextData . put ( "<STR_LIT>" , lastInvocation . distinctName ( ) ) ; contextData . put ( "<STR_LIT>" , lastInvocation . viewClass ( ) ) ; contextData . put ( "<STR_LIT>" , lastInvocation . stateful ( ) ) ; } if ( con != null ) { if ( context . getPrivateData ( Boolean . class ) == null || context . getPrivateData ( Boolean . class ) == false ) return context . proceed ( ) ; contextData . put ( "<STR_LIT>" , con . getApplicationName ( ) ) ; contextData . put ( "<STR_LIT>" , con . getModuleName ( ) ) ; contextData . put ( "<STR_LIT>" , con . getBeanName ( ) ) ; contextData . put ( "<STR_LIT>" , con . getDistinctName ( ) ) ; contextData . put ( "<STR_LIT>" , con . getViewByClass ( ( Class < ? > ) contextData . get ( "<STR_LIT>" ) ) ) ; contextData . put ( "<STR_LIT>" , con . getBeanType ( ) == SessionBeanType . STATEFUL ) ; lastInvocation = new InvocationContext ( con . getApplicationName ( ) , con . getModuleName ( ) , con . getBeanName ( ) , con . getDistinctName ( ) , con . getViewByClass ( ( Class < ? > ) contextData . get ( "<STR_LIT>" ) ) , con . getBeanType ( ) == SessionBeanType . STATEFUL ) ; } log . info ( "<STR_LIT>" ) ; return context . proceed ( ) ; } private class InvocationContext { private String $appName ; private String $moduleName ; private String $beanName ; private String $distinctName ; private Class < ? > $viewClass ; private boolean $stateful ; public InvocationContext ( String $appName , String $moduleName , String $beanName , String $distinctName , Class < ? > $viewClass , boolean $stateful ) { this . $appName = $appName ; this . $moduleName = $moduleName ; this . $beanName = $beanName ; this . $distinctName = $distinctName ; this . $viewClass = $viewClass ; this . $stateful = $stateful ; } String appName ( ) { return $appName ; } String moduleName ( ) { return $moduleName ; } String beanName ( ) { return $beanName ; } String distinctName ( ) { return $distinctName ; } Class < ? > viewClass ( ) { return $viewClass ; } boolean stateful ( ) { return $stateful ; } } } </s>
<s> package org . nju . artemis . aejb . component . interceptors ; import java . util . Map ; import org . jboss . invocation . Interceptor ; import org . jboss . invocation . InterceptorContext ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AEjbStatusListener ; import org . nju . artemis . aejb . component . AcContainer ; import org . nju . artemis . aejb . management . client . AEjbClientImpl . AEjbStatus ; public class InvocationFilterInterceptor implements Interceptor { Logger log = Logger . getLogger ( InvocationFilterInterceptor . class ) ; private final AcContainer container ; private final InvocationManager manager ; public InvocationFilterInterceptor ( AcContainer container ) { this . container = container ; manager = new InvocationManager ( ) ; this . container . getEvolutionStatistics ( ) . addStatusListener ( new AEjbStatusListener ( manager ) ) ; } @ Override public Object processInvocation ( InterceptorContext context ) throws Exception { log . info ( "<STR_LIT>" ) ; final String targetAEjbName = ( String ) context . getContextData ( ) . get ( "<STR_LIT>" ) ; final Map < String , AEjbStatus > status = container . getEvolutionStatistics ( ) . getAEjbStatus ( ) ; if ( status != null && AEjbStatus . BLOCKING == status . get ( targetAEjbName ) ) { manager . blockInvocation ( context , targetAEjbName ) ; } log . info ( "<STR_LIT>" ) ; return context . proceed ( ) ; } public class InvocationManager { private InterceptorContext context ; private String targetName ; public void resumeInvocation ( ) { if ( context != null ) { synchronized ( context ) { context . notify ( ) ; } this . context = null ; } } public void blockInvocation ( InterceptorContext context , String targetName ) { this . context = context ; this . targetName = targetName ; synchronized ( this . context ) { try { this . context . wait ( ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } } public String getTargetName ( ) { return targetName ; } } } </s>
<s> package org . nju . artemis . aejb . component ; import java . util . Map ; import org . nju . artemis . aejb . component . interceptors . InvocationFilterInterceptor . InvocationManager ; import org . nju . artemis . aejb . management . client . AEjbClientImpl . AEjbStatus ; public class AEjbStatusListener implements Listener < Map < String , AEjbStatus > > { private final InvocationManager invocationManager ; public AEjbStatusListener ( InvocationManager invocationManager ) { this . invocationManager = invocationManager ; } @ Override public void transition ( Map < String , AEjbStatus > context ) { if ( invocationManager != null && context != null && ! context . isEmpty ( ) ) { final String targetName = invocationManager . getTargetName ( ) ; if ( targetName != null && AEjbStatus . RESUMING == context . get ( targetName ) ) { invocationManager . resumeInvocation ( ) ; } } } } </s>
<s> package org . nju . artemis . aejb . component ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import org . jboss . msc . service . Service ; import org . jboss . msc . service . ServiceName ; import org . jboss . msc . service . StartContext ; import org . jboss . msc . service . StartException ; import org . jboss . msc . service . StopContext ; import org . nju . artemis . aejb . management . client . AEjbClientImpl . AEjbStatus ; public class AEjbUtilities implements Service < AEjbUtilities > { public static final ServiceName SERVICE_NAME = ServiceName . JBOSS . append ( "<STR_LIT>" , "<STR_LIT>" ) ; static Map < String , Map < String , AcContainer > > DeploymentUnits = new HashMap < String , Map < String , AcContainer > > ( ) ; public static boolean registerAEJB ( String unitName , AcContainer container ) { if ( DeploymentUnits . containsKey ( unitName ) ) { AcContainer accon = DeploymentUnits . get ( unitName ) . put ( container . getAEJBName ( ) , container ) ; if ( accon != null ) return false ; } else { Map < String , AcContainer > aejbs = new HashMap < String , AcContainer > ( ) ; aejbs . put ( container . getAEJBName ( ) , container ) ; DeploymentUnits . put ( unitName , aejbs ) ; } container . start ( ) ; return true ; } public static void removeDeploymentUnit ( String unitName ) { if ( DeploymentUnits . containsKey ( unitName ) ) { Map < String , AcContainer > aejbs = DeploymentUnits . get ( unitName ) ; Iterator < Entry < String , AcContainer > > iterator = aejbs . entrySet ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { iterator . next ( ) . getValue ( ) . stop ( ) ; } aejbs = null ; DeploymentUnits . remove ( unitName ) ; } } public static Map < String , Map < String , AcContainer > > getAllAEjbsInfo ( ) { return DeploymentUnits ; } public void setAEjbStatus ( Map < String , AEjbStatus > aejbStatus ) { for ( Entry < String , Map < String , AcContainer > > entry : DeploymentUnits . entrySet ( ) ) { Map < String , AcContainer > mapValue = entry . getValue ( ) ; for ( Entry < String , AcContainer > en : mapValue . entrySet ( ) ) { Map < String , AEjbStatus > status = new HashMap < String , AEjbStatus > ( aejbStatus ) ; en . getValue ( ) . getEvolutionStatistics ( ) . setAEjbStatus ( status ) ; } } } public static AcContainer getContainer ( String aejbName ) { for ( Entry < String , Map < String , AcContainer > > entry : DeploymentUnits . entrySet ( ) ) { Map < String , AcContainer > mapValue = entry . getValue ( ) ; for ( Entry < String , AcContainer > en : mapValue . entrySet ( ) ) { if ( aejbName . equals ( en . getValue ( ) . getAEJBName ( ) ) ) return en . getValue ( ) ; } } return null ; } public List < AcContainer > getAllContainers ( ) { List < AcContainer > containers = new ArrayList < AcContainer > ( ) ; for ( Entry < String , Map < String , AcContainer > > entry : DeploymentUnits . entrySet ( ) ) { Map < String , AcContainer > mapValue = entry . getValue ( ) ; for ( Entry < String , AcContainer > en : mapValue . entrySet ( ) ) { containers . add ( en . getValue ( ) ) ; } } return containers ; } @ Override public AEjbUtilities getValue ( ) throws IllegalStateException , IllegalArgumentException { return this ; } @ Override public void start ( StartContext context ) throws StartException { } @ Override public void stop ( StopContext context ) { } } </s>
<s> package org . nju . artemis . aejb . component ; public interface Listener < T > { void transition ( T transitionContext ) ; } </s>
<s> package org . nju . artemis . aejb . component ; import java . lang . reflect . Constructor ; import java . lang . reflect . InvocationHandler ; import java . lang . reflect . InvocationTargetException ; import java . lang . reflect . Proxy ; import java . security . AccessController ; import java . security . PrivilegedAction ; import org . jboss . as . naming . ManagedReference ; import org . jboss . as . naming . ManagedReferenceFactory ; import org . jboss . as . naming . ValueManagedReference ; import org . jboss . logging . Logger ; import org . jboss . msc . value . ImmediateValue ; import org . jboss . msc . value . Value ; public class ContainerManagedReferenceFactory implements ManagedReferenceFactory { Logger log = Logger . getLogger ( ContainerManagedReferenceFactory . class ) ; private final String appName ; private final String moduleName ; private final String distinctName ; private final String beanName ; private final String viewClass ; private final boolean stateful ; private final Value < ClassLoader > viewClassLoader ; private final AcContainer container ; public ContainerManagedReferenceFactory ( final String appName , final String moduleName , final String distinctName , final String beanName , final String viewClass , boolean stateful , AcContainer container ) { this ( appName , moduleName , distinctName , beanName , viewClass , null , stateful , container ) ; } public ContainerManagedReferenceFactory ( final String appName , final String moduleName , final String distinctName , final String beanName , final String viewClass , final Value < ClassLoader > viewClassLoader , boolean stateful , AcContainer container ) { this . appName = appName == null ? "<STR_LIT>" : appName ; this . moduleName = moduleName ; this . distinctName = distinctName ; this . beanName = beanName ; this . viewClass = viewClass ; this . viewClassLoader = viewClassLoader ; this . stateful = stateful ; this . container = container ; this . container . addOriginDepndencies ( moduleName + '<CHAR_LIT:/>' + beanName ) ; } @ Override public ManagedReference getReference ( ) { Class < ? > viewClass ; try { viewClass = Class . forName ( this . viewClass , false , getContextClassLoader ( ) ) ; } catch ( ClassNotFoundException e ) { if ( viewClassLoader == null ) { throw new RuntimeException ( "<STR_LIT>" + beanName ) ; } try { viewClass = Class . forName ( this . viewClass , false , viewClassLoader . getValue ( ) ) ; } catch ( ClassNotFoundException ce ) { throw new RuntimeException ( "<STR_LIT>" + beanName ) ; } } Class < ? > proxyClass = Proxy . getProxyClass ( viewClass . getClassLoader ( ) , viewClass ) . asSubclass ( viewClass ) ; Constructor < ? > proxyConstructor = null ; Object proxy = null ; try { proxyConstructor = proxyClass . getConstructor ( InvocationHandler . class ) ; } catch ( NoSuchMethodException e ) { throw new NoSuchMethodError ( "<STR_LIT>" ) ; } try { proxy = proxyConstructor . newInstance ( new ContainerInvocationHandler ( appName , moduleName , distinctName , beanName , viewClass , stateful , container ) ) ; } catch ( IllegalArgumentException e ) { e . printStackTrace ( ) ; } catch ( InstantiationException e ) { e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { e . printStackTrace ( ) ; } catch ( InvocationTargetException e ) { e . printStackTrace ( ) ; } return new ValueManagedReference ( new ImmediateValue < Object > ( proxy ) ) ; } public static ClassLoader getContextClassLoader ( ) { if ( System . getSecurityManager ( ) == null ) { return Thread . currentThread ( ) . getContextClassLoader ( ) ; } else { return AccessController . doPrivileged ( new PrivilegedAction < ClassLoader > ( ) { public ClassLoader run ( ) { return Thread . currentThread ( ) . getContextClassLoader ( ) ; } } ) ; } } } </s>
<s> package org . nju . artemis . aejb . component ; import java . lang . reflect . InvocationHandler ; import java . lang . reflect . Method ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . jboss . invocation . Interceptor ; import org . jboss . invocation . InterceptorContext ; import org . jboss . logging . Logger ; public class ContainerInvocationHandler implements InvocationHandler { Logger log = Logger . getLogger ( ContainerInvocationHandler . class ) ; private final Map < String , Object > contextData ; private final List < Interceptor > interceptors ; public ContainerInvocationHandler ( final String appName , final String moduleName , final String distinctName , final String beanName , final Class < ? > viewClass , boolean stateful , AcContainer container ) { final String aejbName = moduleName + "<STR_LIT:/>" + beanName ; contextData = new HashMap < String , Object > ( ) ; contextData . put ( "<STR_LIT>" , appName ) ; contextData . put ( "<STR_LIT>" , moduleName ) ; contextData . put ( "<STR_LIT>" , distinctName ) ; contextData . put ( "<STR_LIT>" , beanName ) ; contextData . put ( "<STR_LIT>" , viewClass ) ; contextData . put ( "<STR_LIT>" , stateful ) ; contextData . put ( "<STR_LIT>" , aejbName ) ; this . interceptors = container . getInterceptors ( ) ; } @ Override public Object invoke ( Object proxy , Method method , Object [ ] args ) throws Throwable { final InterceptorContext context = new InterceptorContext ( ) ; context . setInterceptors ( interceptors ) ; context . putPrivateData ( Object . class , proxy ) ; context . setParameters ( args ) ; context . setMethod ( method ) ; context . setContextData ( contextData ) ; return context . proceed ( ) ; } } </s>
<s> package org . nju . artemis . aejb . subsystem ; import java . util . List ; import org . jboss . as . controller . AbstractBoottimeAddStepHandler ; import org . jboss . as . controller . OperationContext ; import org . jboss . as . controller . OperationFailedException ; import org . jboss . as . controller . ServiceVerificationHandler ; import org . jboss . as . server . AbstractDeploymentChainStep ; import org . jboss . as . server . DeploymentProcessorTarget ; import org . jboss . dmr . ModelNode ; import org . jboss . logging . Logger ; import org . jboss . msc . service . ServiceController ; import org . jboss . msc . service . ServiceController . Mode ; import org . jboss . msc . service . ServiceName ; import org . nju . artemis . aejb . AEjbLogger ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . deployment . processors . AEjbInjectionAnnotationProcessor ; import org . nju . artemis . aejb . deployment . processors . AnnotatedAEJBComponentDescriptionProcessor ; import org . nju . artemis . aejb . deployment . processors . BusinessViewProcessor ; import org . nju . artemis . aejb . deployment . processors . SubsystemDeploymentProcessor ; import org . nju . artemis . aejb . deployment . processors . TransactionAnnotationProcessor ; import org . nju . artemis . aejb . evolution . DuService ; import org . nju . artemis . aejb . management . client . AEjbClientImpl ; public class AEJBSubsystemAdd extends AbstractBoottimeAddStepHandler { Logger log = Logger . getLogger ( AEJBSubsystemAdd . class ) ; static final AEJBSubsystemAdd INSTANCE = new AEJBSubsystemAdd ( ) ; static final String JAR_FILE_EXTENSION = "<STR_LIT>" ; private AEJBSubsystemAdd ( ) { } @ Override protected void performBoottime ( OperationContext context , ModelNode operation , ModelNode model , ServiceVerificationHandler verificationHandler , List < ServiceController < ? > > newControllers ) throws OperationFailedException { AEjbLogger . ROOT_LOGGER . activatingAEjbSubsystem ( ) ; context . addStep ( new AbstractDeploymentChainStep ( ) { public void execute ( DeploymentProcessorTarget processorTarget ) { processorTarget . addDeploymentProcessor ( SubsystemDeploymentProcessor . PHASE , SubsystemDeploymentProcessor . PRIORITY , new SubsystemDeploymentProcessor ( ) ) ; processorTarget . addDeploymentProcessor ( AnnotatedAEJBComponentDescriptionProcessor . PHASE , AnnotatedAEJBComponentDescriptionProcessor . PRIORITY , new AnnotatedAEJBComponentDescriptionProcessor ( ) ) ; processorTarget . addDeploymentProcessor ( AEjbInjectionAnnotationProcessor . PHASE , AEjbInjectionAnnotationProcessor . PRIORITY , new AEjbInjectionAnnotationProcessor ( ) ) ; processorTarget . addDeploymentProcessor ( TransactionAnnotationProcessor . PHASE , TransactionAnnotationProcessor . PRIORITY , new TransactionAnnotationProcessor ( ) ) ; processorTarget . addDeploymentProcessor ( BusinessViewProcessor . POST_MODULE , BusinessViewProcessor . PRIORITY , new BusinessViewProcessor ( ) ) ; } } , OperationContext . Stage . RUNTIME ) ; TrackerService service = new TrackerService ( JAR_FILE_EXTENSION , <NUM_LIT> ) ; ServiceName name = TrackerService . createServiceName ( JAR_FILE_EXTENSION ) ; ServiceController < TrackerService > controller = context . getServiceTarget ( ) . addService ( name , service ) . addListener ( verificationHandler ) . setInitialMode ( Mode . ACTIVE ) . install ( ) ; newControllers . add ( controller ) ; final AEjbUtilities aejbUtilities = new AEjbUtilities ( ) ; newControllers . add ( context . getServiceTarget ( ) . addService ( AEjbUtilities . SERVICE_NAME , aejbUtilities ) . setInitialMode ( ServiceController . Mode . ACTIVE ) . addListener ( verificationHandler ) . install ( ) ) ; final DuService duService = new DuService ( ) ; newControllers . add ( context . getServiceTarget ( ) . addService ( DuService . SERVICE_NAME , duService ) . addInjection ( duService . getAejbClientValue ( ) , AEjbClientImpl . INSTANCE ) . addDependency ( AEjbUtilities . SERVICE_NAME , AEjbUtilities . class , duService . getAejbUtilitiesValue ( ) ) . setInitialMode ( ServiceController . Mode . PASSIVE ) . addListener ( verificationHandler ) . install ( ) ) ; } @ Override protected void populateModel ( ModelNode operation , ModelNode model ) throws OperationFailedException { model . get ( "<STR_LIT>" ) . setEmptyObject ( ) ; } } </s>
<s> package org . nju . artemis . aejb . subsystem ; import java . util . Collections ; import java . util . HashSet ; import java . util . Set ; import java . util . concurrent . atomic . AtomicLong ; import org . jboss . logging . Logger ; import org . jboss . msc . service . Service ; import org . jboss . msc . service . ServiceName ; import org . jboss . msc . service . StartContext ; import org . jboss . msc . service . StartException ; import org . jboss . msc . service . StopContext ; public class TrackerService implements Service < TrackerService > { Logger log = Logger . getLogger ( TrackerService . class ) ; private AtomicLong tick = new AtomicLong ( <NUM_LIT> ) ; private Set < String > deployments = Collections . synchronizedSet ( new HashSet < String > ( ) ) ; private Set < String > coolDeployments = Collections . synchronizedSet ( new HashSet < String > ( ) ) ; private final String suffix ; private Thread OUTPUT = new Thread ( ) { @ Override public void run ( ) { while ( true ) { try { Thread . sleep ( tick . get ( ) ) ; log . info ( "<STR_LIT>" + suffix + "<STR_LIT>" + deployments + "<STR_LIT>" + coolDeployments . size ( ) ) ; } catch ( InterruptedException e ) { interrupted ( ) ; break ; } } } } ; public TrackerService ( String suffix , long tick ) { this . suffix = suffix ; this . tick . set ( tick ) ; } @ Override public TrackerService getValue ( ) throws IllegalStateException , IllegalArgumentException { return this ; } @ Override public void start ( StartContext context ) throws StartException { OUTPUT . start ( ) ; } @ Override public void stop ( StopContext context ) { OUTPUT . interrupt ( ) ; } public static ServiceName createServiceName ( String suffix ) { return ServiceName . JBOSS . append ( "<STR_LIT>" , suffix ) ; } public void addDeployment ( String name ) { deployments . add ( name ) ; } public void addCoolDeployment ( String name ) { coolDeployments . add ( name ) ; } public void removeDeployment ( String name ) { deployments . remove ( name ) ; coolDeployments . remove ( name ) ; } void setTick ( long tick ) { this . tick . set ( tick ) ; } public long getTick ( ) { return this . tick . get ( ) ; } } </s>
<s> package org . nju . artemis . aejb . subsystem ; import static org . jboss . as . controller . descriptions . ModelDescriptionConstants . CHILDREN ; import static org . jboss . as . controller . descriptions . ModelDescriptionConstants . DESCRIPTION ; import static org . jboss . as . controller . descriptions . ModelDescriptionConstants . HEAD_COMMENT_ALLOWED ; import static org . jboss . as . controller . descriptions . ModelDescriptionConstants . MODEL_DESCRIPTION ; import static org . jboss . as . controller . descriptions . ModelDescriptionConstants . NAMESPACE ; import static org . jboss . as . controller . descriptions . ModelDescriptionConstants . TAIL_COMMENT_ALLOWED ; import java . util . Locale ; import org . jboss . as . controller . descriptions . DescriptionProvider ; import org . jboss . dmr . ModelNode ; class AEJBSubsystemProviders { public static DescriptionProvider SUBSYSTEM = new DescriptionProvider ( ) { public ModelNode getModelDescription ( Locale locale ) { final ModelNode subsystem = new ModelNode ( ) ; subsystem . get ( DESCRIPTION ) . set ( "<STR_LIT>" ) ; subsystem . get ( HEAD_COMMENT_ALLOWED ) . set ( true ) ; subsystem . get ( TAIL_COMMENT_ALLOWED ) . set ( true ) ; subsystem . get ( NAMESPACE ) . set ( AEJBSubsystemExtension . NAMESPACE ) ; subsystem . get ( CHILDREN , "<STR_LIT>" , DESCRIPTION ) . set ( "<STR_LIT>" ) ; subsystem . get ( CHILDREN , "<STR_LIT>" , MODEL_DESCRIPTION ) ; return subsystem ; } } ; public static DescriptionProvider SUBSYSTEM_ADD = new DescriptionProvider ( ) { public ModelNode getModelDescription ( Locale locale ) { final ModelNode subsystem = new ModelNode ( ) ; subsystem . get ( DESCRIPTION ) . set ( "<STR_LIT>" ) ; return subsystem ; } } ; public static DescriptionProvider JNDI_CHILD = new DescriptionProvider ( ) { @ Override public ModelNode getModelDescription ( Locale locale ) { ModelNode node = new ModelNode ( ) ; node . get ( DESCRIPTION ) . set ( "<STR_LIT>" ) ; return node ; } } ; } </s>
<s> package org . nju . artemis . aejb . subsystem ; import static org . jboss . as . controller . descriptions . ModelDescriptionConstants . DESCRIPTION ; import java . util . List ; import java . util . Locale ; import org . jboss . as . controller . AbstractAddStepHandler ; import org . jboss . as . controller . OperationContext ; import org . jboss . as . controller . OperationFailedException ; import org . jboss . as . controller . PathAddress ; import org . jboss . as . controller . ServiceVerificationHandler ; import org . jboss . as . controller . descriptions . DescriptionProvider ; import org . jboss . as . controller . descriptions . ModelDescriptionConstants ; import org . jboss . as . naming . ManagedReference ; import org . jboss . as . naming . ManagedReferenceFactory ; import org . jboss . as . naming . ServiceBasedNamingStore ; import org . jboss . as . naming . ValueManagedReference ; import org . jboss . as . naming . deployment . ContextNames ; import org . jboss . as . naming . service . BinderService ; import org . jboss . dmr . ModelNode ; import org . jboss . logging . Logger ; import org . jboss . msc . service . AbstractServiceListener ; import org . jboss . msc . service . ServiceBuilder ; import org . jboss . msc . service . ServiceController ; import org . jboss . msc . service . ServiceName ; import org . jboss . msc . service . ServiceTarget ; import org . jboss . msc . value . ImmediateValue ; import org . nju . artemis . aejb . AEjbLogger ; import org . nju . artemis . aejb . management . client . AEjbClientService ; class ClientJndiBindingHandler extends AbstractAddStepHandler implements DescriptionProvider { Logger log = Logger . getLogger ( ClientJndiBindingHandler . class ) ; public static final ServiceName SERVICE_NAME_BASE = ServiceName . JBOSS . append ( "<STR_LIT>" ) ; public static final ClientJndiBindingHandler INSTANCE = new ClientJndiBindingHandler ( ) ; private ClientJndiBindingHandler ( ) { } @ Override public ModelNode getModelDescription ( Locale locale ) { ModelNode node = new ModelNode ( ) ; node . get ( DESCRIPTION ) . set ( "<STR_LIT>" ) ; return node ; } @ Override protected void populateModel ( ModelNode operation , ModelNode model ) throws OperationFailedException { } @ Override protected void performRuntime ( OperationContext context , ModelNode operation , ModelNode model , ServiceVerificationHandler verificationHandler , List < ServiceController < ? > > newControllers ) throws OperationFailedException { final ServiceTarget serviceTarget = context . getServiceTarget ( ) ; final String jndiName = PathAddress . pathAddress ( operation . get ( ModelDescriptionConstants . ADDRESS ) ) . getLastElement ( ) . getValue ( ) ; final AEjbClientService service = new AEjbClientService ( ) ; final ServiceName serviceName = SERVICE_NAME_BASE . append ( jndiName ) ; final ServiceBuilder < ? > aejbClientBuilder = serviceTarget . addService ( serviceName , service ) ; final ManagedReferenceFactory valueManagedReferenceFactory = new ManagedReferenceFactory ( ) { @ Override public ManagedReference getReference ( ) { return new ValueManagedReference ( new ImmediateValue < Object > ( service . getValue ( ) ) ) ; } } ; final ContextNames . BindInfo bindInfo = ContextNames . bindInfoFor ( jndiName ) ; final BinderService binderService = new BinderService ( bindInfo . getBindName ( ) ) ; final ServiceBuilder < ? > binderBuilder = serviceTarget . addService ( bindInfo . getBinderServiceName ( ) , binderService ) . addInjection ( binderService . getManagedObjectInjector ( ) , valueManagedReferenceFactory ) . addDependency ( bindInfo . getParentContextServiceName ( ) , ServiceBasedNamingStore . class , binderService . getNamingStoreInjector ( ) ) . addListener ( new AbstractServiceListener < Object > ( ) { public void transition ( final ServiceController < ? extends Object > controller , final ServiceController . Transition transition ) { switch ( transition ) { case STARTING_to_UP : { AEjbLogger . ROOT_LOGGER . boundClientService ( jndiName ) ; break ; } case START_REQUESTED_to_DOWN : { AEjbLogger . ROOT_LOGGER . unboundClientService ( jndiName ) ; break ; } case REMOVING_to_REMOVED : { AEjbLogger . ROOT_LOGGER . removeClientService ( jndiName ) ; break ; } } } } ) ; aejbClientBuilder . setInitialMode ( ServiceController . Mode . ACTIVE ) . addListener ( verificationHandler ) ; binderBuilder . setInitialMode ( ServiceController . Mode . ACTIVE ) . addListener ( verificationHandler ) ; newControllers . add ( aejbClientBuilder . install ( ) ) ; newControllers . add ( binderBuilder . install ( ) ) ; } } </s>
<s> package org . nju . artemis . aejb . subsystem ; import static org . jboss . as . controller . descriptions . ModelDescriptionConstants . ADD ; import static org . jboss . as . controller . descriptions . ModelDescriptionConstants . DESCRIBE ; import static org . jboss . as . controller . descriptions . ModelDescriptionConstants . OP ; import static org . jboss . as . controller . descriptions . ModelDescriptionConstants . OP_ADDR ; import static org . jboss . as . controller . descriptions . ModelDescriptionConstants . SUBSYSTEM ; import java . util . Collections ; import java . util . List ; import java . util . Locale ; import javax . xml . stream . XMLStreamConstants ; import javax . xml . stream . XMLStreamException ; import org . jboss . as . controller . Extension ; import org . jboss . as . controller . ExtensionContext ; import org . jboss . as . controller . OperationContext ; import org . jboss . as . controller . OperationFailedException ; import org . jboss . as . controller . OperationStepHandler ; import org . jboss . as . controller . PathAddress ; import org . jboss . as . controller . PathElement ; import org . jboss . as . controller . SubsystemRegistration ; import org . jboss . as . controller . descriptions . DescriptionProvider ; import org . jboss . as . controller . descriptions . ModelDescriptionConstants ; import org . jboss . as . controller . descriptions . common . CommonDescriptions ; import org . jboss . as . controller . parsing . ExtensionParsingContext ; import org . jboss . as . controller . parsing . ParseUtils ; import org . jboss . as . controller . persistence . SubsystemMarshallingContext ; import org . jboss . as . controller . registry . ManagementResourceRegistration ; import org . jboss . as . controller . registry . OperationEntry ; import org . jboss . dmr . ModelNode ; import org . jboss . dmr . Property ; import org . jboss . logging . Logger ; import org . jboss . staxmapper . XMLElementReader ; import org . jboss . staxmapper . XMLElementWriter ; import org . jboss . staxmapper . XMLExtendedStreamReader ; import org . jboss . staxmapper . XMLExtendedStreamWriter ; public class AEJBSubsystemExtension implements Extension { Logger log = Logger . getLogger ( AEJBSubsystemExtension . class ) ; public static final String NAMESPACE = "<STR_LIT>" ; public static final String SUBSYSTEM_NAME = "<STR_LIT>" ; private final AEJBSubsystemParser parser = new AEJBSubsystemParser ( ) ; public void initialize ( ExtensionContext context ) { final SubsystemRegistration subsystem = context . registerSubsystem ( SUBSYSTEM_NAME ) ; final ManagementResourceRegistration registration = subsystem . registerSubsystemModel ( AEJBSubsystemProviders . SUBSYSTEM ) ; registration . registerOperationHandler ( ADD , AEJBSubsystemAdd . INSTANCE , AEJBSubsystemProviders . SUBSYSTEM_ADD , false ) ; registration . registerOperationHandler ( DESCRIBE , AEJBSubsystemDescribeHandler . INSTANCE , AEJBSubsystemDescribeHandler . INSTANCE , false , OperationEntry . EntryType . PRIVATE ) ; ManagementResourceRegistration jndiChild = registration . registerSubModel ( PathElement . pathElement ( "<STR_LIT>" ) , AEJBSubsystemProviders . JNDI_CHILD ) ; jndiChild . registerOperationHandler ( ModelDescriptionConstants . ADD , ClientJndiBindingHandler . INSTANCE , ClientJndiBindingHandler . INSTANCE ) ; subsystem . registerXMLElementWriter ( parser ) ; } @ SuppressWarnings ( "<STR_LIT:deprecation>" ) public void initializeParsers ( ExtensionParsingContext context ) { context . setSubsystemXmlMapping ( NAMESPACE , parser ) ; } private static ModelNode createAEJBSubsystemOperation ( ) { final ModelNode subsystem = new ModelNode ( ) ; subsystem . get ( OP ) . set ( ADD ) ; subsystem . get ( OP_ADDR ) . add ( SUBSYSTEM , SUBSYSTEM_NAME ) ; return subsystem ; } private static class AEJBSubsystemParser implements XMLStreamConstants , XMLElementReader < List < ModelNode > > , XMLElementWriter < SubsystemMarshallingContext > { @ Override public void readElement ( XMLExtendedStreamReader reader , List < ModelNode > list ) throws XMLStreamException { ParseUtils . requireNoAttributes ( reader ) ; list . add ( createAEJBSubsystemOperation ( ) ) ; while ( reader . hasNext ( ) && reader . nextTag ( ) != END_ELEMENT ) { if ( ! reader . getLocalName ( ) . equals ( "<STR_LIT>" ) ) { throw ParseUtils . unexpectedElement ( reader ) ; } if ( reader . getLocalName ( ) . equals ( "<STR_LIT>" ) ) readClientService ( reader , list ) ; while ( reader . hasNext ( ) && reader . nextTag ( ) != END_ELEMENT ) { } } } private void readClientService ( XMLExtendedStreamReader reader , List < ModelNode > list ) throws XMLStreamException { String jndiName = null ; for ( int i = <NUM_LIT:0> ; i < reader . getAttributeCount ( ) ; i ++ ) { String attr = reader . getAttributeLocalName ( i ) ; if ( attr . equals ( "<STR_LIT>" ) ) { jndiName = reader . getAttributeValue ( i ) ; } else { throw ParseUtils . unexpectedAttribute ( reader , i ) ; } } ParseUtils . requireNoContent ( reader ) ; if ( jndiName == null ) { throw ParseUtils . missingRequiredElement ( reader , Collections . singleton ( "<STR_LIT>" ) ) ; } ModelNode addType = new ModelNode ( ) ; addType . get ( OP ) . set ( ModelDescriptionConstants . ADD ) ; PathAddress addr = PathAddress . pathAddress ( PathElement . pathElement ( SUBSYSTEM , SUBSYSTEM_NAME ) , PathElement . pathElement ( "<STR_LIT>" , jndiName ) ) ; addType . get ( OP_ADDR ) . set ( addr . toModelNode ( ) ) ; list . add ( addType ) ; } @ Override public void writeContent ( final XMLExtendedStreamWriter writer , final SubsystemMarshallingContext context ) throws XMLStreamException { context . startSubsystemElement ( AEJBSubsystemExtension . NAMESPACE , false ) ; writer . writeStartElement ( "<STR_LIT>" ) ; ModelNode node = context . getModelNode ( ) ; ModelNode jndiName = node . get ( "<STR_LIT>" ) ; for ( Property property : jndiName . asPropertyList ( ) ) { writer . writeAttribute ( "<STR_LIT>" , property . getName ( ) ) ; } writer . writeEndElement ( ) ; writer . writeEndElement ( ) ; } } private static class AEJBSubsystemDescribeHandler implements OperationStepHandler , DescriptionProvider { static final AEJBSubsystemDescribeHandler INSTANCE = new AEJBSubsystemDescribeHandler ( ) ; public void execute ( OperationContext context , ModelNode operation ) throws OperationFailedException { context . getResult ( ) . add ( createAEJBSubsystemOperation ( ) ) ; ModelNode node = context . readModel ( PathAddress . EMPTY_ADDRESS ) ; for ( Property property : node . get ( "<STR_LIT>" ) . asPropertyList ( ) ) { ModelNode addType = new ModelNode ( ) ; addType . get ( OP ) . set ( ModelDescriptionConstants . ADD ) ; PathAddress addr = PathAddress . pathAddress ( PathElement . pathElement ( SUBSYSTEM , SUBSYSTEM_NAME ) , PathElement . pathElement ( "<STR_LIT>" , property . getName ( ) ) ) ; addType . get ( OP_ADDR ) . set ( addr . toModelNode ( ) ) ; context . getResult ( ) . add ( addType ) ; } context . completeStep ( ) ; } @ Override public ModelNode getModelDescription ( Locale locale ) { return CommonDescriptions . getSubsystemDescribeOperation ( locale ) ; } } } </s>
<s> package org . nju . artemis . aejb . deployment . processors ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import javax . aejb . Transaction ; import org . jboss . as . ee . component . Attachments ; import org . jboss . as . ee . component . BindingConfiguration ; import org . jboss . as . ee . component . EEModuleClassDescription ; import org . jboss . as . ee . component . EEModuleDescription ; import org . jboss . as . ee . component . InjectionSource ; import org . jboss . as . naming . ManagedReference ; import org . jboss . as . naming . ManagedReferenceFactory ; import org . jboss . as . naming . ValueManagedReference ; import org . jboss . as . server . deployment . DeploymentPhaseContext ; import org . jboss . as . server . deployment . DeploymentUnit ; import org . jboss . as . server . deployment . DeploymentUnitProcessingException ; import org . jboss . as . server . deployment . DeploymentUnitProcessor ; import org . jboss . as . server . deployment . Phase ; import org . jboss . as . server . deployment . annotation . CompositeIndex ; import org . jboss . jandex . AnnotationInstance ; import org . jboss . jandex . AnnotationTarget ; import org . jboss . jandex . AnnotationValue ; import org . jboss . jandex . ClassInfo ; import org . jboss . jandex . DotName ; import org . jboss . jandex . MethodInfo ; import org . jboss . logging . Logger ; import org . jboss . msc . inject . Injector ; import org . jboss . msc . service . ServiceBuilder ; import org . jboss . msc . value . ImmediateValue ; import org . nju . artemis . aejb . AEjbLogger ; import org . nju . artemis . aejb . component . AcContainer ; import org . nju . artemis . aejb . deployment . transaction . TransactionState ; import org . nju . artemis . aejb . deployment . transaction . TransactionManagerImpl ; public class TransactionAnnotationProcessor implements DeploymentUnitProcessor { Logger log = Logger . getLogger ( TransactionAnnotationProcessor . class ) ; private static final DotName TRANSACTION_ANNOTATION = DotName . createSimple ( Transaction . class . getName ( ) ) ; public static final Phase PHASE = Phase . PARSE ; public static final int PRIORITY = <NUM_LIT> ; private AcContainer container ; @ Override public void deploy ( DeploymentPhaseContext phaseContext ) throws DeploymentUnitProcessingException { log . debug ( "<STR_LIT>" ) ; final DeploymentUnit deploymentUnit = phaseContext . getDeploymentUnit ( ) ; final Map < String , AcContainer > aejbInfo = deploymentUnit . getAttachment ( org . nju . artemis . aejb . deployment . Attachments . AEJB_INFO ) ; final CompositeIndex index = deploymentUnit . getAttachment ( org . jboss . as . server . deployment . Attachments . COMPOSITE_ANNOTATION_INDEX ) ; final EEModuleDescription moduleDescription = deploymentUnit . getAttachment ( Attachments . EE_MODULE_DESCRIPTION ) ; final List < AnnotationInstance > aejbAnnotations = index . getAnnotations ( TRANSACTION_ANNOTATION ) ; for ( final AnnotationInstance aejbAnnotation : aejbAnnotations ) { final AnnotationTarget target = aejbAnnotation . target ( ) ; if ( ! ( target instanceof MethodInfo ) ) { log . warn ( aejbAnnotation . name ( ) + "<STR_LIT>" + target + "<STR_LIT>" ) ; continue ; } String beanName = ( ( MethodInfo ) target ) . declaringClass ( ) . name ( ) . local ( ) ; if ( ! aejbInfo . containsKey ( beanName ) ) { log . warn ( aejbAnnotation . name ( ) + "<STR_LIT>" + beanName + "<STR_LIT>" ) ; continue ; } container = aejbInfo . get ( beanName ) ; final TransactionResourceWrapper annotationWrapper = new TransactionResourceWrapper ( aejbAnnotation ) ; if ( annotationWrapper . states ( ) == null ) { log . warn ( aejbAnnotation . name ( ) + "<STR_LIT>" ) ; return ; } try { processTransaction ( annotationWrapper , ( MethodInfo ) target , moduleDescription ) ; } catch ( TransactionProcessFailedException e ) { e . printStackTrace ( ) ; return ; } } } private void processTransaction ( TransactionResourceWrapper annotationWrapper , MethodInfo method , final EEModuleDescription eeModuleDescription ) throws TransactionProcessFailedException { int states_count = annotationWrapper . states ( ) . length ; if ( states_count == <NUM_LIT:1> ) { log . warn ( annotationWrapper . name ( ) + "<STR_LIT>" ) ; return ; } else if ( states_count != annotationWrapper . next ( ) . length + <NUM_LIT:1> ) throw new TransactionProcessFailedException ( "<STR_LIT>" ) ; TransactionState [ ] states = new TransactionState [ states_count ] ; Map [ ] nextStates = new HashMap [ states_count - <NUM_LIT:1> ] ; for ( int i = <NUM_LIT:0> ; i < states_count - <NUM_LIT:1> ; i ++ ) nextStates [ i ] = new HashMap < String , String > ( ) ; List < String > portNames = new ArrayList < String > ( ) ; for ( int i = <NUM_LIT:0> ; i < states_count ; i ++ ) { String [ ] passedPorts = null , futurePorts = null ; String [ ] portz = annotationWrapper . states ( ) [ i ] . split ( "<STR_LIT:;>" ) ; int pLength = portz . length ; if ( pLength > <NUM_LIT:2> ) { throw new TransactionProcessFailedException ( "<STR_LIT>" ) ; } for ( int index = <NUM_LIT:0> ; index < pLength ; index ++ ) { String [ ] ports = portz [ index ] . split ( "<STR_LIT:U+002C>" ) ; if ( index == <NUM_LIT:0> ) passedPorts = ports ; else futurePorts = ports ; } for ( String port : passedPorts ) { if ( ! portNames . contains ( port ) ) portNames . add ( port ) ; } TransactionState s = new TransactionState ( passedPorts , futurePorts ) ; states [ i ] = s ; if ( i == states_count - <NUM_LIT:1> ) continue ; String [ ] nexts = annotationWrapper . next ( ) [ i ] . split ( "<STR_LIT:U+002C>" ) ; for ( String next : nexts ) { if ( next != null && ! next . equals ( "<STR_LIT>" ) ) { String [ ] n = next . split ( "<STR_LIT:->" ) ; if ( n . length != <NUM_LIT:2> ) throw new TransactionProcessFailedException ( "<STR_LIT>" ) ; nextStates [ i ] . put ( n [ <NUM_LIT:0> ] , n [ <NUM_LIT:1> ] ) ; } } } final int size = portNames . size ( ) ; TransactionManager tm = new TransactionManagerImpl ( annotationWrapper . name ( ) , method . name ( ) , portNames . toArray ( new String [ size ] ) , states , nextStates ) ; container . setTransactionManager ( tm ) ; bindTransactionManager ( tm , method . declaringClass ( ) , eeModuleDescription ) ; } private void bindTransactionManager ( final TransactionManager tm , final ClassInfo classInfo , final EEModuleDescription eeModuleDescription ) { final EEModuleClassDescription classDescription = eeModuleDescription . addOrGetLocalClassDescription ( classInfo . name ( ) . toString ( ) ) ; final ManagedReferenceFactory valueManagedReferenceFactory = new ManagedReferenceFactory ( ) { @ Override public ManagedReference getReference ( ) { return new ValueManagedReference ( new ImmediateValue < Object > ( tm ) ) ; } } ; final String jndiName = "<STR_LIT>" + tm . getName ( ) ; final BindingConfiguration bindingConfiguration = new BindingConfiguration ( jndiName , new InjectionSource ( ) { @ Override public void getResourceValue ( ResolutionContext arg0 , ServiceBuilder < ? > builder , DeploymentPhaseContext arg2 , Injector < ManagedReferenceFactory > injector ) throws DeploymentUnitProcessingException { injector . inject ( valueManagedReferenceFactory ) ; AEjbLogger . ROOT_LOGGER . boundTransactionManager ( jndiName ) ; } } ) ; classDescription . getBindingConfigurations ( ) . add ( bindingConfiguration ) ; } @ Override public void undeploy ( DeploymentUnit arg0 ) { } private class TransactionResourceWrapper { private final String name ; private final String [ ] states ; private final String [ ] next ; private TransactionResourceWrapper ( final AnnotationInstance annotation ) { name = stringValueOrNull ( annotation , "<STR_LIT:name>" ) ; states = arrayValueOrNull ( annotation , "<STR_LIT>" ) ; next = arrayValueOrNull ( annotation , "<STR_LIT>" ) ; } private String name ( ) { return name ; } private String [ ] states ( ) { return states ; } private String [ ] next ( ) { return next ; } private String stringValueOrNull ( final AnnotationInstance annotation , final String attribute ) { final AnnotationValue value = annotation . value ( attribute ) ; return value != null ? value . asString ( ) : null ; } private String [ ] arrayValueOrNull ( final AnnotationInstance annotation , final String attribute ) { final AnnotationValue value = annotation . value ( attribute ) ; return value != null ? value . asStringArray ( ) : null ; } } } </s>
<s> package org . nju . artemis . aejb . deployment . processors ; import java . util . List ; import javax . aejb . TransactionTrigger ; public interface TransactionManager extends TransactionTrigger { String toString ( ) ; int getRunNumber ( ) ; String getName ( ) ; boolean isActive ( ) ; boolean isActive ( String objectId ) ; List < String > getAffectedPorts ( ) ; List < String > getAffectedPorts ( String objectId ) ; String [ ] getInvolvedPorts ( ) ; String getTransactionMethodName ( ) ; void createTransaction ( String objectId ) ; void destroyTransaction ( String objectId ) ; List < String > getPassedPorts ( String objectId ) ; List < String > getFuturePorts ( String objectId ) ; } </s>
<s> package org . nju . artemis . aejb . deployment . processors ; import static org . jboss . as . ee . component . Attachments . EE_MODULE_DESCRIPTION ; import java . util . Collection ; import java . util . Map ; import javax . ejb . Local ; import javax . ejb . Remote ; import org . jboss . as . ee . component . ComponentDescription ; import org . jboss . as . ee . component . EEModuleDescription ; import org . jboss . as . ee . component . ViewDescription ; import org . jboss . as . ejb3 . component . EJBViewDescription ; import org . jboss . as . ejb3 . component . MethodIntf ; import org . jboss . as . ejb3 . component . session . SessionBeanComponentDescription ; import org . jboss . as . server . deployment . DeploymentPhaseContext ; import org . jboss . as . server . deployment . DeploymentUnit ; import org . jboss . as . server . deployment . DeploymentUnitProcessingException ; import org . jboss . as . server . deployment . DeploymentUnitProcessor ; import org . jboss . as . server . deployment . Phase ; import org . jboss . logging . Logger ; import org . jboss . modules . Module ; import org . nju . artemis . aejb . component . AcContainer ; public class BusinessViewProcessor implements DeploymentUnitProcessor { private static final Logger logger = Logger . getLogger ( BusinessViewProcessor . class ) ; public static final Phase POST_MODULE = Phase . POST_MODULE ; public static final int PRIORITY = <NUM_LIT> ; @ Override public void deploy ( DeploymentPhaseContext phaseContext ) throws DeploymentUnitProcessingException { logger . info ( "<STR_LIT>" ) ; final DeploymentUnit deploymentUnit = phaseContext . getDeploymentUnit ( ) ; final EEModuleDescription eeModuleDescription = deploymentUnit . getAttachment ( EE_MODULE_DESCRIPTION ) ; final Map < String , AcContainer > aejbInfo = deploymentUnit . getAttachment ( org . nju . artemis . aejb . deployment . Attachments . AEJB_INFO ) ; final Collection < ComponentDescription > componentDescriptions = eeModuleDescription . getComponentDescriptions ( ) ; final Module module = deploymentUnit . getAttachment ( org . jboss . as . server . deployment . Attachments . MODULE ) ; if ( aejbInfo == null || module == null ) { return ; } final ClassLoader moduleClassLoader = module . getClassLoader ( ) ; if ( componentDescriptions != null ) { for ( ComponentDescription componentDescription : componentDescriptions ) { if ( componentDescription instanceof SessionBeanComponentDescription == false || aejbInfo . containsKey ( componentDescription . getComponentName ( ) ) == false ) { continue ; } for ( ViewDescription view : componentDescription . getViews ( ) ) { if ( view instanceof EJBViewDescription == false ) continue ; final Class < ? > viewClass ; try { viewClass = moduleClassLoader . loadClass ( view . getViewClassName ( ) ) ; } catch ( ClassNotFoundException e ) { throw new DeploymentUnitProcessingException ( "<STR_LIT>" + view . getViewClassName ( ) + "<STR_LIT>" , e ) ; } logger . info ( "<STR_LIT>" + view . getViewClassName ( ) ) ; final MethodIntf intf = ( ( EJBViewDescription ) view ) . getMethodIntf ( ) ; final AcContainer container = aejbInfo . get ( componentDescription . getComponentName ( ) ) ; if ( intf == MethodIntf . LOCAL ) { container . setLocalView ( viewClass ) ; } else if ( intf == MethodIntf . REMOTE ) { container . setRemoteView ( viewClass ) ; } } } } logger . info ( "<STR_LIT>" ) ; } @ Override public void undeploy ( DeploymentUnit context ) { } } </s>
<s> package org . nju . artemis . aejb . deployment . processors ; import org . jboss . dmr . ModelNode ; public class TransactionProcessFailedException extends Exception { private static final long serialVersionUID = <NUM_LIT> ; private final ModelNode failureDescription ; public TransactionProcessFailedException ( final String msg , final ModelNode description ) { super ( msg ) ; failureDescription = description ; } public TransactionProcessFailedException ( final String message ) { this ( message , new ModelNode ( message ) ) ; } @ Override public String toString ( ) { return super . toString ( ) + "<STR_LIT>" + failureDescription + "<STR_LIT>" ; } } </s>
<s> package org . nju . artemis . aejb . deployment . processors ; import java . util . List ; import java . util . Map ; import javax . aejb . AEjb ; import org . jboss . as . ee . component . Attachments ; import org . jboss . as . ee . component . BindingConfiguration ; import org . jboss . as . ee . component . EEModuleClassDescription ; import org . jboss . as . ee . component . EEModuleDescription ; import org . jboss . as . ee . component . FieldInjectionTarget ; import org . jboss . as . ee . component . InjectionTarget ; import org . jboss . as . ee . component . ResourceInjectionConfiguration ; import org . jboss . as . server . deployment . DeploymentPhaseContext ; import org . jboss . as . server . deployment . DeploymentUnit ; import org . jboss . as . server . deployment . DeploymentUnitProcessingException ; import org . jboss . as . server . deployment . DeploymentUnitProcessor ; import org . jboss . as . server . deployment . Phase ; import org . jboss . as . server . deployment . annotation . CompositeIndex ; import org . jboss . jandex . AnnotationInstance ; import org . jboss . jandex . AnnotationTarget ; import org . jboss . jandex . AnnotationValue ; import org . jboss . jandex . ClassInfo ; import org . jboss . jandex . DotName ; import org . jboss . jandex . FieldInfo ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AcContainer ; public class AEjbInjectionAnnotationProcessor implements DeploymentUnitProcessor { Logger log = Logger . getLogger ( AEjbInjectionAnnotationProcessor . class ) ; private static final DotName AEJB_ANNOTATION = DotName . createSimple ( AEjb . class . getName ( ) ) ; public static final Phase PHASE = Phase . PARSE ; public static final int PRIORITY = <NUM_LIT> ; private AcContainer container ; @ Override public void deploy ( DeploymentPhaseContext phaseContext ) throws DeploymentUnitProcessingException { log . debug ( "<STR_LIT>" ) ; final DeploymentUnit deploymentUnit = phaseContext . getDeploymentUnit ( ) ; final Map < String , AcContainer > aejbInfo = deploymentUnit . getAttachment ( org . nju . artemis . aejb . deployment . Attachments . AEJB_INFO ) ; final CompositeIndex index = deploymentUnit . getAttachment ( org . jboss . as . server . deployment . Attachments . COMPOSITE_ANNOTATION_INDEX ) ; final EEModuleDescription moduleDescription = deploymentUnit . getAttachment ( Attachments . EE_MODULE_DESCRIPTION ) ; final List < AnnotationInstance > aejbAnnotations = index . getAnnotations ( AEJB_ANNOTATION ) ; for ( final AnnotationInstance aejbAnnotation : aejbAnnotations ) { final AnnotationTarget target = aejbAnnotation . target ( ) ; if ( ! ( target instanceof FieldInfo ) ) { log . warn ( aejbAnnotation . name ( ) + "<STR_LIT>" + target + "<STR_LIT>" ) ; continue ; } String beanName = ( ( FieldInfo ) target ) . declaringClass ( ) . name ( ) . local ( ) ; if ( ! aejbInfo . containsKey ( beanName ) ) { log . warn ( aejbAnnotation . name ( ) + "<STR_LIT>" + beanName + "<STR_LIT>" ) ; continue ; } container = aejbInfo . get ( beanName ) ; final AEJBResourceWrapper annotationWrapper = new AEJBResourceWrapper ( aejbAnnotation ) ; processField ( deploymentUnit , annotationWrapper , ( FieldInfo ) target , moduleDescription ) ; } } private void processField ( final DeploymentUnit deploymentUnit , final AEJBResourceWrapper annotation , final FieldInfo fieldInfo , final EEModuleDescription eeModuleDescription ) { final String fieldName = fieldInfo . name ( ) ; final String fieldType = fieldInfo . type ( ) . name ( ) . toString ( ) ; final InjectionTarget targetDescription = new FieldInjectionTarget ( fieldInfo . declaringClass ( ) . name ( ) . toString ( ) , fieldName , fieldType ) ; final String localContextName = isEmpty ( annotation . name ( ) ) ? fieldInfo . declaringClass ( ) . name ( ) . toString ( ) + "<STR_LIT:/>" + fieldInfo . name ( ) : annotation . name ( ) ; final String beanInterfaceType = isEmpty ( annotation . beanInterface ( ) ) || annotation . beanInterface ( ) . equals ( Object . class . getName ( ) ) ? fieldType : annotation . beanInterface ( ) ; process ( deploymentUnit , beanInterfaceType , annotation . beanName ( ) , annotation . lookup ( ) , fieldInfo . declaringClass ( ) , targetDescription , localContextName , eeModuleDescription ) ; } private void process ( final DeploymentUnit deploymentUnit , final String beanInterface , final String beanName , final String lookup , final ClassInfo classInfo , final InjectionTarget targetDescription , final String localContextName , final EEModuleDescription eeModuleDescription ) { if ( ! isEmpty ( lookup ) && ! isEmpty ( beanName ) ) { log . debug ( "<STR_LIT>" + beanName + "<STR_LIT>" + lookup + "<STR_LIT>" + "<STR_LIT>" + classInfo . name ( ) ) ; } final EEModuleClassDescription classDescription = eeModuleDescription . addOrGetLocalClassDescription ( classInfo . name ( ) . toString ( ) ) ; final AejbInjectionSource aejbInjectionSource ; if ( ! isEmpty ( lookup ) ) { if ( ! isEmpty ( beanName ) ) { aejbInjectionSource = new AejbInjectionSource ( lookup , beanName , beanInterface , localContextName , deploymentUnit , container ) ; } else { aejbInjectionSource = new AejbInjectionSource ( lookup , null , beanInterface , localContextName , deploymentUnit , container ) ; } } else { if ( ! isEmpty ( beanName ) ) { aejbInjectionSource = new AejbInjectionSource ( beanName , beanInterface , localContextName , deploymentUnit , container ) ; } else { aejbInjectionSource = new AejbInjectionSource ( null , beanInterface , localContextName , deploymentUnit , container ) ; } } final ResourceInjectionConfiguration injectionConfiguration = targetDescription != null ? new ResourceInjectionConfiguration ( targetDescription , aejbInjectionSource ) : null ; final BindingConfiguration bindingConfiguration = new BindingConfiguration ( localContextName , aejbInjectionSource ) ; classDescription . getBindingConfigurations ( ) . add ( bindingConfiguration ) ; if ( injectionConfiguration != null ) { classDescription . addResourceInjection ( injectionConfiguration ) ; } } @ Override public void undeploy ( DeploymentUnit context ) { } private boolean isEmpty ( final String string ) { return string == null || string . isEmpty ( ) ; } private class AEJBResourceWrapper { private final String name ; private final String beanInterface ; private final String beanName ; private final String lookup ; private final String description ; private AEJBResourceWrapper ( final AnnotationInstance annotation ) { name = stringValueOrNull ( annotation , "<STR_LIT:name>" ) ; beanInterface = classValueOrNull ( annotation , "<STR_LIT>" ) ; beanName = stringValueOrNull ( annotation , "<STR_LIT>" ) ; String lookupValue = stringValueOrNull ( annotation , "<STR_LIT>" ) ; if ( isEmpty ( lookupValue ) ) { lookupValue = stringValueOrNull ( annotation , "<STR_LIT>" ) ; } this . lookup = lookupValue ; description = stringValueOrNull ( annotation , "<STR_LIT:description>" ) ; } private String name ( ) { return name ; } private String beanInterface ( ) { return beanInterface ; } private String beanName ( ) { return beanName ; } private String lookup ( ) { return lookup ; } private String description ( ) { return description ; } private String stringValueOrNull ( final AnnotationInstance annotation , final String attribute ) { final AnnotationValue value = annotation . value ( attribute ) ; return value != null ? value . asString ( ) : null ; } private String classValueOrNull ( final AnnotationInstance annotation , final String attribute ) { final AnnotationValue value = annotation . value ( attribute ) ; return value != null ? value . asClass ( ) . name ( ) . toString ( ) : null ; } } } </s>
<s> package org . nju . artemis . aejb . deployment . processors ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Set ; import javax . aejb . Adaptive ; import org . jboss . as . ee . component . ComponentDescription ; import org . jboss . as . ee . component . EEModuleDescription ; import org . jboss . as . ejb3 . component . session . SessionBeanComponentDescription ; import org . jboss . as . ejb3 . component . session . SessionBeanComponentDescription . SessionBeanType ; import org . jboss . as . ejb3 . deployment . EjbDeploymentMarker ; import org . jboss . as . server . deployment . Attachments ; import org . jboss . as . server . deployment . DeploymentPhaseContext ; import org . jboss . as . server . deployment . DeploymentUnit ; import org . jboss . as . server . deployment . DeploymentUnitProcessingException ; import org . jboss . as . server . deployment . DeploymentUnitProcessor ; import org . jboss . as . server . deployment . Phase ; import org . jboss . as . server . deployment . annotation . CompositeIndex ; import org . jboss . jandex . AnnotationInstance ; import org . jboss . jandex . AnnotationTarget ; import org . jboss . jandex . ClassInfo ; import org . jboss . jandex . DotName ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . component . AcContainer ; public class AnnotatedAEJBComponentDescriptionProcessor implements DeploymentUnitProcessor { Logger log = Logger . getLogger ( AnnotatedAEJBComponentDescriptionProcessor . class ) ; private static final DotName ADAPTIVE_ANNOTATION = DotName . createSimple ( Adaptive . class . getName ( ) ) ; public static final Phase PHASE = Phase . PARSE ; public static final int PRIORITY = <NUM_LIT> ; public String unitName ; @ Override public void deploy ( DeploymentPhaseContext phaseContext ) throws DeploymentUnitProcessingException { log . debug ( "<STR_LIT>" ) ; final DeploymentUnit deploymentUnit = phaseContext . getDeploymentUnit ( ) ; if ( ! EjbDeploymentMarker . isEjbDeployment ( deploymentUnit ) ) return ; final CompositeIndex compositeIndex = deploymentUnit . getAttachment ( Attachments . COMPOSITE_ANNOTATION_INDEX ) ; if ( compositeIndex == null ) return ; final List < AnnotationInstance > adpAnnotations = compositeIndex . getAnnotations ( ADAPTIVE_ANNOTATION ) ; if ( adpAnnotations . isEmpty ( ) ) return ; final Set < String > aejbClassInfo = getAEJBClassInfo ( adpAnnotations ) ; Map < String , AcContainer > aejbInfo = new HashMap < String , AcContainer > ( ) ; this . unitName = deploymentUnit . getName ( ) ; final EEModuleDescription moduleDescription = deploymentUnit . getAttachment ( org . jboss . as . ee . component . Attachments . EE_MODULE_DESCRIPTION ) ; for ( ComponentDescription beanDescription : moduleDescription . getComponentDescriptions ( ) ) { if ( ! ( beanDescription instanceof SessionBeanComponentDescription ) ) continue ; String beanClass = beanDescription . getComponentName ( ) ; if ( ! aejbClassInfo . contains ( beanClass ) ) continue ; SessionBeanComponentDescription sessionBeanDescription = ( SessionBeanComponentDescription ) beanDescription ; String appName = moduleDescription . getEarApplicationName ( ) ; String moduleName = sessionBeanDescription . getModuleName ( ) ; String beanName = sessionBeanDescription . getEJBName ( ) ; String distinctName = moduleDescription . getDistinctName ( ) ; SessionBeanType beanType = sessionBeanDescription . getSessionBeanType ( ) ; AcContainer accon = new AcContainer ( appName , moduleName , beanName , distinctName , beanType ) ; AEjbUtilities . registerAEJB ( unitName , accon ) ; aejbInfo . put ( beanClass , accon ) ; } deploymentUnit . putAttachment ( org . nju . artemis . aejb . deployment . Attachments . AEJB_INFO , aejbInfo ) ; } @ Override public void undeploy ( DeploymentUnit deploymentUnit ) { AEjbUtilities . removeDeploymentUnit ( deploymentUnit . getName ( ) ) ; } private Set < String > getAEJBClassInfo ( List < AnnotationInstance > adpAnnotations ) { Set < String > aejbClassInfo = new HashSet < String > ( ) ; for ( final AnnotationInstance adpAnnotation : adpAnnotations ) { final AnnotationTarget target = adpAnnotation . target ( ) ; if ( ! ( target instanceof ClassInfo ) ) { log . warn ( adpAnnotation . name ( ) + "<STR_LIT>" + target + "<STR_LIT>" ) ; continue ; } aejbClassInfo . add ( ( ( ClassInfo ) target ) . name ( ) . local ( ) ) ; } return aejbClassInfo ; } } </s>
<s> package org . nju . artemis . aejb . deployment . processors ; import static org . jboss . as . ee . component . Attachments . EE_APPLICATION_DESCRIPTION ; import java . util . HashSet ; import java . util . Set ; import org . jboss . as . ee . component . EEApplicationDescription ; import org . jboss . as . ee . component . EEModuleDescription ; import org . jboss . as . ee . component . InjectionSource ; import org . jboss . as . ee . component . ViewDescription ; import org . jboss . as . ejb3 . EjbMessages ; import org . jboss . as . ejb3 . component . EJBComponentDescription ; import org . jboss . as . ejb3 . component . EJBViewDescription ; import org . jboss . as . naming . ManagedReferenceFactory ; import org . jboss . as . server . deployment . Attachments ; import org . jboss . as . server . deployment . DeploymentPhaseContext ; import org . jboss . as . server . deployment . DeploymentUnit ; import org . jboss . as . server . deployment . DeploymentUnitProcessingException ; import org . jboss . as . server . deployment . module . ResourceRoot ; import org . jboss . logging . Logger ; import org . jboss . msc . inject . Injector ; import org . jboss . msc . service . ServiceBuilder ; import org . jboss . msc . service . ServiceName ; import org . nju . artemis . aejb . component . AcContainer ; import org . nju . artemis . aejb . component . ContainerManagedReferenceFactory ; public class AejbInjectionSource extends InjectionSource { Logger log = Logger . getLogger ( AejbInjectionSource . class ) ; private final String lookup ; private final String beanName ; private final String typeName ; private final String bindingName ; private final DeploymentUnit deploymentUnit ; private final AcContainer container ; private volatile String error = null ; private volatile ServiceName resolvedViewName ; ContainerManagedReferenceFactory containerFactory ; private volatile boolean resolved = false ; public AejbInjectionSource ( final String lookup , final String beanName , final String typeName , final String bindingName , final DeploymentUnit deploymentUnit , AcContainer container ) { this . beanName = beanName ; this . typeName = typeName ; this . bindingName = bindingName ; this . deploymentUnit = deploymentUnit ; this . lookup = lookup ; this . container = container ; } public AejbInjectionSource ( final String beanName , final String typeName , final String bindingName , final DeploymentUnit deploymentUnit , AcContainer container ) { this . bindingName = bindingName ; this . deploymentUnit = deploymentUnit ; this . beanName = beanName ; this . typeName = typeName ; this . lookup = null ; this . container = container ; } @ Override public void getResourceValue ( ResolutionContext resolutionContext , ServiceBuilder < ? > serviceBuilder , DeploymentPhaseContext phaseContext , Injector < ManagedReferenceFactory > injector ) throws DeploymentUnitProcessingException { resolve ( ) ; if ( error != null ) { throw new DeploymentUnitProcessingException ( error ) ; } if ( containerFactory != null ) { injector . inject ( containerFactory ) ; } } private void resolve ( ) { if ( ! resolved ) { synchronized ( this ) { if ( ! resolved ) { final Set < ViewDescription > views = getViews ( ) ; final Set < EJBViewDescription > ejbsForViewName = new HashSet < EJBViewDescription > ( ) ; for ( final ViewDescription view : views ) { if ( view instanceof EJBViewDescription ) { ejbsForViewName . add ( ( EJBViewDescription ) view ) ; } } if ( ejbsForViewName . isEmpty ( ) ) { if ( beanName == null ) { error = EjbMessages . MESSAGES . ejbNotFound ( typeName , bindingName ) ; } else { error = EjbMessages . MESSAGES . ejbNotFound ( typeName , beanName , bindingName ) ; } } else if ( ejbsForViewName . size ( ) > <NUM_LIT:1> ) { if ( beanName == null ) { error = EjbMessages . MESSAGES . moreThanOneEjbFound ( typeName , bindingName , ejbsForViewName ) ; } else { error = EjbMessages . MESSAGES . moreThanOneEjbFound ( typeName , beanName , bindingName , ejbsForViewName ) ; } error = "<STR_LIT>" + typeName + "<STR_LIT>" + beanName + "<STR_LIT>" + bindingName ; } else { final EJBViewDescription description = ejbsForViewName . iterator ( ) . next ( ) ; log . debug ( "<STR_LIT>" ) ; final EJBComponentDescription componentDescription = ( EJBComponentDescription ) description . getComponentDescription ( ) ; final EEModuleDescription moduleDescription = componentDescription . getModuleDescription ( ) ; final String earApplicationName = moduleDescription . getEarApplicationName ( ) ; containerFactory = new ContainerManagedReferenceFactory ( earApplicationName , moduleDescription . getModuleName ( ) , moduleDescription . getDistinctName ( ) , componentDescription . getComponentName ( ) , description . getViewClassName ( ) , componentDescription . isStateful ( ) , container ) ; final ServiceName serviceName = description . getServiceName ( ) ; resolvedViewName = serviceName ; } resolved = true ; } } } } private Set < ViewDescription > getViews ( ) { final EEApplicationDescription applicationDescription = deploymentUnit . getAttachment ( EE_APPLICATION_DESCRIPTION ) ; final ResourceRoot deploymentRoot = deploymentUnit . getAttachment ( Attachments . DEPLOYMENT_ROOT ) ; final Set < ViewDescription > componentsForViewName ; if ( beanName != null ) { componentsForViewName = applicationDescription . getComponents ( beanName , typeName , deploymentRoot . getRoot ( ) ) ; } else { componentsForViewName = applicationDescription . getComponentsForViewName ( typeName , deploymentRoot . getRoot ( ) ) ; } return componentsForViewName ; } public boolean equals ( Object o ) { if ( this == o ) return true ; if ( ! ( o instanceof AejbInjectionSource ) ) return false ; resolve ( ) ; if ( error != null ) { return false ; } final AejbInjectionSource other = ( AejbInjectionSource ) o ; return eq ( typeName , other . typeName ) && eq ( resolvedViewName , other . resolvedViewName ) ; } public int hashCode ( ) { return typeName . hashCode ( ) ; } private static boolean eq ( Object a , Object b ) { return a == b || ( a != null && a . equals ( b ) ) ; } } </s>
<s> package org . nju . artemis . aejb . deployment . processors ; import org . jboss . as . server . AbstractDeploymentChainStep ; import org . jboss . as . server . deployment . Attachments ; import org . jboss . as . server . deployment . DeploymentPhaseContext ; import org . jboss . as . server . deployment . DeploymentUnit ; import org . jboss . as . server . deployment . DeploymentUnitProcessingException ; import org . jboss . as . server . deployment . DeploymentUnitProcessor ; import org . jboss . as . server . deployment . Phase ; import org . jboss . as . server . deployment . module . ResourceRoot ; import org . jboss . logging . Logger ; import org . jboss . msc . service . ServiceController ; import org . jboss . msc . service . ServiceRegistry ; import org . jboss . vfs . VirtualFile ; import org . nju . artemis . aejb . subsystem . TrackerService ; public class SubsystemDeploymentProcessor implements DeploymentUnitProcessor { Logger log = Logger . getLogger ( SubsystemDeploymentProcessor . class ) ; public static final Phase PHASE = Phase . DEPENDENCIES ; public static final int PRIORITY = <NUM_LIT> ; @ Override public void deploy ( DeploymentPhaseContext phaseContext ) throws DeploymentUnitProcessingException { String name = phaseContext . getDeploymentUnit ( ) . getName ( ) ; ResourceRoot root = phaseContext . getDeploymentUnit ( ) . getAttachment ( Attachments . DEPLOYMENT_ROOT ) ; TrackerService service = getTrackerService ( phaseContext . getServiceRegistry ( ) , name ) ; if ( service != null ) { VirtualFile cool = root . getRoot ( ) . getChild ( "<STR_LIT>" ) ; service . addDeployment ( name ) ; if ( cool . exists ( ) ) { service . addCoolDeployment ( name ) ; } } } @ Override public void undeploy ( DeploymentUnit context ) { context . getServiceRegistry ( ) ; String name = context . getName ( ) ; TrackerService service = getTrackerService ( context . getServiceRegistry ( ) , name ) ; if ( service != null ) { service . removeDeployment ( name ) ; } } private TrackerService getTrackerService ( ServiceRegistry registry , String name ) { int last = name . lastIndexOf ( "<STR_LIT:.>" ) ; String suffix = name . substring ( last + <NUM_LIT:1> ) ; ServiceController < ? > container = registry . getService ( TrackerService . createServiceName ( suffix ) ) ; if ( container != null ) { TrackerService service = ( TrackerService ) container . getValue ( ) ; return service ; } return null ; } } </s>
<s> package org . nju . artemis . aejb . deployment . transaction ; import java . util . ArrayList ; import java . util . Hashtable ; import java . util . List ; import java . util . Map ; public class TransactionState { private Map < String , TransactionState > $nextStates = new Hashtable < String , TransactionState > ( ) ; private List < String > $passedPorts ; private List < String > $futurePorts ; public TransactionState ( String [ ] passedPorts , String [ ] futurePorts ) { if ( passedPorts != null ) { $passedPorts = new ArrayList < String > ( ) ; for ( String passed : passedPorts ) $passedPorts . add ( passed ) ; } if ( futurePorts != null ) { $futurePorts = new ArrayList < String > ( ) ; for ( String future : futurePorts ) $futurePorts . add ( future ) ; } } public void setNextState ( String eventName , TransactionState next ) { $nextStates . put ( eventName , next ) ; } public TransactionState getStateAfterEvent ( String eventName ) { TransactionState s = ( TransactionState ) $nextStates . get ( eventName ) ; return s ; } public List < String > getAffectedPorts ( ) { List < String > affectedPorts = null ; if ( $passedPorts != null && $futurePorts != null ) { affectedPorts = new ArrayList < String > ( $passedPorts ) ; affectedPorts . retainAll ( $futurePorts ) ; } return affectedPorts ; } public List < String > getPassedPorts ( ) { return $passedPorts ; } public List < String > getFuturePorts ( ) { return $futurePorts ; } } </s>
<s> package org . nju . artemis . aejb . deployment . transaction ; import java . util . List ; public class Transaction { private TransactionState $currentState ; public void init ( TransactionState initialState ) { $currentState = initialState ; } public TransactionState getCurrentState ( ) { return $currentState ; } public void trigger ( String eventName ) { if ( $currentState != null ) { TransactionState next = $currentState . getStateAfterEvent ( eventName ) ; if ( next != null ) { $currentState = next ; } } } public List < String > getAffectedPorts ( ) { return $currentState . getAffectedPorts ( ) ; } public List < String > getPassedPorts ( ) { return $currentState . getPassedPorts ( ) ; } public List < String > getFuturePorts ( ) { return $currentState . getFuturePorts ( ) ; } } </s>
<s> package org . nju . artemis . aejb . deployment . transaction ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import org . nju . artemis . aejb . deployment . processors . TransactionManager ; public class TransactionManagerImpl implements TransactionManager { private TransactionState [ ] $states ; private String $name ; private int $runNumber ; private Map < String , Transaction > $transactions ; private String [ ] $portNames ; private String $transactionmethod ; public String getTransactionMethodName ( ) { return $transactionmethod ; } public TransactionManagerImpl ( String name , String method , String [ ] portNames , TransactionState [ ] states , Map < String , String > [ ] nextStates ) { $name = name ; $states = states ; $transactionmethod = method ; $transactions = new HashMap < String , Transaction > ( ) ; $portNames = portNames ; final int index = $states . length - <NUM_LIT:1> ; for ( int i = <NUM_LIT:0> ; i < index ; i ++ ) { Map < String , String > table = nextStates [ i ] ; Iterator < Entry < String , String > > itrator = table . entrySet ( ) . iterator ( ) ; while ( itrator . hasNext ( ) ) { Entry < String , String > entry = itrator . next ( ) ; String eventName = entry . getKey ( ) ; String next = entry . getValue ( ) ; int n = Integer . parseInt ( next . substring ( <NUM_LIT:1> ) ) ; $states [ i ] . setNextState ( eventName , $states [ n ] ) ; } } } public String getName ( ) { return $name ; } public String toString ( ) { return $name + "<STR_LIT:_>" + getRunNumber ( ) ; } public int getRunNumber ( ) { return $runNumber ; } public boolean isActive ( ) { return getRunNumber ( ) != <NUM_LIT:0> ; } public boolean isActive ( String objectId ) { return $transactions . containsKey ( objectId ) ; } public void trigger ( String objectId , String eventName ) { synchronized ( $transactions ) { if ( ! $transactions . containsKey ( objectId ) ) createTransaction ( objectId ) ; Transaction tran = $transactions . get ( objectId ) ; tran . trigger ( eventName ) ; } } public List < String > getAffectedPorts ( ) { List < String > affectedports = new ArrayList < String > ( ) ; for ( Transaction tran : $transactions . values ( ) ) { affectedports . addAll ( tran . getAffectedPorts ( ) ) ; } return affectedports ; } public String [ ] getInvolvedPorts ( ) { return $portNames ; } public void createTransaction ( String objectId ) { Transaction transaction = new Transaction ( ) ; transaction . init ( $states [ <NUM_LIT:0> ] ) ; $runNumber ++ ; $transactions . put ( objectId , transaction ) ; } public void destroyTransaction ( String objectId ) { $transactions . remove ( objectId ) ; $runNumber -- ; } @ Override public List < String > getAffectedPorts ( String objectId ) { if ( $transactions . containsKey ( objectId ) ) { Transaction transaction = $transactions . get ( objectId ) ; return transaction . getAffectedPorts ( ) ; } return null ; } @ Override public List < String > getPassedPorts ( String objectId ) { if ( $transactions . containsKey ( objectId ) ) { Transaction transaction = $transactions . get ( objectId ) ; return transaction . getPassedPorts ( ) ; } return null ; } @ Override public List < String > getFuturePorts ( String objectId ) { if ( $transactions . containsKey ( objectId ) ) { Transaction transaction = $transactions . get ( objectId ) ; return transaction . getFuturePorts ( ) ; } return null ; } @ Override public void trigger ( String objectId ) { synchronized ( $transactions ) { if ( ! $transactions . containsKey ( objectId ) ) return ; destroyTransaction ( objectId ) ; } } } </s>
<s> package org . nju . artemis . aejb . deployment ; import java . util . Map ; import org . jboss . as . server . deployment . AttachmentKey ; import org . nju . artemis . aejb . component . AcContainer ; public class Attachments { public static final AttachmentKey < Map < String , AcContainer > > AEJB_INFO = AttachmentKey . create ( Map . class ) ; } </s>
<s> package org . nju . artemis . aejb . evolution ; import org . jboss . dmr . ModelNode ; public class OperationFailedException extends Exception { private final ModelNode failureDescription ; private static final long serialVersionUID = - <NUM_LIT> ; public OperationFailedException ( final String msg , final ModelNode description ) { super ( msg ) ; failureDescription = description ; } public OperationFailedException ( final String message ) { this ( message , new ModelNode ( message ) ) ; } @ Override public String toString ( ) { return super . toString ( ) + "<STR_LIT>" + failureDescription + "<STR_LIT>" ; } } </s>
<s> package org . nju . artemis . aejb . evolution . behaviors ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; import org . nju . artemis . aejb . evolution . handlers . OperationStepHandler ; public abstract class EvolutionBehavior implements OperationStepHandler { List < OperationStepHandler > handlers = new ArrayList < OperationStepHandler > ( ) ; abstract protected void initializeStepHandlers ( ) ; protected void perform ( ) throws OperationFailedException { OperationContext context = generateOperationContext ( ) ; initializeStepHandlers ( ) ; for ( Iterator < OperationStepHandler > iterator = handlers . iterator ( ) ; iterator . hasNext ( ) ; ) { OperationStepHandler handler = iterator . next ( ) ; if ( handler . execute ( context ) == OperationResult . UnExpected ) rollBackWhenUnExpectedResult ( handler ) ; } } abstract protected OperationContext generateOperationContext ( ) ; abstract void rollBackWhenUnExpectedResult ( OperationStepHandler handler ) throws OperationFailedException ; } </s>
<s> package org . nju . artemis . aejb . evolution . behaviors ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; import org . nju . artemis . aejb . evolution . handlers . DependencyComputeHandler ; import org . nju . artemis . aejb . evolution . handlers . OperationStepHandler ; import org . nju . artemis . aejb . evolution . handlers . StatusShiftHandler ; import org . nju . artemis . aejb . management . client . AEjbClientImpl . AEjbStatus ; public class ComponentLocker extends EvolutionBehavior { private static final String HANDLER_NAME = "<STR_LIT>" ; static final String LOCK = "<STR_LIT>" ; static final String UNLOCK = "<STR_LIT>" ; private String aejbName ; private AEjbUtilities utilities ; private AEjbStatus status ; private void lock ( String aejbName ) throws OperationFailedException { this . aejbName = aejbName ; this . status = AEjbStatus . BLOCKING ; perform ( ) ; } private void unlock ( String aejbName ) throws OperationFailedException { this . aejbName = aejbName ; this . status = AEjbStatus . RESUMING ; perform ( ) ; } @ Override protected OperationContext generateOperationContext ( ) { OperationContext context = new OperationContext ( null , aejbName ) ; context . getContextData ( ) . put ( AEjbUtilities . class , utilities ) ; context . getContextData ( ) . put ( AEjbStatus . class , status ) ; return context ; } @ Override protected void initializeStepHandlers ( ) { handlers . add ( new DependencyComputeHandler ( ) ) ; handlers . add ( new StatusShiftHandler ( ) ) ; } @ Override public OperationResult execute ( OperationContext context ) throws OperationFailedException { String operationName = context . getOperationName ( ) ; utilities = ( AEjbUtilities ) context . getContextData ( ) . get ( AEjbUtilities . class ) ; if ( LOCK . equals ( operationName ) ) { lock ( context . getTargetName ( ) ) ; } else if ( UNLOCK . equals ( operationName ) ) { unlock ( context . getTargetName ( ) ) ; } else throw new OperationFailedException ( "<STR_LIT>" + operationName + "<STR_LIT>" ) ; return OperationResult . Expected ; } @ Override public String getHandlerName ( ) { return HANDLER_NAME ; } @ Override void rollBackWhenUnExpectedResult ( OperationStepHandler handler ) { } } </s>
<s> package org . nju . artemis . aejb . evolution . behaviors ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; import org . nju . artemis . aejb . evolution . handlers . ComponentInstanceDirectHandler ; import org . nju . artemis . aejb . evolution . handlers . ComponentSecurityHandler ; import org . nju . artemis . aejb . evolution . handlers . DependencyChangeHandler ; import org . nju . artemis . aejb . evolution . handlers . InterfaceCompareHandler ; import org . nju . artemis . aejb . evolution . handlers . OperationAlterHandler ; import org . nju . artemis . aejb . evolution . handlers . OperationStepHandler ; public class ComponentReplacer extends EvolutionBehavior { Logger log = Logger . getLogger ( ComponentReplacer . class ) ; private static final String HANDLER_NAME = "<STR_LIT>" ; private final String fromName ; private final String toName ; private final String protocol ; private AEjbUtilities utilities ; public ComponentReplacer ( String fromName , String toName , String protocol ) { this . fromName = fromName ; this . toName = toName ; this . protocol = protocol ; } @ Override public OperationResult execute ( OperationContext context ) throws OperationFailedException { utilities = ( AEjbUtilities ) context . getContextData ( ) . get ( AEjbUtilities . class ) ; perform ( ) ; return OperationResult . Expected ; } @ Override public String getHandlerName ( ) { return HANDLER_NAME ; } @ Override protected void initializeStepHandlers ( ) { handlers . add ( new InterfaceCompareHandler ( ) ) ; handlers . add ( new OperationAlterHandler ( ComponentLocker . LOCK ) ) ; handlers . add ( new ComponentLocker ( ) ) ; handlers . add ( new ComponentSecurityHandler ( ) ) ; handlers . add ( new ComponentInstanceDirectHandler ( ) ) ; handlers . add ( new OperationAlterHandler ( ComponentLocker . UNLOCK ) ) ; handlers . add ( new ComponentLocker ( ) ) ; handlers . add ( new DependencyChangeHandler ( ) ) ; } @ Override protected OperationContext generateOperationContext ( ) { OperationContext context = new OperationContext ( null , fromName ) ; context . getContextData ( ) . put ( AEjbUtilities . class , utilities ) ; context . getContextData ( ) . put ( "<STR_LIT>" , toName ) ; context . getContextData ( ) . put ( "<STR_LIT>" , protocol ) ; return context ; } @ Override void rollBackWhenUnExpectedResult ( OperationStepHandler handler ) throws OperationFailedException { } } </s>
<s> package org . nju . artemis . aejb . evolution . behaviors ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; import org . nju . artemis . aejb . evolution . handlers . DependencyChangeHandler ; import org . nju . artemis . aejb . evolution . handlers . DependencyComputeHandler ; import org . nju . artemis . aejb . evolution . handlers . ComponentInstanceDirectHandler ; import org . nju . artemis . aejb . evolution . handlers . InterfaceCompareHandler ; import org . nju . artemis . aejb . evolution . handlers . OperationStepHandler ; public class ComponentSwitcher extends EvolutionBehavior { Logger log = Logger . getLogger ( ComponentSwitcher . class ) ; private static final String HANDLER_NAME = "<STR_LIT>" ; private final String fromName ; private final String toName ; private final String protocol ; private AEjbUtilities utilities ; public ComponentSwitcher ( String fromName , String toName , String protocol ) { this . fromName = fromName ; this . toName = toName ; this . protocol = protocol ; } @ Override public OperationResult execute ( OperationContext context ) throws OperationFailedException { utilities = ( AEjbUtilities ) context . getContextData ( ) . get ( AEjbUtilities . class ) ; perform ( ) ; return OperationResult . Expected ; } @ Override protected void initializeStepHandlers ( ) { handlers . add ( new InterfaceCompareHandler ( ) ) ; handlers . add ( new DependencyComputeHandler ( ) ) ; handlers . add ( new ComponentInstanceDirectHandler ( ) ) ; handlers . add ( new DependencyChangeHandler ( ) ) ; } @ Override protected OperationContext generateOperationContext ( ) { OperationContext context = new OperationContext ( null , fromName ) ; context . getContextData ( ) . put ( AEjbUtilities . class , utilities ) ; context . getContextData ( ) . put ( "<STR_LIT>" , toName ) ; context . getContextData ( ) . put ( "<STR_LIT>" , protocol ) ; return context ; } @ Override public String getHandlerName ( ) { return HANDLER_NAME ; } @ Override void rollBackWhenUnExpectedResult ( OperationStepHandler handler ) throws OperationFailedException { throw new OperationFailedException ( handler . getHandlerName ( ) + "<STR_LIT>" ) ; } } </s>
<s> package org . nju . artemis . aejb . evolution ; import java . util . HashMap ; import java . util . Map ; public class OperationContext { private String operationName ; private String targetName ; private Map < Object , Object > contextData = new HashMap < Object , Object > ( ) ; public OperationContext ( String operationName , String targetName ) { this . operationName = operationName ; this . targetName = targetName ; } public Map < Object , Object > getContextData ( ) { return contextData ; } public String getOperationName ( ) { return operationName ; } public void setOperationName ( String operationName ) { this . operationName = operationName ; } public String getTargetName ( ) { return targetName ; } public void setTargetName ( String targetName ) { this . targetName = targetName ; } } </s>
<s> package org . nju . artemis . aejb . evolution ; import java . util . Iterator ; import java . util . Map ; import java . util . Map . Entry ; import java . util . concurrent . atomic . AtomicLong ; import org . jboss . logging . Logger ; import org . jboss . msc . service . Service ; import org . jboss . msc . service . ServiceName ; import org . jboss . msc . service . StartContext ; import org . jboss . msc . service . StartException ; import org . jboss . msc . service . StopContext ; import org . jboss . msc . value . InjectedValue ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . evolution . behaviors . ComponentSwitcher ; import org . nju . artemis . aejb . evolution . protocols . Protocol ; import org . nju . artemis . aejb . evolution . protocols . QuiescenceProtocol ; import org . nju . artemis . aejb . evolution . protocols . TranquilityProtocol ; import org . nju . artemis . aejb . management . client . AEjbClient ; import org . nju . artemis . aejb . management . client . AEjbClientImpl . AEjbStatus ; public class DuService implements Service < DuService > { Logger log = Logger . getLogger ( DuService . class ) ; public static final ServiceName SERVICE_NAME = ServiceName . JBOSS . append ( "<STR_LIT>" , "<STR_LIT>" ) ; private final InjectedValue < AEjbClient > aejbClientValue = new InjectedValue < AEjbClient > ( ) ; private final InjectedValue < AEjbUtilities > aejbUtilitiesValue = new InjectedValue < AEjbUtilities > ( ) ; private final AtomicLong tick = new AtomicLong ( <NUM_LIT> ) ; @ Override public DuService getValue ( ) throws IllegalStateException , IllegalArgumentException { return this ; } AEjbClient getAEjbClient ( ) { return aejbClientValue . getValue ( ) ; } AEjbUtilities getAEjbUtilities ( ) { return aejbUtilitiesValue . getValue ( ) ; } private Thread CLIENT_MONITOR = new Thread ( ) { @ Override public void run ( ) { while ( true ) { try { Thread . sleep ( tick . get ( ) ) ; Map < String , AEjbStatus > aejbStatus = getAEjbClient ( ) . getAEjbStatus ( ) ; if ( ! aejbStatus . isEmpty ( ) ) { manageAEjbState ( aejbStatus ) ; getAEjbClient ( ) . clearAEjbStatus ( ) ; } Map < String , String > switchMap = getAEjbClient ( ) . getSwitchMap ( ) ; if ( ! switchMap . isEmpty ( ) ) { manageAEjbSwitch ( switchMap ) ; getAEjbClient ( ) . clearSwitchMap ( ) ; } } catch ( InterruptedException e ) { interrupted ( ) ; break ; } } } } ; @ Override public void start ( StartContext context ) throws StartException { CLIENT_MONITOR . start ( ) ; } private void manageAEjbState ( Map < String , AEjbStatus > aejbStatus ) { getAEjbUtilities ( ) . setAEjbStatus ( aejbStatus ) ; } private void manageAEjbSwitch ( Map < String , String > switchMap ) { Iterator < Entry < String , String > > iterator = switchMap . entrySet ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { Entry < String , String > entry = iterator . next ( ) ; String fromName = entry . getKey ( ) ; String toName = entry . getValue ( ) ; OperationContext context = new OperationContext ( null , fromName ) ; context . getContextData ( ) . put ( AEjbUtilities . class , getAEjbUtilities ( ) ) ; try { new ComponentSwitcher ( fromName , toName , getAEjbClient ( ) . getProtocol ( fromName ) ) . execute ( context ) ; } catch ( OperationFailedException e ) { log . warn ( e . getMessage ( ) ) ; log . info ( "<STR_LIT>" + fromName + "<STR_LIT>" + toName + "<STR_LIT>" ) ; } } } @ Override public void stop ( StopContext context ) { CLIENT_MONITOR . interrupt ( ) ; } public InjectedValue < AEjbClient > getAejbClientValue ( ) { return aejbClientValue ; } public InjectedValue < AEjbUtilities > getAejbUtilitiesValue ( ) { return aejbUtilitiesValue ; } public static Protocol getProtocol ( String protocolName ) { if ( "<STR_LIT>" . equals ( protocolName ) ) { return new QuiescenceProtocol ( ) ; } else if ( "<STR_LIT>" . equals ( protocolName ) ) { return new TranquilityProtocol ( ) ; } return null ; } } </s>
<s> package org . nju . artemis . aejb . evolution . handlers ; import java . util . ArrayList ; import java . util . List ; import java . util . Set ; import org . jboss . logging . Logger ; import javax . aejb . AEjb ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . component . AcContainer ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; public class DependencyComputeHandler implements OperationStepHandler { Logger log = Logger . getLogger ( DependencyComputeHandler . class ) ; private static final String HANDLER_NAME = "<STR_LIT>" ; @ Override public OperationResult execute ( OperationContext context ) throws OperationFailedException { log . info ( "<STR_LIT>" ) ; final AEjbUtilities utilities = ( AEjbUtilities ) context . getContextData ( ) . get ( AEjbUtilities . class ) ; final String targetName = context . getTargetName ( ) ; if ( utilities == null || targetName == null ) throw new OperationFailedException ( "<STR_LIT>" ) ; List < String > neighbors = new ArrayList < String > ( ) ; for ( AcContainer container : utilities . getAllContainers ( ) ) { Set < String > dependencies = container . getRuntimeDependencies ( ) ; log . info ( "<STR_LIT>" + container . getAEJBName ( ) + "<STR_LIT>" + dependencies ) ; if ( dependencies != null && dependencies . contains ( targetName ) ) { neighbors . add ( container . getAEJBName ( ) ) ; } } log . info ( targetName + "<STR_LIT>" + neighbors ) ; context . getContextData ( ) . put ( "<STR_LIT>" , neighbors ) ; log . info ( "<STR_LIT>" ) ; return OperationResult . Expected ; } @ Override public String getHandlerName ( ) { return HANDLER_NAME ; } } </s>
<s> package org . nju . artemis . aejb . evolution . handlers ; import java . util . List ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . component . AcContainer ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; public class ComponentInstanceDirectHandler implements OperationStepHandler { Logger log = Logger . getLogger ( ComponentInstanceDirectHandler . class ) ; private final String HANDLER_NAME = "<STR_LIT>" ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) @ Override public OperationResult execute ( OperationContext context ) throws OperationFailedException { log . debug ( "<STR_LIT>" ) ; final List < String > neighbors = ( List < String > ) context . getContextData ( ) . get ( "<STR_LIT>" ) ; final String targetName = context . getTargetName ( ) ; final String toName = ( String ) context . getContextData ( ) . get ( "<STR_LIT>" ) ; final String protocol = ( String ) context . getContextData ( ) . get ( "<STR_LIT>" ) ; final AcContainer toCon = AEjbUtilities . getContainer ( toName ) ; if ( neighbors == null ) throw new OperationFailedException ( "<STR_LIT>" ) ; if ( toCon == null ) throw new OperationFailedException ( "<STR_LIT>" + toName + "<STR_LIT:.>" ) ; for ( String aejbName : neighbors ) { AcContainer con = AEjbUtilities . getContainer ( aejbName ) ; if ( con == null ) throw new OperationFailedException ( "<STR_LIT>" + aejbName + "<STR_LIT:.>" ) ; con . getEvolutionStatistics ( ) . addToDirectionalMap ( targetName , toCon ) ; con . getEvolutionStatistics ( ) . addProtocol ( targetName , protocol ) ; } log . debug ( "<STR_LIT>" ) ; return OperationResult . Expected ; } @ Override public String getHandlerName ( ) { return HANDLER_NAME ; } } </s>
<s> package org . nju . artemis . aejb . evolution . handlers ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; public interface OperationStepHandler { enum OperationResult { Expected , UnExpected , } OperationResult execute ( OperationContext context ) throws OperationFailedException ; String getHandlerName ( ) ; } </s>
<s> package org . nju . artemis . aejb . evolution . handlers ; import java . util . List ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . component . AcContainer ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; import org . nju . artemis . aejb . management . client . AEjbClientImpl . AEjbStatus ; public class StatusShiftHandler implements OperationStepHandler { private static final String HANDLER_NAME = "<STR_LIT>" ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) @ Override public OperationResult execute ( OperationContext context ) throws OperationFailedException { final List < String > neighbors = ( List < String > ) context . getContextData ( ) . get ( "<STR_LIT>" ) ; final String targetName = context . getTargetName ( ) ; final AEjbStatus status = ( AEjbStatus ) context . getContextData ( ) . get ( AEjbStatus . class ) ; if ( neighbors == null ) throw new OperationFailedException ( "<STR_LIT>" ) ; for ( String aejbName : neighbors ) { AcContainer con = AEjbUtilities . getContainer ( aejbName ) ; if ( con == null ) throw new OperationFailedException ( "<STR_LIT>" + aejbName + "<STR_LIT:.>" ) ; con . getEvolutionStatistics ( ) . setAEjbStatus ( targetName , status ) ; } return OperationResult . Expected ; } @ Override public String getHandlerName ( ) { return HANDLER_NAME ; } } </s>
<s> package org . nju . artemis . aejb . evolution . handlers ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; public class OperationAlterHandler implements OperationStepHandler { private static final String HANDLER_NAME = "<STR_LIT>" ; private final String operationName ; public OperationAlterHandler ( String operationName ) { this . operationName = operationName ; } @ Override public OperationResult execute ( OperationContext context ) throws OperationFailedException { context . setOperationName ( operationName ) ; return OperationResult . Expected ; } @ Override public String getHandlerName ( ) { return HANDLER_NAME ; } } </s>
<s> package org . nju . artemis . aejb . evolution . handlers ; import java . util . List ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . component . AcContainer ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; public class DependencyChangeHandler implements OperationStepHandler { Logger log = Logger . getLogger ( DependencyChangeHandler . class ) ; private static final String HANDLER_NAME = "<STR_LIT>" ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) @ Override public OperationResult execute ( OperationContext context ) throws OperationFailedException { log . info ( "<STR_LIT>" ) ; if ( context . getContextData ( ) . get ( "<STR_LIT>" ) == null || ( Boolean ) context . getContextData ( ) . get ( "<STR_LIT>" ) ) { final List < String > neighbors = ( List < String > ) context . getContextData ( ) . get ( "<STR_LIT>" ) ; final String targetName = context . getTargetName ( ) ; final String toName = ( String ) context . getContextData ( ) . get ( "<STR_LIT>" ) ; if ( neighbors == null ) throw new OperationFailedException ( "<STR_LIT>" ) ; for ( String aejbName : neighbors ) { AcContainer con = AEjbUtilities . getContainer ( aejbName ) ; if ( con == null ) throw new OperationFailedException ( "<STR_LIT>" + aejbName + "<STR_LIT:.>" ) ; con . changeRuntimeDependencies ( targetName , toName ) ; log . info ( aejbName + "<STR_LIT>" + targetName + "<STR_LIT:U+0020toU+0020>" + toName ) ; } } log . info ( "<STR_LIT>" ) ; return OperationResult . Expected ; } @ Override public String getHandlerName ( ) { return HANDLER_NAME ; } } </s>
<s> package org . nju . artemis . aejb . evolution . handlers ; import java . lang . reflect . Method ; import java . util . Set ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . component . AcContainer ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; public class InterfaceCompareHandler implements OperationStepHandler { Logger log = Logger . getLogger ( InterfaceCompareHandler . class ) ; private static final String HANDLER_NAME = "<STR_LIT>" ; @ Override public OperationResult execute ( OperationContext context ) throws OperationFailedException { log . info ( "<STR_LIT>" ) ; final String fromName = context . getTargetName ( ) ; final String toName = ( String ) context . getContextData ( ) . get ( "<STR_LIT>" ) ; final AEjbUtilities utilities = ( AEjbUtilities ) context . getContextData ( ) . get ( AEjbUtilities . class ) ; if ( utilities == null || fromName == null ) throw new OperationFailedException ( "<STR_LIT>" ) ; if ( toName == null ) throw new OperationFailedException ( fromName + "<STR_LIT>" ) ; log . info ( "<STR_LIT>" + fromName + "<STR_LIT>" + toName ) ; AcContainer fromContainer = AEjbUtilities . getContainer ( fromName ) ; AcContainer toContainer = AEjbUtilities . getContainer ( toName ) ; if ( fromContainer == null || toContainer == null ) throw new OperationFailedException ( fromName + "<STR_LIT>" + toName + "<STR_LIT>" ) ; if ( fromContainer . getLocalView ( ) . size ( ) != toContainer . getLocalView ( ) . size ( ) || fromContainer . getRemoteView ( ) . size ( ) != toContainer . getRemoteView ( ) . size ( ) ) throw new OperationFailedException ( fromName + "<STR_LIT:U+0020andU+0020>" + toName + "<STR_LIT>" ) ; boolean locale = equalSet ( fromContainer . getLocalView ( ) , toContainer . getLocalView ( ) ) ; boolean remote = equalSet ( fromContainer . getRemoteView ( ) , toContainer . getRemoteView ( ) ) ; log . info ( "<STR_LIT>" ) ; return ( locale && remote ) ? OperationResult . Expected : OperationResult . UnExpected ; } private boolean equalSet ( Set < Class < ? > > sets1 , Set < Class < ? > > sets2 ) { int sum = sets1 . size ( ) ; int num = <NUM_LIT:0> ; for ( Class < ? > class1 : sets1 ) { for ( Class < ? > class2 : sets2 ) { if ( equals ( class1 , class2 ) ) { num ++ ; break ; } } } return sum == num ; } public static boolean equals ( Class < ? > c1 , Class < ? > c2 ) { if ( c1 == null && c2 == null ) return true ; if ( c1 != null && c2 != null ) { Method [ ] methods1 = c1 . getMethods ( ) ; Method [ ] methods2 = c2 . getMethods ( ) ; if ( methods1 == null || methods2 == null || methods1 . length != methods2 . length ) return false ; int methodsSum = methods1 . length ; int methodsNum = <NUM_LIT:0> ; for ( Method method1 : methods1 ) { for ( Method method2 : methods2 ) { if ( method1 . getName ( ) == method2 . getName ( ) ) { if ( ! method1 . getReturnType ( ) . equals ( method2 . getReturnType ( ) ) ) continue ; Class < ? > [ ] params1 = method1 . getParameterTypes ( ) ; Class < ? > [ ] params2 = method2 . getParameterTypes ( ) ; if ( params1 . length == params2 . length ) { int i ; for ( i = <NUM_LIT:0> ; i < params1 . length ; i ++ ) { if ( params1 [ i ] != params2 [ i ] ) break ; } if ( i == params1 . length ) methodsNum ++ ; } } } } if ( methodsNum == methodsSum ) return true ; } return false ; } @ Override public String getHandlerName ( ) { return HANDLER_NAME ; } } </s>
<s> package org . nju . artemis . aejb . evolution . handlers ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . evolution . DuService ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; import org . nju . artemis . aejb . evolution . protocols . Protocol ; public class ComponentSecurityHandler implements OperationStepHandler { Logger log = Logger . getLogger ( ComponentSecurityHandler . class ) ; private final String HANDLER_NAME = "<STR_LIT>" ; @ Override public OperationResult execute ( OperationContext context ) throws OperationFailedException { final String protocolName = ( String ) context . getContextData ( ) . get ( "<STR_LIT>" ) ; final String aejbName = context . getTargetName ( ) ; Protocol protocol = DuService . getProtocol ( protocolName ) ; if ( protocol != null ) { boolean res = protocol . setToSafePoint ( AEjbUtilities . getContainer ( aejbName ) ) ; if ( res ) return OperationResult . Expected ; } return OperationResult . UnExpected ; } @ Override public String getHandlerName ( ) { return HANDLER_NAME ; } } </s>
<s> package org . nju . artemis . aejb . evolution . handlers ; import org . nju . artemis . aejb . evolution . OperationContext ; import org . nju . artemis . aejb . evolution . OperationFailedException ; public class SingletonAEjbHandler implements OperationStepHandler { private static final String HANDLER_NAME = "<STR_LIT>" ; @ Override public OperationResult execute ( OperationContext context ) throws OperationFailedException { return null ; } @ Override public String getHandlerName ( ) { return HANDLER_NAME ; } } </s>
<s> package org . nju . artemis . aejb . evolution . protocols ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AcContainer ; import org . nju . artemis . aejb . deployment . processors . TransactionManager ; public class QuiescenceProtocol implements Protocol { Logger log = Logger . getLogger ( QuiescenceProtocol . class ) ; @ Override public boolean checkTransactionSecurity ( String targetName , String objectId , TransactionManager transactionManager ) { log . debug ( "<STR_LIT>" + getName ( ) + "<STR_LIT>" ) ; String [ ] ports = transactionManager . getInvolvedPorts ( ) ; if ( ports != null && transactionManager . isActive ( objectId ) ) { if ( transactionManager . getPassedPorts ( objectId ) . contains ( targetName ) || transactionManager . getFuturePorts ( objectId ) . contains ( targetName ) ) return false ; } return true ; } @ Override public String getName ( ) { return "<STR_LIT>" ; } @ Override public boolean setToSafePoint ( AcContainer container ) { return false ; } } </s>
<s> package org . nju . artemis . aejb . evolution . protocols ; import java . util . List ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AcContainer ; import org . nju . artemis . aejb . deployment . processors . TransactionManager ; public class TranquilityProtocol implements Protocol { Logger log = Logger . getLogger ( TranquilityProtocol . class ) ; @ Override public boolean checkTransactionSecurity ( String targetName , String objectId , TransactionManager transactionManager ) { log . debug ( "<STR_LIT>" + getName ( ) + "<STR_LIT>" ) ; List < String > ports = transactionManager . getAffectedPorts ( objectId ) ; if ( ports != null && ports . contains ( targetName ) ) return false ; return true ; } @ Override public String getName ( ) { return "<STR_LIT>" ; } @ Override public boolean setToSafePoint ( AcContainer container ) { return false ; } } </s>
<s> package org . nju . artemis . aejb . evolution . protocols ; import org . nju . artemis . aejb . component . AcContainer ; import org . nju . artemis . aejb . deployment . processors . TransactionManager ; public interface Protocol { boolean checkTransactionSecurity ( String targetName , String objectId , TransactionManager transactionManager ) ; String getName ( ) ; boolean setToSafePoint ( AcContainer container ) ; } </s>
<s> package org . nju . artemis . aejb ; import org . jboss . logging . BasicLogger ; import org . jboss . logging . LogMessage ; import org . jboss . logging . Logger ; import org . jboss . logging . Logger . Level ; import org . jboss . logging . Message ; import org . jboss . logging . MessageLogger ; @ MessageLogger ( projectCode = "<STR_LIT>" ) public interface AEjbLogger extends BasicLogger { AEjbLogger ROOT_LOGGER = Logger . getMessageLogger ( AEjbLogger . class , AEjbLogger . class . getPackage ( ) . getName ( ) ) ; @ LogMessage ( level = Level . INFO ) @ Message ( id = <NUM_LIT> , value = "<STR_LIT>" ) void activatingAEjbSubsystem ( ) ; @ LogMessage ( level = Level . INFO ) @ Message ( id = <NUM_LIT> , value = "<STR_LIT>" ) void boundClientService ( String jndi ) ; @ LogMessage ( level = Level . INFO ) @ Message ( id = <NUM_LIT> , value = "<STR_LIT>" ) void unboundClientService ( String jndi ) ; @ LogMessage ( level = Level . INFO ) @ Message ( id = <NUM_LIT> , value = "<STR_LIT>" ) void removeClientService ( String jndi ) ; @ LogMessage ( level = Level . INFO ) @ Message ( id = <NUM_LIT> , value = "<STR_LIT>" ) void boundTransactionManager ( String jndi ) ; } </s>
<s> package org . nju . artemis . aejb . management . cli ; import java . security . PrivilegedAction ; class PropertyWriteAction implements PrivilegedAction < String > { private final String key ; private final String value ; PropertyWriteAction ( final String key , final String value ) { this . key = key ; this . value = value ; } @ Override public String run ( ) { return System . setProperty ( key , value ) ; } } </s>
<s> package org . nju . artemis . aejb . management . cli ; import java . io . File ; public abstract class FilenameTabCompleter { public String translatePath ( String path ) { final String translated ; if ( path . startsWith ( "<STR_LIT>" + File . separator ) ) { translated = System . getProperty ( "<STR_LIT>" ) + path . substring ( <NUM_LIT:1> ) ; } else if ( path . startsWith ( "<STR_LIT>" ) ) { translated = new File ( System . getProperty ( "<STR_LIT>" ) ) . getParentFile ( ) . getAbsolutePath ( ) ; } else if ( ! startsWithRoot ( path ) ) { throw new IllegalArgumentException ( ManagementMessages . FilePathNotCorrect + "<STR_LIT::U+0020>" + path ) ; } else { translated = path ; } return translated ; } protected abstract boolean startsWithRoot ( String path ) ; public File getFile ( String buffer ) { if ( buffer . length ( ) >= <NUM_LIT:2> && buffer . charAt ( <NUM_LIT:0> ) == '<CHAR_LIT:">' ) { int lastQuote = buffer . lastIndexOf ( '<CHAR_LIT:">' ) ; if ( lastQuote >= <NUM_LIT:0> ) { StringBuilder buf = new StringBuilder ( ) ; buf . append ( buffer . substring ( <NUM_LIT:1> , lastQuote ) ) ; if ( lastQuote != buffer . length ( ) - <NUM_LIT:1> ) { buf . append ( buffer . substring ( lastQuote + <NUM_LIT:1> ) ) ; } buffer = buf . toString ( ) ; } } final String path ; if ( buffer . length ( ) == <NUM_LIT:0> ) { path = null ; } else { path = translatePath ( buffer ) ; } if ( path == null ) return null ; File file = new File ( path ) ; if ( file . exists ( ) ) return file ; else { return null ; } } } </s>
<s> package org . nju . artemis . aejb . management . cli ; import java . security . AccessController ; import java . security . PrivilegedAction ; class SecurityActions { private interface TCLAction { class UTIL { static TCLAction getTCLAction ( ) { return System . getSecurityManager ( ) == null ? NON_PRIVILEGED : PRIVILEGED ; } static String getSystemProperty ( String name ) { return getTCLAction ( ) . getSystemProperty ( name ) ; } static ClassLoader getContextClassLoader ( ) { return getTCLAction ( ) . getContextClassLoader ( ) ; } } TCLAction NON_PRIVILEGED = new TCLAction ( ) { @ Override public String getSystemProperty ( String name ) { return System . getProperty ( name ) ; } @ Override public ClassLoader getContextClassLoader ( ) { return Thread . currentThread ( ) . getContextClassLoader ( ) ; } } ; TCLAction PRIVILEGED = new TCLAction ( ) { @ Override public String getSystemProperty ( final String name ) { return ( String ) AccessController . doPrivileged ( new PrivilegedAction < Object > ( ) { public Object run ( ) { return System . getProperty ( name ) ; } } ) ; } @ Override public ClassLoader getContextClassLoader ( ) { return ( ClassLoader ) AccessController . doPrivileged ( new PrivilegedAction < Object > ( ) { public Object run ( ) { return Thread . currentThread ( ) . getContextClassLoader ( ) ; } } ) ; } } ; String getSystemProperty ( String name ) ; ClassLoader getContextClassLoader ( ) ; } protected static String getSystemProperty ( String name ) { return TCLAction . UTIL . getSystemProperty ( name ) ; } protected static ClassLoader getContextClassLoader ( ) { return TCLAction . UTIL . getContextClassLoader ( ) ; } } </s>
<s> package org . nju . artemis . aejb . management . cli ; public class WindowsFilenameTabCompleter extends FilenameTabCompleter { @ Override protected boolean startsWithRoot ( String path ) { return path . contains ( "<STR_LIT>" ) ; } } </s>
<s> package org . nju . artemis . aejb . management . cli ; public interface ManagementMessages { String FunctionPrompt = "<STR_LIT>" ; String JbossHomeNotSet = "<STR_LIT>" ; String InputFilePathPrompt = "<STR_LIT>" ; String InputFileNamePrompt = "<STR_LIT>" ; String FilePathNotCorrect = "<STR_LIT>" ; String FilePathNotExist = "<STR_LIT>" ; String DisplayDeployments = "<STR_LIT>" ; String NotConnectServer = "<STR_LIT>" ; String EmptyDeployments = "<STR_LIT>" ; String AEjbNamePrompt = "<STR_LIT>" ; String AEjbNotExist = "<STR_LIT>" ; String WaitingPrompt = "<STR_LIT>" ; String ThreadExceptionPrompt = "<STR_LIT>" ; String OperationFailed = "<STR_LIT>" ; String OperationTimeOutFailed = "<STR_LIT>" ; String OperationSuccess = "<STR_LIT>" ; String ConnectPrompt = "<STR_LIT>" ; String ProtocolPrompt = "<STR_LIT>" ; String UnexpectedCommandPrompt = "<STR_LIT>" ; String UnexpectedSameName = "<STR_LIT>" ; } </s>
<s> package org . nju . artemis . aejb . management . cli ; import java . io . Console ; import java . io . File ; import java . lang . reflect . Method ; import java . security . AccessController ; import java . util . Hashtable ; import java . util . Iterator ; import java . util . Map ; import java . util . Map . Entry ; import java . util . concurrent . atomic . AtomicLong ; import javax . naming . Context ; import javax . naming . InitialContext ; import javax . naming . NamingException ; import org . nju . artemis . aejb . management . client . AEjbClient ; import org . nju . artemis . aejb . management . client . AEjbClientImpl . AEjbStatus ; public class CommandLineMain { private static final String NEW_LINE = "<STR_LIT:n>" ; private static final String SPACE = "<STR_LIT:U+0020>" ; private static final String TAB = "<STR_LIT:;U+0020>" ; private static final String POINT = "<STR_LIT:.>" ; private static final AtomicLong TICK = new AtomicLong ( <NUM_LIT> ) ; private static final int MAXCONNECTTIMES = <NUM_LIT:20> ; private static String classpath = null ; private static final Console theConsole = System . console ( ) ; private State nextState ; FilenameTabCompleter pathCompleter ; static final String CLIENT_EJB_JNDI = "<STR_LIT>" + "<STR_LIT:/>" + "<STR_LIT>" + "<STR_LIT:/>" + "<STR_LIT:/>" + "<STR_LIT>" + "<STR_LIT:!>" + "<STR_LIT>" ; static AEjbClient client ; static Context context ; static { final Hashtable jndiProperties = new Hashtable ( ) ; jndiProperties . put ( Context . URL_PKG_PREFIXES , "<STR_LIT>" ) ; try { context = new InitialContext ( jndiProperties ) ; } catch ( NamingException e ) { } } private CommandLineMain ( ) { if ( theConsole == null ) { throw new IllegalStateException ( "<STR_LIT>" ) ; } pathCompleter = isWindows ( ) ? new WindowsFilenameTabCompleter ( ) : new DefaultFilenameTabCompleter ( ) ; nextState = new ConnectState ( ) ; } private void run ( ) { while ( ( nextState = nextState . execute ( ) ) != null ) { } } public static void main ( String [ ] args ) { final int argsLen = args . length ; if ( argsLen >= <NUM_LIT:1> ) { for ( int i = <NUM_LIT:0> , argsLength = argsLen ; i < argsLength ; i ++ ) { final String arg = args [ i ] ; if ( arg . charAt ( <NUM_LIT:0> ) == '<CHAR_LIT:->' ) { if ( "<STR_LIT>" . equals ( arg ) || "<STR_LIT>" . equals ( arg ) ) { classpath = args [ ++ i ] ; AccessController . doPrivileged ( new PropertyWriteAction ( "<STR_LIT>" , classpath ) ) ; } } } } new CommandLineMain ( ) . run ( ) ; } private class FunctionPrompt implements State { @ Override public State execute ( ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( ManagementMessages . FunctionPrompt ) ; theConsole . printf ( NEW_LINE ) ; while ( true ) { String temp = theConsole . readLine ( "<STR_LIT>" ) ; if ( temp == null ) { theConsole . printf ( NEW_LINE ) ; return null ; } if ( temp . length ( ) > <NUM_LIT:0> ) { if ( temp . length ( ) == <NUM_LIT:1> ) { switch ( temp . charAt ( <NUM_LIT:0> ) ) { case '<CHAR_LIT:a>' : case '<CHAR_LIT:A>' : return new DeploymentsDisplayer ( ) ; case '<CHAR_LIT:b>' : case '<CHAR_LIT>' : return new DeploymentFilePathInput ( ) ; case '<CHAR_LIT:c>' : case '<CHAR_LIT>' : return new DeploymentFileNameInput ( ) ; case '<CHAR_LIT>' : case '<CHAR_LIT>' : return new AEjbBlocker ( new AEjbNameInput ( ) ) ; case '<CHAR_LIT:e>' : case '<CHAR_LIT>' : return new AEjbRecorver ( new AEjbNameInput ( ) ) ; case '<CHAR_LIT>' : case '<CHAR_LIT>' : return new AEjbSwitcher ( new AEjbNameInput ( ) ) ; } } theConsole . printf ( ManagementMessages . UnexpectedCommandPrompt + SPACE + "<STR_LIT:'>" + temp + "<STR_LIT>" ) ; theConsole . printf ( NEW_LINE ) ; } } } } private class DeploymentFilePathInput implements State { private DeploymentFilePathInput ( ) { } @ Override public State execute ( ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( ManagementMessages . InputFilePathPrompt ) ; theConsole . printf ( NEW_LINE ) ; while ( true ) { String temp = theConsole . readLine ( "<STR_LIT>" ) ; if ( temp == null ) { theConsole . printf ( NEW_LINE ) ; return null ; } if ( temp . length ( ) > <NUM_LIT:0> ) { return new DeploymentFileFinder ( temp ) ; } } } } private class DeploymentFileNameInput implements State { private DeploymentFileNameInput ( ) { } @ Override public State execute ( ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( ManagementMessages . InputFileNamePrompt ) ; theConsole . printf ( NEW_LINE ) ; while ( true ) { String temp = theConsole . readLine ( "<STR_LIT>" ) ; if ( temp == null ) { theConsole . printf ( NEW_LINE ) ; return null ; } if ( temp . length ( ) > <NUM_LIT:0> ) { return new DeploymentFileFinder ( temp , true ) ; } } } } private class AEjbNameInput implements State { private String aejbName ; private String prompt ; public String getAEjbName ( ) { return aejbName ; } public void setPrompt ( String prompt ) { this . prompt = prompt ; } @ Override public State execute ( ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( ManagementMessages . AEjbNamePrompt ) ; theConsole . printf ( NEW_LINE ) ; while ( true ) { String temp ; if ( prompt == null ) temp = theConsole . readLine ( "<STR_LIT>" ) ; else temp = theConsole . readLine ( "<STR_LIT:[>" + prompt + "<STR_LIT>" ) ; if ( temp == null ) { theConsole . printf ( NEW_LINE ) ; return null ; } if ( temp . length ( ) > <NUM_LIT:0> ) { aejbName = temp ; return null ; } } } } private class ProtocolNameInput implements State { private String protocol ; public String getProtocol ( ) { return protocol ; } @ Override public State execute ( ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( ManagementMessages . ProtocolPrompt ) ; theConsole . printf ( NEW_LINE ) ; while ( true ) { String temp = theConsole . readLine ( "<STR_LIT>" ) ; if ( temp == null ) { theConsole . printf ( NEW_LINE ) ; return null ; } if ( temp . length ( ) > <NUM_LIT:0> ) { if ( temp . length ( ) == <NUM_LIT:1> ) { switch ( temp . charAt ( <NUM_LIT:0> ) ) { case '<CHAR_LIT:a>' : case '<CHAR_LIT:A>' : protocol = "<STR_LIT>" ; return null ; case '<CHAR_LIT:b>' : case '<CHAR_LIT>' : protocol = "<STR_LIT>" ; return null ; } } theConsole . printf ( ManagementMessages . UnexpectedCommandPrompt + SPACE + "<STR_LIT:'>" + temp + "<STR_LIT>" ) ; theConsole . printf ( NEW_LINE ) ; } } } } private class AEjbBlocker implements State { final AEjbNameInput input ; private AEjbBlocker ( AEjbNameInput input ) { this . input = input ; } @ Override public State execute ( ) { input . execute ( ) ; final String aejbName = input . getAEjbName ( ) ; boolean exsit = false ; try { exsit = blockAEjb ( aejbName ) ; } catch ( Exception e ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( "<STR_LIT>" ) ; theConsole . printf ( e . getMessage ( ) ) ; return new ErrorState ( ManagementMessages . NotConnectServer , new FunctionPrompt ( ) ) ; } if ( exsit == false ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( ManagementMessages . AEjbNotExist ) ; theConsole . printf ( NEW_LINE ) ; return new FunctionPrompt ( ) ; } return new AEjbResponseWaiting ( aejbName ) ; } } private class AEjbRecorver implements State { final AEjbNameInput input ; private AEjbRecorver ( AEjbNameInput input ) { this . input = input ; } @ Override public State execute ( ) { input . execute ( ) ; final String aejbName = input . getAEjbName ( ) ; boolean exsit = false ; try { exsit = recorverAEjb ( aejbName ) ; } catch ( Exception e ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( "<STR_LIT>" ) ; theConsole . printf ( e . getMessage ( ) ) ; return new ErrorState ( ManagementMessages . NotConnectServer , new FunctionPrompt ( ) ) ; } if ( exsit == false ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( ManagementMessages . AEjbNotExist ) ; theConsole . printf ( NEW_LINE ) ; return new FunctionPrompt ( ) ; } return new AEjbResponseWaiting ( aejbName ) ; } } private class AEjbSwitcher implements State { final AEjbNameInput input ; private AEjbSwitcher ( AEjbNameInput input ) { this . input = input ; } @ Override public State execute ( ) { input . setPrompt ( "<STR_LIT>" ) ; input . execute ( ) ; final String fromName = input . getAEjbName ( ) ; input . setPrompt ( "<STR_LIT>" ) ; input . execute ( ) ; final String toName = input . getAEjbName ( ) ; if ( fromName . equals ( toName ) ) return new ErrorState ( ManagementMessages . UnexpectedSameName , new FunctionPrompt ( ) ) ; ProtocolNameInput protocolInput = new ProtocolNameInput ( ) ; protocolInput . execute ( ) ; final String protocol = protocolInput . getProtocol ( ) ; boolean exsit = false ; try { exsit = switchAEjb ( fromName , toName , protocol ) ; } catch ( Exception e ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( "<STR_LIT>" ) ; theConsole . printf ( e . getMessage ( ) ) ; return new ErrorState ( ManagementMessages . NotConnectServer , new FunctionPrompt ( ) ) ; } if ( exsit == false ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( ManagementMessages . AEjbNotExist ) ; theConsole . printf ( NEW_LINE ) ; return new FunctionPrompt ( ) ; } return new SuccessState ( ManagementMessages . OperationSuccess , new FunctionPrompt ( ) ) ; } } private class AEjbResponseWaiting implements State { String aejbName ; private AEjbResponseWaiting ( String aejbName ) { this . aejbName = aejbName ; } @ Override public State execute ( ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( ManagementMessages . WaitingPrompt ) ; AEjbStatus status = AEjbStatus . BLOCKING ; int times = <NUM_LIT:0> ; do { try { Thread . sleep ( TICK . get ( ) ) ; status = getAEjbStatus ( aejbName ) ; times ++ ; theConsole . printf ( POINT ) ; } catch ( InterruptedException e ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( ManagementMessages . ThreadExceptionPrompt ) ; theConsole . printf ( NEW_LINE ) ; break ; } catch ( Exception e ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( "<STR_LIT>" ) ; theConsole . printf ( e . getMessage ( ) ) ; theConsole . printf ( NEW_LINE ) ; break ; } } while ( status != null && times < MAXCONNECTTIMES ) ; if ( status != null && times == MAXCONNECTTIMES ) return new ErrorState ( ManagementMessages . OperationTimeOutFailed , new FunctionPrompt ( ) ) ; if ( status != null ) return new ErrorState ( ManagementMessages . OperationFailed , new FunctionPrompt ( ) ) ; return new SuccessState ( ManagementMessages . OperationSuccess , new FunctionPrompt ( ) ) ; } } private class DeploymentFileFinder implements State { String buffer ; boolean file ; private DeploymentFileFinder ( String buffer ) { this . buffer = buffer ; this . file = false ; } private DeploymentFileFinder ( String buffer , boolean file ) { this . buffer = buffer ; this . file = file ; } @ Override public State execute ( ) { String jbossHome = System . getenv ( "<STR_LIT>" ) ; if ( jbossHome == null ) { return new ErrorState ( ManagementMessages . JbossHomeNotSet , null ) ; } File deployment = null ; if ( file ) { buffer = jbossHome + "<STR_LIT>" + buffer ; } try { deployment = pathCompleter . getFile ( buffer ) ; } catch ( IllegalArgumentException e ) { return new ErrorState ( e . getMessage ( ) , new FunctionPrompt ( ) ) ; } if ( deployment == null ) { return new ErrorState ( ManagementMessages . FilePathNotExist + "<STR_LIT::U+0020>" + buffer , new FunctionPrompt ( ) ) ; } if ( file ) { deployment . delete ( ) ; } else { FileOperations . copyFile ( deployment , jbossHome + "<STR_LIT>" + deployment . getName ( ) ) ; } return new SuccessState ( ManagementMessages . OperationSuccess , new FunctionPrompt ( ) ) ; } } private class DeploymentsDisplayer implements State { private DeploymentsDisplayer ( ) { } @ Override public State execute ( ) { Map < String , String [ ] > info ; try { info = getAllDeploymentsInfo ( ) ; } catch ( Exception e ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( "<STR_LIT>" ) ; theConsole . printf ( e . getMessage ( ) ) ; return new ErrorState ( ManagementMessages . NotConnectServer , new FunctionPrompt ( ) ) ; } theConsole . printf ( NEW_LINE ) ; theConsole . printf ( SPACE ) ; theConsole . printf ( "<STR_LIT>" ) ; theConsole . printf ( ManagementMessages . DisplayDeployments ) ; theConsole . printf ( SPACE ) ; theConsole . printf ( "<STR_LIT>" ) ; theConsole . printf ( NEW_LINE ) ; if ( info . isEmpty ( ) ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( ManagementMessages . EmptyDeployments ) ; theConsole . printf ( NEW_LINE ) ; return new FunctionPrompt ( ) ; } Iterator < Entry < String , String [ ] > > itrator = info . entrySet ( ) . iterator ( ) ; while ( itrator . hasNext ( ) ) { Entry < String , String [ ] > entry = itrator . next ( ) ; theConsole . printf ( NEW_LINE ) ; theConsole . printf ( "<STR_LIT>" ) ; theConsole . printf ( entry . getKey ( ) ) ; theConsole . printf ( NEW_LINE ) ; theConsole . printf ( "<STR_LIT>" ) ; for ( String aejbName : entry . getValue ( ) ) { theConsole . printf ( aejbName ) ; theConsole . printf ( TAB ) ; } } theConsole . printf ( NEW_LINE ) ; return new FunctionPrompt ( ) ; } } private class ErrorState implements State { private final State nextState ; private final String errorMessage ; private ErrorState ( String errorMessage ) { this ( errorMessage , null ) ; } private ErrorState ( String errorMessage , State nextState ) { this . errorMessage = errorMessage ; this . nextState = nextState ; } @ Override public State execute ( ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( "<STR_LIT>" ) ; theConsole . printf ( NEW_LINE ) ; theConsole . printf ( errorMessage ) ; theConsole . printf ( NEW_LINE ) ; theConsole . printf ( NEW_LINE ) ; return nextState ; } } private class SuccessState implements State { private final State nextState ; private final String sMessage ; private SuccessState ( String sMessage ) { this ( sMessage , null ) ; } private SuccessState ( String sMessage , State nextState ) { this . sMessage = sMessage ; this . nextState = nextState ; } @ Override public State execute ( ) { theConsole . printf ( NEW_LINE ) ; theConsole . printf ( "<STR_LIT>" ) ; theConsole . printf ( NEW_LINE ) ; theConsole . printf ( sMessage ) ; theConsole . printf ( NEW_LINE ) ; try { Thread . sleep ( <NUM_LIT> ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } return nextState ; } } private class ConnectState implements State { @ Override public State execute ( ) { theConsole . printf ( ManagementMessages . ConnectPrompt ) ; theConsole . printf ( NEW_LINE ) ; while ( true ) { String temp = theConsole . readLine ( "<STR_LIT>" ) ; if ( temp == null ) { theConsole . printf ( NEW_LINE ) ; return null ; } if ( temp . length ( ) > <NUM_LIT:0> ) { if ( temp . equals ( "<STR_LIT>" ) ) break ; else { theConsole . printf ( ManagementMessages . UnexpectedCommandPrompt + SPACE + "<STR_LIT:'>" + temp + "<STR_LIT>" ) ; theConsole . printf ( NEW_LINE ) ; } } } try { getAndInvokeClientEjb ( ) ; } catch ( Exception e ) { theConsole . printf ( NEW_LINE ) ; return new ErrorState ( ManagementMessages . NotConnectServer , new ConnectState ( ) ) ; } return new FunctionPrompt ( ) ; } } private static boolean switchAEjb ( String fromName , String toName , String protocol ) throws Exception { return getAndManageClientEjb ( fromName , toName , "<STR_LIT>" , protocol ) ; } private static boolean blockAEjb ( String aejbName ) throws Exception { return getAndManageClientEjb ( aejbName , "<STR_LIT>" ) ; } private static boolean recorverAEjb ( String aejbName ) throws Exception { return getAndManageClientEjb ( aejbName , "<STR_LIT>" ) ; } private static AEjbStatus getAEjbStatus ( String aejbName ) throws Exception { getAndInvokeClientEjb ( ) ; return client . getAEjbStatus ( aejbName ) ; } private static Map < String , String [ ] > getAllDeploymentsInfo ( ) throws Exception { getAndInvokeClientEjb ( ) ; return client . listAEjbs ( ) ; } private static void getAndInvokeClientEjb ( ) throws Exception { Object remoteClient = context . lookup ( CLIENT_EJB_JNDI ) ; Method method = getClientMethod ( remoteClient , "<STR_LIT>" ) ; client = ( AEjbClient ) method . invoke ( remoteClient ) ; } private static boolean getAndManageClientEjb ( String aejbName , String methodName ) throws Exception { Object remoteClient = context . lookup ( CLIENT_EJB_JNDI ) ; Method method = getClientMethod ( remoteClient , methodName ) ; return ( Boolean ) method . invoke ( remoteClient , aejbName ) ; } private static boolean getAndManageClientEjb ( String fromName , String toName , String methodName , String protocol ) throws Exception { Object remoteClient = context . lookup ( CLIENT_EJB_JNDI ) ; Method method = getClientMethod ( remoteClient , methodName ) ; return ( Boolean ) method . invoke ( remoteClient , fromName , toName , protocol ) ; } private static Method getClientMethod ( Object remoteClient , String methodName ) { for ( Method me : remoteClient . getClass ( ) . getMethods ( ) ) { if ( me . getName ( ) . contains ( methodName ) ) { return me ; } } return null ; } private interface State { State execute ( ) ; } public static boolean isWindows ( ) { return SecurityActions . getSystemProperty ( "<STR_LIT>" ) . toLowerCase ( ) . indexOf ( "<STR_LIT>" ) >= <NUM_LIT:0> ; } } </s>
<s> package org . nju . artemis . aejb . management . cli ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . FileWriter ; import java . io . InputStream ; import java . io . PrintWriter ; public class FileOperations { public FileOperations ( ) { } public static void newFolder ( String folderPath ) { try { String filePath = folderPath ; filePath = filePath . toString ( ) ; java . io . File myFilePath = new java . io . File ( filePath ) ; if ( ! myFilePath . exists ( ) ) { myFilePath . mkdir ( ) ; } } catch ( Exception e ) { System . out . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } } public static void newFile ( String filePathAndName , String fileContent ) { try { String filePath = filePathAndName ; filePath = filePath . toString ( ) ; File myFilePath = new File ( filePath ) ; if ( ! myFilePath . exists ( ) ) { myFilePath . createNewFile ( ) ; } FileWriter resultFile = new FileWriter ( myFilePath ) ; PrintWriter myFile = new PrintWriter ( resultFile ) ; String strContent = fileContent ; myFile . println ( strContent ) ; resultFile . close ( ) ; } catch ( Exception e ) { System . out . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } } public static void delFile ( String filePathAndName ) { try { String filePath = filePathAndName ; java . io . File myDelFile = new java . io . File ( filePath ) ; myDelFile . delete ( ) ; } catch ( Exception e ) { System . out . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } } public static void delFolder ( String folderPath ) { try { delAllFile ( folderPath ) ; String filePath = folderPath ; filePath = filePath . toString ( ) ; java . io . File myFilePath = new java . io . File ( filePath ) ; myFilePath . delete ( ) ; } catch ( Exception e ) { System . out . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } } public static void delAllFile ( String path ) { File file = new File ( path ) ; if ( ! file . exists ( ) ) { return ; } if ( ! file . isDirectory ( ) ) { return ; } String [ ] tempList = file . list ( ) ; File temp = null ; for ( int i = <NUM_LIT:0> ; i < tempList . length ; i ++ ) { if ( path . endsWith ( File . separator ) ) { temp = new File ( path + tempList [ i ] ) ; } else { temp = new File ( path + File . separator + tempList [ i ] ) ; } if ( temp . isFile ( ) ) { temp . delete ( ) ; } if ( temp . isDirectory ( ) ) { delAllFile ( path + "<STR_LIT:/>" + tempList [ i ] ) ; delFolder ( path + "<STR_LIT:/>" + tempList [ i ] ) ; } } } public static void copyFile ( File oldfile , String newPath ) { try { int byteread = <NUM_LIT:0> ; delFile ( newPath ) ; Thread . sleep ( <NUM_LIT> ) ; if ( oldfile . exists ( ) ) { InputStream inStream = new FileInputStream ( oldfile ) ; FileOutputStream fs = new FileOutputStream ( newPath ) ; byte [ ] buffer = new byte [ <NUM_LIT> ] ; while ( ( byteread = inStream . read ( buffer ) ) != - <NUM_LIT:1> ) { fs . write ( buffer , <NUM_LIT:0> , byteread ) ; } inStream . close ( ) ; fs . close ( ) ; } } catch ( Exception e ) { System . out . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } } public static void copyFolder ( String oldPath , String newPath ) { try { ( new File ( newPath ) ) . mkdirs ( ) ; File a = new File ( oldPath ) ; String [ ] file = a . list ( ) ; File temp = null ; for ( int i = <NUM_LIT:0> ; i < file . length ; i ++ ) { if ( oldPath . endsWith ( File . separator ) ) { temp = new File ( oldPath + file [ i ] ) ; } else { temp = new File ( oldPath + File . separator + file [ i ] ) ; } if ( temp . isFile ( ) ) { FileInputStream input = new FileInputStream ( temp ) ; FileOutputStream output = new FileOutputStream ( newPath + "<STR_LIT:/>" + ( temp . getName ( ) ) . toString ( ) ) ; byte [ ] b = new byte [ <NUM_LIT> * <NUM_LIT:5> ] ; int len ; while ( ( len = input . read ( b ) ) != - <NUM_LIT:1> ) { output . write ( b , <NUM_LIT:0> , len ) ; } output . flush ( ) ; output . close ( ) ; input . close ( ) ; } if ( temp . isDirectory ( ) ) { copyFolder ( oldPath + "<STR_LIT:/>" + file [ i ] , newPath + "<STR_LIT:/>" + file [ i ] ) ; } } } catch ( Exception e ) { System . out . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } } public static void moveFile ( String oldPath , String newPath ) { File oldfile = new File ( oldPath ) ; copyFile ( oldfile , newPath ) ; delFile ( oldPath ) ; } public static void moveFolder ( String oldPath , String newPath ) { copyFolder ( oldPath , newPath ) ; delFolder ( oldPath ) ; } } </s>
<s> package org . nju . artemis . aejb . management . cli ; import java . io . File ; public class DefaultFilenameTabCompleter extends FilenameTabCompleter { @ Override protected boolean startsWithRoot ( String path ) { return path . startsWith ( File . separator ) ; } } </s>
<s> package org . nju . artemis . aejb . management . client ; import org . jboss . logging . Logger ; import org . jboss . msc . service . Service ; import org . jboss . msc . service . StartContext ; import org . jboss . msc . service . StartException ; import org . jboss . msc . service . StopContext ; public class AEjbClientService implements Service < AEjbClient > { private static final Logger log = Logger . getLogger ( AEjbClientService . class ) ; public AEjbClientService ( ) { } @ Override public AEjbClient getValue ( ) throws IllegalStateException , IllegalArgumentException { AEjbClientImpl . INSTANCE . refreshAEjbsInfo ( ) ; return AEjbClientImpl . INSTANCE ; } @ Override public void start ( StartContext context ) throws StartException { log . info ( "<STR_LIT>" ) ; } @ Override public void stop ( StopContext context ) { log . info ( "<STR_LIT>" ) ; } } </s>
<s> package org . nju . artemis . aejb . management . client ; import java . util . Collection ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Iterator ; import java . util . Map ; import java . util . Map . Entry ; import java . util . Set ; import org . jboss . logging . Logger ; import org . nju . artemis . aejb . component . AEjbUtilities ; import org . nju . artemis . aejb . component . AcContainer ; public class AEjbClientImpl implements AEjbClient { private static final long serialVersionUID = <NUM_LIT:1L> ; Logger log = Logger . getLogger ( AEjbClientImpl . class ) ; private Map < String , String [ ] > aejbInfos = new HashMap < String , String [ ] > ( ) ; private Set < String > aejbNames = new HashSet < String > ( ) ; private Map < String , AEjbStatus > aejbStatus = new HashMap < String , AEjbStatus > ( ) ; private Map < String , String > switchMap = new HashMap < String , String > ( ) ; private Map < String , String > protocols = new HashMap < String , String > ( ) ; public static final AEjbClientImpl INSTANCE = new AEjbClientImpl ( ) ; public enum AEjbStatus { BLOCKING , RESUMING , } private AEjbClientImpl ( ) { } public Map < String , String [ ] > listAEjbs ( ) { return aejbInfos ; } void refreshAEjbsInfo ( ) { Map < String , Map < String , AcContainer > > deploymentUnits = AEjbUtilities . getAllAEjbsInfo ( ) ; Iterator < Entry < String , Map < String , AcContainer > > > iterator = deploymentUnits . entrySet ( ) . iterator ( ) ; reset ( ) ; while ( iterator . hasNext ( ) ) { Entry < String , Map < String , AcContainer > > entry = iterator . next ( ) ; Map < String , AcContainer > aejbs = entry . getValue ( ) ; int size = aejbs . size ( ) ; Collection < String > aejbNames = new HashSet < String > ( aejbs . keySet ( ) ) ; aejbInfos . put ( entry . getKey ( ) , aejbs . keySet ( ) . toArray ( new String [ size ] ) ) ; this . aejbNames . addAll ( aejbNames ) ; } } private void reset ( ) { aejbInfos . clear ( ) ; aejbNames . clear ( ) ; } public boolean blockAEjb ( String aejbName ) { if ( aejbStatus . containsKey ( aejbName ) && aejbStatus . get ( aejbName ) == AEjbStatus . BLOCKING ) return true ; else if ( aejbStatus . containsKey ( aejbName ) || aejbNames . contains ( aejbName ) ) { aejbStatus . put ( aejbName , AEjbStatus . BLOCKING ) ; return true ; } return false ; } public Map < String , AEjbStatus > getAEjbStatus ( ) { return aejbStatus ; } public AEjbStatus getAEjbStatus ( String aejbName ) { return aejbStatus . get ( aejbName ) ; } public void clearAEjbStatus ( ) { aejbStatus . clear ( ) ; } public void clearSwitchMap ( ) { switchMap . clear ( ) ; } @ Override public boolean resumeAEjb ( String aejbName ) { if ( aejbStatus . containsKey ( aejbName ) && aejbStatus . get ( aejbName ) == AEjbStatus . RESUMING ) return true ; else if ( aejbStatus . containsKey ( aejbName ) || aejbNames . contains ( aejbName ) ) { aejbStatus . put ( aejbName , AEjbStatus . RESUMING ) ; return true ; } return false ; } @ Override public boolean switchAEjb ( String fromName , String toName , String protocol ) { if ( switchMap . containsKey ( fromName ) && toName . equals ( switchMap . get ( fromName ) ) ) { protocols . put ( fromName , protocol ) ; return true ; } if ( aejbNames . contains ( fromName ) && aejbNames . contains ( toName ) ) { switchMap . put ( fromName , toName ) ; protocols . put ( fromName , protocol ) ; return true ; } return false ; } @ Override public Map < String , String > getSwitchMap ( ) { return switchMap ; } @ Override public String getProtocol ( String name ) { return protocols . get ( name ) ; } @ Override public boolean replaceAEjb ( String fromName , String toName , String protocol ) { return false ; } } </s>
<s> package org . nju . artemis . aejb . management . client ; import java . io . Serializable ; import java . util . Map ; import org . nju . artemis . aejb . management . client . AEjbClientImpl . AEjbStatus ; public interface AEjbClient extends Serializable { Map < String , String [ ] > listAEjbs ( ) ; Map < String , AEjbStatus > getAEjbStatus ( ) ; AEjbStatus getAEjbStatus ( String aejbName ) ; boolean blockAEjb ( String aejbName ) ; boolean resumeAEjb ( String aejbName ) ; void clearAEjbStatus ( ) ; void clearSwitchMap ( ) ; boolean switchAEjb ( String fromName , String toName , String protocol ) ; Map < String , String > getSwitchMap ( ) ; String getProtocol ( String name ) ; boolean replaceAEjb ( String fromName , String toName , String protocol ) ; } </s>
<s> package org . nju . artemis . aejb ; import junit . framework . Test ; import junit . framework . TestCase ; import junit . framework . TestSuite ; public class AppTest extends TestCase { public AppTest ( String testName ) { super ( testName ) ; } public static Test suite ( ) { return new TestSuite ( AppTest . class ) ; } public void testApp ( ) { assertTrue ( true ) ; } } </s>
<s> package org . nju . artemis . aejb . preprocessor ; import java . util . LinkedList ; import java . util . List ; public class StateMachine { private int start ; private int end ; private List states = new LinkedList ( ) ; private List < Event > events = new LinkedList < Event > ( ) ; public StateMachine ( ) { } public int getStart ( ) { return start ; } public void setStart ( int start ) { this . start = start ; } public int getEnd ( ) { return end ; } public void setEnd ( int end ) { this . end = end ; } public List getStates ( ) { return states ; } public void setStates ( List states ) { this . states = states ; } public int getstate ( int head , String event ) { for ( int i = <NUM_LIT:0> ; i < events . size ( ) ; i ++ ) { Event e = events . get ( i ) ; if ( e . getHead ( ) == head && e . getEvent ( ) . equals ( event ) ) return e . getTail ( ) ; } return - <NUM_LIT:1> ; } public int stateindex ( int index ) { for ( int i = <NUM_LIT:0> ; i < states . size ( ) ; i ++ ) { if ( ( Integer ) states . get ( i ) == index ) return i ; } return - <NUM_LIT:1> ; } public void addState ( int state ) { states . add ( state ) ; } public void deleteState ( int state ) { for ( int i = <NUM_LIT:0> ; i < states . size ( ) ; i ++ ) { if ( ( Integer ) states . get ( i ) == state ) states . remove ( i ) ; } } public void mergeStates ( int s1 , int s2 ) { int s1_index = states . indexOf ( s1 ) ; states . remove ( s1_index ) ; for ( int i = <NUM_LIT:0> ; i < events . size ( ) ; i ++ ) { Event e = events . get ( i ) ; if ( e . getTail ( ) == s1 ) { e . setTail ( s2 ) ; } } } public int getStatesCount ( ) { return states . size ( ) ; } public void addEvent ( Event event ) { events . add ( event ) ; } public void deleteEvent ( Event event ) { for ( int i = <NUM_LIT:0> ; i < events . size ( ) ; i ++ ) { if ( event . getEvent ( ) . equals ( events . get ( i ) . getEvent ( ) ) ) events . remove ( i ) ; } } public List < Event > getEvents ( ) { return events ; } } </s>
<s> package org . nju . artemis . aejb . preprocessor ; import java . io . BufferedOutputStream ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . util . jar . Attributes ; import java . util . jar . JarEntry ; import java . util . jar . JarInputStream ; import java . util . jar . JarOutputStream ; import java . util . jar . Manifest ; public class JarTool { private static final int BUFFER_SIZE = <NUM_LIT> ; private static String MAIN_CLASS ; private byte [ ] mBuffer = new byte [ BUFFER_SIZE ] ; private int mByteCount = <NUM_LIT:0> ; private boolean mVerbose = false ; private String mDestJarName = "<STR_LIT>" ; public JarTool ( ) { } public void jarDir ( File dirOrFile2Jar , File destJar ) throws IOException { if ( dirOrFile2Jar == null || destJar == null ) throw new IllegalArgumentException ( ) ; mDestJarName = destJar . getCanonicalPath ( ) ; FileOutputStream fout = new FileOutputStream ( destJar ) ; JarOutputStream jout ; if ( MAIN_CLASS != null ) { Manifest manifest = new Manifest ( ) ; Attributes attrs = manifest . getMainAttributes ( ) ; attrs . putValue ( "<STR_LIT>" , "<STR_LIT:1.0>" ) ; attrs . putValue ( "<STR_LIT>" , "<STR_LIT:.>" ) ; attrs . putValue ( "<STR_LIT>" , MAIN_CLASS ) ; jout = new JarOutputStream ( fout , manifest ) ; } else { jout = new JarOutputStream ( fout ) ; } try { jarDir ( dirOrFile2Jar , jout , null ) ; } catch ( IOException ioe ) { throw ioe ; } finally { jout . close ( ) ; fout . close ( ) ; } } public void unjarDir ( File jarFile , File destDir ) throws IOException { BufferedOutputStream dest = null ; FileInputStream fis = new FileInputStream ( jarFile ) ; unjar ( fis , destDir ) ; } public void unjar ( InputStream in , File destDir ) throws IOException { BufferedOutputStream dest = null ; JarInputStream jis = new JarInputStream ( in ) ; JarEntry entry ; while ( ( entry = jis . getNextJarEntry ( ) ) != null ) { if ( entry . isDirectory ( ) ) { File dir = new File ( destDir , entry . getName ( ) ) ; dir . mkdir ( ) ; if ( entry . getTime ( ) != - <NUM_LIT:1> ) dir . setLastModified ( entry . getTime ( ) ) ; continue ; } String name = entry . getName ( ) ; while ( name . contains ( "<STR_LIT:/>" ) || name . contains ( "<STR_LIT>" ) ) { File fdir = new File ( destDir . getCanonicalPath ( ) + "<STR_LIT:/>" + name . split ( "<STR_LIT:/>" ) [ <NUM_LIT:0> ] ) ; int index = name . indexOf ( "<STR_LIT:/>" ) ; if ( ! fdir . exists ( ) ) fdir . mkdir ( ) ; name = name . substring ( index + <NUM_LIT:1> ) ; } int count ; byte data [ ] = new byte [ BUFFER_SIZE ] ; File destFile = new File ( destDir , entry . getName ( ) ) ; if ( mVerbose ) System . out . println ( "<STR_LIT>" + destFile + "<STR_LIT>" + entry . getName ( ) ) ; FileOutputStream fos = new FileOutputStream ( destFile ) ; dest = new BufferedOutputStream ( fos , BUFFER_SIZE ) ; while ( ( count = jis . read ( data , <NUM_LIT:0> , BUFFER_SIZE ) ) != - <NUM_LIT:1> ) { dest . write ( data , <NUM_LIT:0> , count ) ; } dest . flush ( ) ; dest . close ( ) ; if ( entry . getTime ( ) != - <NUM_LIT:1> ) destFile . setLastModified ( entry . getTime ( ) ) ; } jis . close ( ) ; } public void setVerbose ( boolean b ) { mVerbose = b ; } private static final char SEP = '<CHAR_LIT:/>' ; private void jarDir ( File dirOrFile2jar , JarOutputStream jos , String path ) throws IOException { if ( mVerbose ) System . out . println ( "<STR_LIT>" + dirOrFile2jar ) ; if ( dirOrFile2jar . isDirectory ( ) ) { String [ ] dirList = dirOrFile2jar . list ( ) ; String subPath = ( path == null ) ? "<STR_LIT>" : ( path + dirOrFile2jar . getName ( ) + SEP ) ; if ( path != null ) { JarEntry je = new JarEntry ( subPath ) ; je . setTime ( dirOrFile2jar . lastModified ( ) ) ; jos . putNextEntry ( je ) ; jos . flush ( ) ; jos . closeEntry ( ) ; } for ( int i = <NUM_LIT:0> ; i < dirList . length ; i ++ ) { File f = new File ( dirOrFile2jar , dirList [ i ] ) ; jarDir ( f , jos , subPath ) ; } } else { if ( dirOrFile2jar . getCanonicalPath ( ) . equals ( mDestJarName ) ) { if ( mVerbose ) System . out . println ( "<STR_LIT>" + dirOrFile2jar . getPath ( ) ) ; return ; } if ( mVerbose ) System . out . println ( "<STR_LIT>" + dirOrFile2jar . getPath ( ) ) ; FileInputStream fis = new FileInputStream ( dirOrFile2jar ) ; try { JarEntry entry = new JarEntry ( path + dirOrFile2jar . getName ( ) ) ; entry . setTime ( dirOrFile2jar . lastModified ( ) ) ; jos . putNextEntry ( entry ) ; while ( ( mByteCount = fis . read ( mBuffer ) ) != - <NUM_LIT:1> ) { jos . write ( mBuffer , <NUM_LIT:0> , mByteCount ) ; if ( mVerbose ) System . out . println ( "<STR_LIT>" + mByteCount + "<STR_LIT>" ) ; } jos . flush ( ) ; jos . closeEntry ( ) ; } catch ( IOException ioe ) { throw ioe ; } finally { fis . close ( ) ; } } } public static void main ( String [ ] args ) throws IOException { JarTool jarHelper = new JarTool ( ) ; jarHelper . mVerbose = true ; File destJar = new File ( "<STR_LIT>" ) ; File dirOrFile2Jar = new File ( "<STR_LIT>" ) ; File jar2Dir = new File ( "<STR_LIT>" ) ; jar2Dir . mkdir ( ) ; jarHelper . unjarDir ( destJar , jar2Dir ) ; jarHelper . jarDir ( jar2Dir , dirOrFile2Jar ) ; } } </s>
<s> package org . nju . artemis . aejb . preprocessor ; import java . util . Iterator ; import java . util . LinkedList ; import java . util . List ; import org . objectweb . asm . tree . AbstractInsnNode ; import org . objectweb . asm . tree . MethodNode ; public class ControlFlow { List < flow > con = new LinkedList < flow > ( ) ; public flow getFlow ( int src ) { Iterator < flow > f = con . iterator ( ) ; while ( f . hasNext ( ) ) { flow fn = f . next ( ) ; if ( fn . src == src ) { return fn ; } } return null ; } public void addFlow ( int src , int dst ) { flow fl = getFlow ( src ) ; if ( fl != null ) { fl . setDst ( dst ) ; } else { con . add ( new flow ( src , dst ) ) ; } } public int getDstSize ( int src ) { return getFlow ( src ) . dst . size ( ) ; } public List getDst ( int src ) { return getFlow ( src ) . getDst ( ) ; } public List < AbstractInsnNode > getDstNode ( MethodNode mn , int src ) { List < AbstractInsnNode > dstnode = new LinkedList < AbstractInsnNode > ( ) ; for ( int i = <NUM_LIT:0> ; i < getDstSize ( src ) ; i ++ ) { dstnode . add ( ( AbstractInsnNode ) mn . instructions . get ( ( Integer ) getDst ( src ) . get ( i ) ) ) ; } return dstnode ; } public void showControlFlow ( ) { Iterator < flow > f = con . iterator ( ) ; while ( f . hasNext ( ) ) { flow fn = f . next ( ) ; System . out . print ( fn . src + "<STR_LIT>" ) ; List d = getDst ( fn . src ) ; for ( int i = <NUM_LIT:0> ; i < d . size ( ) ; i ++ ) { System . out . print ( d . get ( i ) + "<STR_LIT:U+002C>" ) ; } System . out . println ( ) ; } } } class flow { int src ; boolean isWhile ; List dst = new LinkedList ( ) ; public flow ( int src , int dst ) { this . src = src ; this . dst . add ( dst ) ; isWhile = false ; } public void setSrc ( int s ) { src = s ; } public void setDst ( int d ) { dst . add ( d ) ; } public int getSrc ( ) { return src ; } public List getDst ( ) { return dst ; } public boolean getIsWhile ( ) { return isWhile ; } public void setIsWhile ( boolean w ) { isWhile = w ; } } </s>