Codota Logo
ProxettaFactory
Code IndexAdd Codota to your IDE (free)

How to use
ProxettaFactory
in
jodd.proxetta

Best Java code snippets using jodd.proxetta.ProxettaFactory (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
BufferedReader b =
  • Codota IconInputStream in;new BufferedReader(new InputStreamReader(in))
  • Codota IconReader in;new BufferedReader(in)
  • Codota IconFile file;new BufferedReader(new FileReader(file))
  • Smart code suggestions by Codota
}
origin: oblac/jodd

/**
 * Defines class or interface to wrap.
 * For setting the interface of the resulting class,
 * use {@link #setTargetInterface(Class)}.
 */
@Override
public WrapperProxettaFactory setTarget(final Class target) {
  super.setTarget(target);
  this.targetClassOrInterface = target;
  return this;
}
origin: oblac/jodd

/**
 * Creates new instance of created class.
 * Assumes default no-arg constructor.
 */
public Object newInstance() {
  Class type = define();
  try {
    return ClassUtil.newInstance(type);
  } catch (Exception ex) {
    throw new ProxettaException("Invalid Proxetta class", ex);
  }
}
origin: oblac/jodd

/**
 * Defines class input stream as a target.
 */
protected T setTarget(final InputStream target) {
  assertTargetIsNotDefined();
  targetInputStream = target;
  targetClass = null;
  targetClassName = null;
  return _this();
}
origin: oblac/jodd

/**
 * Returns byte array of created class.
 */
public byte[] create() {
  process();
  byte[] result = toByteArray();
  dumpClassInDebugFolder(result);
  if ((!proxetta.isForced()) && (!isProxyApplied())) {
    if (log.isDebugEnabled()) {
      log.debug("Proxy not applied: " + StringUtil.toSafeString(targetClassName));
    }
    return null;
  }
  if (log.isDebugEnabled()) {
    log.debug("Proxy created " + StringUtil.toSafeString(targetClassName));
  }
  return result;
}
origin: oblac/jodd

/**
 * Applies proxetta on bean class before bean registration.
 */
@SuppressWarnings("unchecked")
@Override
protected <T> BeanDefinition<T> createBeanDefinitionForRegistration(
    final String name,
    Class<T> type,
    final Scope scope,
    final WiringMode wiringMode,
    final Consumer<T> consumer)
{
  if (proxetta != null) {
    final Class originalType = type;
    final ProxettaFactory builder = proxetta.proxy();
    builder.setTarget(type);
    type = builder.define();
    return new ProxettaBeanDefinition(
      name,
      type,
      scope,
      wiringMode,
      originalType,
      proxetta.getAspects(new ProxyAspect[0]),
      consumer);
  }
  return super.createBeanDefinitionForRegistration(name, type, scope, wiringMode, consumer);
}
origin: oblac/jodd

@Test
void testMethodAnnotationsProxy() {
  ProxyProxetta proxetta = Proxetta
      .proxyProxetta()
      .withAspect(
        ProxyAspect.of(HeroProxyAdvice.class,
          ((ProxyPointcut) MethodInfo::isTopLevelMethod).and(AllRealMethodsPointcut.get())
        ))
      //.setDebugFolder(FileUtil.file("~"))
      ;
  ProxettaFactory proxettaFactory = proxetta.proxy();
  proxettaFactory.setTarget(Hero.class);
  proxetta.setVariableClassName(true);
  Hero hero = (Hero) proxettaFactory.newInstance();
  assertEquals("BatmanHero37W88.3CatWoman99speeeeedXRAYnull", hero.name());
}
origin: oblac/jodd

/**
 * Returns proxy class name.
 */
public String getProxyClassName() {
  assertProxyIsCreated();
  return proxyClassName;
}
origin: oblac/jodd

/**
 * Sets requested proxy class name.
 */
public T setTargetProxyClassName(final String targetProxyClassName) {
  this.requestedProxyClassName = targetProxyClassName;
  return _this();
}
origin: oblac/jodd

/**
 * Reads the target and creates destination class.
 */
protected void process() {
  if (targetInputStream == null) {
    throw new ProxettaException("Target missing: " + targetClassName);
  }
  // create class reader
  final ClassReader classReader;
  try {
    classReader = new ClassReader(targetInputStream);
  } catch (IOException ioex) {
    throw new ProxettaException("Error reading class input stream", ioex);
  }
  // reads information
  final TargetClassInfoReader targetClassInfoReader = new TargetClassInfoReader(proxetta.getClassLoader());
  classReader.accept(targetClassInfoReader, 0);
  this.destClassWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
  // create proxy
  if (log.isDebugEnabled()) {
    log.debug("processing: " + classReader.getClassName());
  }
  WorkData wd = process(classReader, targetClassInfoReader);
  // store important data
  proxyApplied = wd.proxyApplied;
  proxyClassName = wd.thisReference.replace('/', '.');
}
origin: oblac/jodd

process();
if ((!proxetta.isForced()) && (!isProxyApplied())) {
  if (log.isDebugEnabled()) {
    log.debug("Proxy not applied: " + StringUtil.toSafeString(targetClassName));
  final byte[] bytes = toByteArray();
  dumpClassInDebugFolder(bytes);
  return DefineClass.of(getProxyClassName(), bytes, classLoader);
} catch (Exception ex) {
  throw new ProxettaException("Class definition failed", ex);
origin: oblac/jodd

final Proxetta proxetta = proxettaSupplier.get();
existing = proxetta.proxy().setTarget(actionClass).define();
origin: oblac/jodd

@Test
void testClassAnnotationsProxy() {
  ProxyProxetta proxetta = Proxetta
    .proxyProxetta()
    .withAspect(
        new ProxyAspect(HeroProxyAdvice2.class,
          ((ProxyPointcut) MethodInfo::isTopLevelMethod).and(AllRealMethodsPointcut.get())
        ))
      //.setDebugFolder("/Users/igor/")
      ;
  ProxettaFactory proxettaFactory = proxetta.proxy();
  proxettaFactory.setTarget(Hero.class);
  proxetta.setVariableClassName(true);
  Hero hero = (Hero) proxettaFactory.newInstance();
  assertEquals("SilverHero89W99.222None1000speeeeedXRAYnull", hero.name());
}
origin: oblac/jodd

/**
 * Returns <code>true</code> if at least one method was wrapped.
 */
public boolean isProxyApplied() {
  assertProxyIsCreated();
  return proxyApplied;
}
origin: org.jodd/jodd-proxetta

/**
 * Sets requested proxy class name.
 */
public T setTargetProxyClassName(final String targetProxyClassName) {
  this.requestedProxyClassName = targetProxyClassName;
  return _this();
}
origin: org.jodd/jodd-proxetta

/**
 * Reads the target and creates destination class.
 */
protected void process() {
  if (targetInputStream == null) {
    throw new ProxettaException("Target missing: " + targetClassName);
  }
  // create class reader
  final ClassReader classReader;
  try {
    classReader = new ClassReader(targetInputStream);
  } catch (IOException ioex) {
    throw new ProxettaException("Error reading class input stream", ioex);
  }
  // reads information
  final TargetClassInfoReader targetClassInfoReader = new TargetClassInfoReader(proxetta.getClassLoader());
  classReader.accept(targetClassInfoReader, 0);
  this.destClassWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
  // create proxy
  if (log.isDebugEnabled()) {
    log.debug("processing: " + classReader.getClassName());
  }
  WorkData wd = process(classReader, targetClassInfoReader);
  // store important data
  proxyApplied = wd.proxyApplied;
  proxyClassName = wd.thisReference.replace('/', '.');
}
origin: oblac/jodd

@Override
public ProxyProxettaFactory setTarget(final InputStream target) {
  return super.setTarget(target);
}
origin: org.jodd/jodd-proxetta

/**
 * Returns byte array of created class.
 */
public byte[] create() {
  process();
  byte[] result = toByteArray();
  dumpClassInDebugFolder(result);
  if ((!proxetta.isForced()) && (!isProxyApplied())) {
    if (log.isDebugEnabled()) {
      log.debug("Proxy not applied: " + StringUtil.toSafeString(targetClassName));
    }
    return null;
  }
  if (log.isDebugEnabled()) {
    log.debug("Proxy created " + StringUtil.toSafeString(targetClassName));
  }
  return result;
}
origin: org.jodd/jodd-petite

/**
 * Applies proxetta on bean class before bean registration.
 */
@SuppressWarnings("unchecked")
@Override
protected <T> BeanDefinition<T> createBeanDefinitionForRegistration(
    final String name,
    Class<T> type,
    final Scope scope,
    final WiringMode wiringMode,
    final Consumer<T> consumer)
{
  if (proxetta != null) {
    final Class originalType = type;
    final ProxettaFactory builder = proxetta.proxy();
    builder.setTarget(type);
    type = builder.define();
    return new ProxettaBeanDefinition(
      name,
      type,
      scope,
      wiringMode,
      originalType,
      proxetta.getAspects(new ProxyAspect[0]),
      consumer);
  }
  return super.createBeanDefinitionForRegistration(name, type, scope, wiringMode, consumer);
}
origin: oblac/jodd

/**
 * Defines class as a target.
 */
public T setTarget(final Class target) {
  assertTargetIsNotDefined();
  try {
    targetInputStream = ClassLoaderUtil.getClassAsStream(target);
    if (targetInputStream == null) {
      throw new ProxettaException("Target class not found: " + target.getName());
    }
    targetClass = target;
    targetClassName = target.getName();
  }
  catch (IOException ioex) {
    StreamUtil.close(targetInputStream);
    throw new ProxettaException("Unable to stream class: " + target.getName(), ioex);
  }
  return _this();
}
origin: org.jodd/jodd-proxetta

/**
 * Creates new instance of created class.
 * Assumes default no-arg constructor.
 */
public Object newInstance() {
  Class type = define();
  try {
    return ClassUtil.newInstance(type);
  } catch (Exception ex) {
    throw new ProxettaException("Invalid Proxetta class", ex);
  }
}
jodd.proxettaProxettaFactory

Javadoc

Proxetta builder. While Proxetta only holds aspects and configuration, ProxettaBuilder deals with the actually building proxies and wrappers over provided target.

Most used methods

  • setTarget
    Defines class name as a target. Class will not be loaded by classloader!
  • define
    Defines class.
  • _this
  • assertProxyIsCreated
    Checks if proxy is created and throws an exception if not.
  • assertTargetIsNotDefined
    Checks if target is not defined yet.
  • dumpClassInDebugFolder
    Writes created class content to output folder for debugging purposes.
  • getProxyClassName
    Returns proxy class name.
  • isProxyApplied
    Returns true if at least one method was wrapped.
  • process
  • toByteArray
    Returns raw bytecode.
  • newInstance
    Creates new instance of created class. Assumes default no-arg constructor.
  • newInstance

Popular in Java

  • Making http requests using okhttp
  • findViewById (Activity)
  • onRequestPermissionsResult (Fragment)
  • setScale (BigDecimal)
    Returns a BigDecimal whose scale is the specified value, and whose value is numerically equal to thi
  • BigInteger (java.math)
    Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in
  • MalformedURLException (java.net)
    Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a s
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • JTextField (javax.swing)
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now