public void testNonImplementorsHaveNoIndicatorValuesProblem() {
    String problem = ProblemConstants.MAPPING_CLASS_INDICATOR_VALUES_INVALID;

    SimpleContactProject project = new SimpleContactProject();
    MWVariableOneToOneMapping mapping =
        (MWVariableOneToOneMapping) project.getPersonImplDescriptor().mappingNamed("contact");

    assertTrue(
        "The mapping should not have the problem: " + problem, !hasProblem(problem, mapping));

    MWRelationalClassIndicatorFieldPolicy policy = mapping.getClassIndicatorPolicy();
    try {
      MWClassIndicatorValue value =
          (MWClassIndicatorValue)
              ClassTools.attemptNewInstance(
                  MWClassIndicatorValue.class,
                  new Class[] {
                    MWClassIndicatorFieldPolicy.class, MWMappingDescriptor.class, Object.class
                  },
                  new Object[] {policy, project.getPersonImplDescriptor(), "I"});
      value.setInclude(true);
      Collection indicatorValues =
          (Collection) ClassTools.attemptToGetFieldValue(policy, "classIndicatorValues");
      indicatorValues.add(value);
    } catch (NoSuchFieldException exception) {
      // test will fail
    } catch (NoSuchMethodException exception) {
      // test will fail
    }

    assertTrue("The mapping should have the problem: " + problem, hasProblem(problem, mapping));
  }
 private void legacy50SetTypeNameForTopLink(String typeName) {
   this.typeHandle = new MWClassHandle(this, this.buildTypeScrubber());
   if (ClassTools.classNamedIsArray(typeName)) {
     this.dimensionality = ClassTools.arrayDepthForClassNamed(typeName);
     typeName = ClassTools.elementTypeNameForClassNamed(typeName);
   }
   this.typeHandle.legacySetTypeNameForTopLink(typeName);
 }
 private Collection buildServerPlatformNames() {
   Collection servers =
       CollectionTools.sortedSet(ServerPlatformManager.instance().platformShortNames());
   String serverClassName = NullServerPlatformAdapter.instance().getServerClassName();
   servers.remove(ClassTools.shortNameForClassNamed(serverClassName));
   return servers;
 }
  public static Test suite() {
    TestSuite suite = new TestSuite(ClassTools.packageNameFor(AllFrameworkResourcesTests.class));

    suite.addTest(IconRepositoryTests.suite());
    suite.addTest(StringRepositoryTests.suite());

    return suite;
  }
Ejemplo n.º 5
0
 // checked exceptions suck
 private EISConnectionSpec newInstance(MWClass connectionSpecType) {
   try {
     return (EISConnectionSpec)
         ClassTools.newInstance(connectionSpecType.getName(), this.getClass().getClassLoader());
   } catch (ClassNotFoundException ex) {
     throw new RuntimeException(ex);
   }
 }
 /**
  * @see
  *     Diff#appendDescription(org.eclipse.persistence.tools.workbench.utility.io.IndentingPrintWriter)
  */
 public void appendDescription(IndentingPrintWriter pw) {
   if (this.different()) {
     pw.print("The ");
     pw.print(ClassTools.shortNameFor(this.javaClass));
     pw.print("s are different:");
     pw.println();
   }
   super.appendDescription(pw);
 }
 public String toString() {
   StringWriter sw = new StringWriter(200);
   PrintWriter pw = new PrintWriter(sw);
   pw.print(ClassTools.shortClassNameForObject(this));
   pw.print('(');
   this.printDeclarationOn(pw);
   pw.print(')');
   return sw.toString();
 }
 protected HelpManager buildHelpManager() {
   try {
     return (HelpManager)
         ClassTools.newInstance(
             "org.eclipse.persistence.tools.workbench.framework.help.NullHelpManager");
   } catch (ClassNotFoundException ex) {
     throw new RuntimeException(ex);
   }
 }
 private void exec(String[] args) {
   this.completeList1 = this.buildTypeList(args);
   this.completeList2 = this.buildCompleteList2();
   JFrame frame = new JFrame(ClassTools.shortClassNameForObject(this));
   frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
   frame.addWindowListener(this.buildWindowListener());
   frame.getContentPane().add(this.buildMainPanel(), "Center");
   frame.setLocation(300, 300);
   frame.setSize(400, 400);
   frame.setVisible(true);
 }
  private void updateServerPlatformWidgets(String serverClassName) {
    boolean selected = (serverClassName != null);

    if (selected) {
      ServerPlatformAdapter noServerPlatform = NullServerPlatformAdapter.instance();
      String noServerPlatformClassName =
          ClassTools.shortNameForClassNamed(noServerPlatform.getServerClassName());
      selected = !serverClassName.equals(noServerPlatformClassName);
    }

    this.useServerPlatformCheckBox.setSelected(selected);
    this.serverPlatformWidgets.setEnabled(selected);
  }
  public static Test suite() {
    TestSuite suite = new TestSuite(ClassTools.packageNameFor(AllModelMetaTests.class));

    suite.addTest(MWModifierTests.suite());
    suite.addTest(MWTypeDeclarationTests.suite());
    suite.addTest(MWMethodTests.suite());
    suite.addTest(MWClassAttributeTests.suite());
    suite.addTest(MWClassTests.suite());

    suite.addTest(MWClassRepositoryTests.suite());

    return suite;
  }
Ejemplo n.º 12
0
  /**
   * Helper method that returns the Adapter class for the given config class name.
   *
   * @throws NoSuchElementException when scModelClass is not found.
   */
  static final Class adapterClassNamed(String configClassName) {

    String adapterClassName =
        adapterPackageName
            + configClassName.substring(0, configClassName.lastIndexOf(modelClassSuffix))
            + adapterClassSuffix;
    Class adapterClass = null;
    try {
      adapterClass = ClassTools.classForName(adapterClassName);
    } catch (RuntimeException e) {
      throw new NoSuchElementException(
          "Adapter Class Not Known For SC Model Class: " + configClassName);
    }
    return adapterClass;
  }
Ejemplo n.º 13
0
  public static Test suite() {
    // *************************************************************************
    //   NOTE - NOTE - NOTE - NOTE - NOTE
    // run these tests in separate threads since they spend lots of time waiting on the database
    // servers
    // *************************************************************************
    TestSuite suite = new ActiveTestSuite(ClassTools.packageNameFor(AllModelTests.class));

    suite.addTest(DatabasePlatformRepositoryTests.suite());
    suite.addTest(DatabasePlatformTests.suite());
    suite.addTest(DatabaseTypeTests.suite());
    suite.addTest(JavaTypeDeclarationTests.suite());
    suite.addTest(JDBCTypeRepositoryTests.suite());

    return suite;
  }
 /**
  * validate the specified type name and return whether it is the name of a "core" type; the return
  * value isn't really consistent with the purpose of the method, but it provides us with a slight
  * performance improvement
  */
 private boolean checkTypeName(String typeName) {
   if (typeName.length() == 0) {
     throw new IllegalArgumentException("empty type name");
   }
   if (ClassTools.classNamedIsArray(typeName)) {
     throw new IllegalArgumentException("use MWTypeDeclaration for array types");
   }
   if (coreClassNamesContains(typeName)) {
     return true;
   }
   // "java.lang.Object" is OK, but "Java.Lang.OBJECT" is not
   String collision = coreClassNameIgnoreCase(typeName);
   if (collision != null) {
     throw new IllegalArgumentException(
         "case-insensitive name collision with \"core\" type: " + collision);
   }
   return false;
 }
 protected void exec(String[] args) throws Exception {
   File platformsFile;
   if ((args == null) || (args.length == 0)) {
     platformsFile =
         (File)
             ClassTools.invokeStaticMethod(DatabasePlatformRepository.class, "buildDefaultFile");
   } else {
     platformsFile = new File(args[0]);
   }
   WorkbenchContext wbContext = this.buildWorkbenchContext();
   Plugin plugin =
       PlatformsPluginFactory.instance().createPlugin(wbContext.getApplicationContext());
   DatabasePlatformRepositoryNode reposNode =
       (DatabasePlatformRepositoryNode) plugin.open(platformsFile, wbContext);
   this.nodes = this.buildNodes(reposNode);
   this.max = this.nodes.length - 1;
   this.index = 0;
   this.page = this.nodes[this.index].propertiesPage(null);
   this.pageIsCleared = false;
   this.openWindow();
 }
 public void testBogusDoubleArgument2() throws Exception {
   TestModel testModel = new TestModel("root");
   testModel.addNode("root", "child");
   Target target = new Target(testModel, TestModel.STRINGS_TREE, new String[] {"root", "child"});
   Method method =
       ClassTools.method(
           target,
           "collectionChangedDoubleArgument",
           new Class[] {TreeChangeEvent.class, Object.class});
   boolean exCaught = false;
   try {
     TreeChangeListener listener =
         ReflectiveChangeListener.buildTreeChangeListener(target, method);
     fail("bogus listener: " + listener);
   } catch (RuntimeException ex) {
     if (ex.getMessage().equals(method.toString())) {
       exCaught = true;
     }
   }
   assertTrue(exCaught);
 }
 /** @see Object#toString() */
 public String toString() {
   return ClassTools.shortClassNameForObject(this);
 }
 public String toString() {
   return ClassTools.shortClassNameForObject(this) + '(' + this.innerClassName() + ')';
 }
 public String shortName() {
   return ClassTools.shortNameForClassNamed(this.name);
 }
Ejemplo n.º 20
0
 public String toString() {
   return ClassTools.shortClassNameForObject(this) + '(' + this.count + " field(s))";
 }
  protected void setUp() throws Exception {
    super.setUp();

    this.databasePlatform = DatabasePlatformRepository.getDefault().platformNamed("MySQL");
    String projectName = ClassTools.shortClassNameForObject(this);
    this.project =
        new MWRelationalProject(
            projectName, MappingsModelTestTools.buildSPIManager(), this.databasePlatform);
    this.database = this.project.getDatabase();
    this.loginSpec = TestDatabases.mySQLLoginSpec(this.database);
    this.catalogName = null;
    this.schemaName = null;

    // EMP
    this.table_EMP = this.database.addTable(this.catalogName, this.schemaName, "emp");

    this.field_EMP_ID = this.table_EMP.addColumn("emp_id");
    this.field_EMP_ID.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_EMP_ID.setSize(0);
    this.field_EMP_ID.setPrimaryKey(true);

    this.field_ADDR_ID1_FK = this.table_EMP.addColumn("addr_id1");
    this.field_ADDR_ID1_FK.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_ADDR_ID1_FK.setSize(0);

    this.field_ADDR_ID2_FK = this.table_EMP.addColumn("addr_id2");
    this.field_ADDR_ID2_FK.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_ADDR_ID2_FK.setSize(0);

    this.field_PHONE = this.table_EMP.addColumn("phone");
    this.field_PHONE.setDatabaseType(this.databasePlatform.databaseTypeNamed("varchar"));
    this.field_PHONE.setSize(20);

    this.field_BOSS_ID_FK = this.table_EMP.addColumn("boss_id");
    this.field_BOSS_ID_FK.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_BOSS_ID_FK.setSize(0);

    // ADDR
    this.table_ADDR = this.database.addTable(this.catalogName, this.schemaName, "addr");

    this.field_ADDR_ID1 = this.table_ADDR.addColumn("addr_id1");
    this.field_ADDR_ID1.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_ADDR_ID1.setSize(0);
    this.field_ADDR_ID1.setPrimaryKey(true);

    this.field_ADDR_ID2 = this.table_ADDR.addColumn("addr_id2");
    this.field_ADDR_ID2.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_ADDR_ID2.setSize(0);
    this.field_ADDR_ID2.setPrimaryKey(true);

    this.field_STREET = this.table_ADDR.addColumn("street");
    this.field_STREET.setSize(20);
    this.field_CITY = this.table_ADDR.addColumn("city");
    this.field_CITY.setSize(20);

    this.field_STATE_ID1_FK = this.table_ADDR.addColumn("state_id1");
    this.field_STATE_ID1_FK.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_STATE_ID1_FK.setSize(0);

    this.field_STATE_ID2_FK = this.table_ADDR.addColumn("state_id2");
    this.field_STATE_ID2_FK.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_STATE_ID2_FK.setSize(0);

    this.field_ZIP = this.table_ADDR.addColumn("zip");
    this.field_ZIP.setDatabaseType(this.databasePlatform.databaseTypeNamed("varchar"));
    this.field_ZIP.setSize(9);

    // STATE
    this.table_STATE = this.database.addTable(this.catalogName, this.schemaName, "state");
    this.field_STATE_ID1 = this.table_STATE.addColumn("state_id1");
    this.field_STATE_ID1.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_STATE_ID1.setSize(0);
    this.field_STATE_ID1.setPrimaryKey(true);

    this.field_STATE_ID2 = this.table_STATE.addColumn("state_id2");
    this.field_STATE_ID2.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_STATE_ID2.setSize(0);
    this.field_STATE_ID2.setPrimaryKey(true);

    this.field_STATE_CODE = this.table_STATE.addColumn("code");
    this.field_STATE_CODE.setDatabaseType(this.databasePlatform.databaseTypeNamed("varchar"));
    this.field_STATE_CODE.setSize(2);

    this.field_STATE_NAME = this.table_STATE.addColumn("name");
    this.field_STATE_NAME.setDatabaseType(this.databasePlatform.databaseTypeNamed("varchar"));
    this.field_STATE_NAME.setSize(20);

    // constraints
    this.reference_EMP_ADDR = this.table_EMP.addReference("emp_addr", this.table_ADDR);
    this.reference_EMP_ADDR.setOnDatabase(true);
    this.reference_EMP_ADDR.addColumnPair(this.field_ADDR_ID1_FK, this.field_ADDR_ID1);
    this.reference_EMP_ADDR.addColumnPair(this.field_ADDR_ID2_FK, this.field_ADDR_ID2);

    this.reference_EMP_BOSS = this.table_EMP.addReference("emp_boss", this.table_EMP);
    this.reference_EMP_BOSS.setOnDatabase(true);
    this.reference_EMP_BOSS.addColumnPair(this.field_BOSS_ID_FK, this.field_EMP_ID);

    this.reference_ADDR_STATE = this.table_ADDR.addReference("addr_state", this.table_STATE);
    this.reference_ADDR_STATE.setOnDatabase(true);
    this.reference_ADDR_STATE.addColumnPair(this.field_STATE_ID1_FK, this.field_STATE_ID1);
    this.reference_ADDR_STATE.addColumnPair(this.field_STATE_ID2_FK, this.field_STATE_ID2);
  }
 private void verifyType(Class javaClass, String fieldName) throws Exception {
   Field javaField = SPIMetaTestTools.fieldNamed(javaClass, fieldName);
   ExternalField exField = SPIMetaTestTools.fieldNamed(this.exClassFor(javaClass), fieldName);
   assertEquals(javaField.getType().getName(), exField.getType().getName());
   assertEquals(ClassTools.arrayDepthFor(javaField.getType()), exField.getType().getArrayDepth());
 }
Ejemplo n.º 23
0
/**
 * Base class for all Session Configuration adapters. This family of class allows the Session
 * Configuration model classes to be integrated with the Mapping Workbench UI framework.
 *
 * <p>Typically, subclasses should considering implementing the following methods: the constructor
 * for creating a new config object. the constructor for adapting an existing config object.
 * #addChildrenTo(List children) #buildModel() #initialize() #initialize( Object config)
 * #initializeDefaults() #initializeFromModel( Object config) #postInitializationFromModel()
 * #preSaving #postSaving #toString( StringBuffer sb)
 *
 * @author Tran Le
 */
public abstract class SCAdapter extends SCModel {

  private static final String adapterPackageName = ClassTools.packageNameFor(SCAdapter.class) + ".";
  private static final String adapterClassSuffix = "Adapter";
  public static final String modelClassSuffix = "Config";

  private volatile Object config;
  private volatile boolean configClean; // false when config element containts users data.
  private volatile boolean configRequired; // true when config element is mandated in the schema.

  /** Constructor for SCAdapter. */
  SCAdapter() {
    super();
  }
  /** Creates a new SCAdapter and builds a new config object. */
  protected SCAdapter(SCAdapter parent) {
    super(parent);

    this.initialize(buildModel());
    this.initializeDefaults();

    this.setConfigClean(true);
  }
  /** Creates a SCAdapter for adapting the specified config object. */
  SCAdapter(SCAdapter parent, Object configObject) {
    super(parent);

    this.initializeFromModel(configObject);

    this.setConfigClean(false); // contains user's config
  }
  /** Internal: Factory method for building this model. */
  protected abstract Object buildModel();

  /** Returns the Preferences node used by the SC. */
  Preferences preferences() {

    return ((SCAdapter) getParent()).preferences();
  }
  /**
   * Returns the <code>ClassRepository</code> that should be used by the sessions.xml.
   *
   * @return The repository for classpath entries and classes
   */
  public ClassRepository getClassRepository() {
    return ((SCAdapter) getParent()).getClassRepository();
  }
  /** Internal: Returns the adapter's Config Object. */
  protected Object getModel() {

    return this.config;
  }
  /** Returns this sessions.xml version. // true when config is mandated in the schema. */
  protected final String getConfigFileVersion() {
    if (this.getParent() == null) {
      return ((TopLinkSessionsAdapter) this).getVersion();
    }
    return ((SCAdapter) this.getParent()).getConfigFileVersion();
  }
  /**
   * Returns true if sessions.xml version is previous to 10g. For EL added the version > 3 clause
   * since the version number has reset. When EL Workbench surpasses 3.0 this will need to be
   * revisited, but perhaps we won't be supporting opening older TL sessions files and this method
   * can be removed.
   */
  protected final boolean configVersionIsPre10g() {
    String versionString = this.getConfigFileVersion();
    int version = 0;
    for (int i = 0; i < versionString.length(); i++) {
      char c = versionString.charAt(i);
      if (Character.isDigit(c)) version *= 10;
      else break;
      version += Character.digit(c, 10);
    }
    return (version > 3 && version < 10);
  }
  /** Returns True when this config is clean and is not a mandated element in the schema. */
  public boolean hasNoConfigToSave() {

    return this.isACleanConfig() && !isARequiredConfig();
  }
  /** Returns True when this config element has not been setup. */
  protected boolean isACleanConfig() {

    return this.configClean;
  }
  /** Returns True when this config element is mandated in the schema. */
  public boolean isARequiredConfig() {

    return this.configRequired;
  }
  /** Sets the adapter's Config Object. */
  private final void setModel(Object config) {

    this.config = config;
  }
  /**
   * Sets the configClean flag. Allows at saving, to ignore this config if it does not contains user
   * data. True when config element has not been setup.
   */
  protected final void setConfigClean(boolean clean) {

    this.configClean = clean;
  }
  /** Sets the configRequired flag. True when config element is mandated in the schema. */
  protected final void setConfigRequired(boolean required) {

    this.configRequired = required;
  }
  /**
   * Mark the object and all its descendants as clean. Typically used after a config model and its
   * adapter has been created and initialized.
   */
  protected void markEntireConfigurationClean() {

    this.setConfigClean(true);
    for (Iterator i = children(); i.hasNext(); ) {
      ((SCAdapter) i.next()).setConfigClean(true);
    }
  }
  /** Mark the object and its parent as dirty branches */
  public void markBranchDirty() {
    super.markBranchDirty();

    this.setConfigClean(false);
  }
  /** Pre Saving: Prepares this instance config model and its children config model for saving. */
  protected void preSaving() {

    return;
  }
  /**
   * Post Saving: Re-intilizes this instance config model and its children config model after
   * saving.
   */
  protected void postSaving() {

    return;
  }
  /**
   * Builds children adapters for the given modelObjects collection. and returns a collection of
   * resulting adapters.
   *
   * @param modelObjects
   */
  protected Collection adaptAll(Collection configObjects) {

    Collection result = new ArrayList(configObjects.size());

    for (Iterator i = configObjects.iterator(); i.hasNext(); ) {

      result.add(this.adapt(i.next()));
    }
    return result;
  }
  /**
   * Builds this child adapter for the given modelObject.
   *
   * @param modelObject
   */
  protected SCAdapter adapt(Object configObject) {

    if (configObject == null) return null;

    Constructor adapterConstructor = adapterConstructorFor(configObject);

    return SCAdapter.buildsAdapterWith(adapterConstructor, new Object[] {this, configObject});
  }
  /** From a collection of adapters extract the modelObjects. */
  protected Collection modelObjectsFrom(Collection adapters) {

    Iterator iterator =
        new TransformationIterator(adapters.iterator()) {

          protected Object transform(Object next) {
            return ((SCAdapter) next).getModel();
          }
        };
    return CollectionTools.collection(iterator);
  }
  /** From a collection find the adapter for the specified modelObject. */
  protected SCAdapter findAdapterFor(Object modelObject, Iterator iterator) {

    for (Iterator i = iterator; i.hasNext(); ) {
      SCAdapter adapter = (SCAdapter) i.next();
      if (adapter.getModel() == modelObject) return adapter;
    }
    return null;
  }
  /**
   * Returns the two-parameter constructor of the given adapterClass (i.e. ASCAdapter( SCAdapter
   * parent, Object configObject)). When the adapterClass is an abstract class, finds the
   * appropriate concrete adapter with the method #adapterClassFor( Class);
   *
   * @param configObject
   */
  private final Constructor adapterConstructorFor(Object configObject) {

    Class adapterClass = adapterClassFor(configObject);
    Class configClass = configObject.getClass();

    return adapterConstructorFor(configClass, adapterClass, 2);
  }
  /** Returns the one-parameter constructor of the given adapterClass */
  static final Constructor adapterConstructor(Class adapterClass) {
    Object configObject = null;
    try {
      configObject =
          ((SCAdapter) adapterClass.newInstance())
              .buildModel(); // required zero-parameter constructor
    } catch (InstantiationException ie) {
      throw new RuntimeException(
          "Instantiation Exception When Instantiating " + adapterClass.getName(), ie);
    } catch (IllegalAccessException iae) {
      throw new RuntimeException(
          "Illegal Access Exception When Instantiating " + adapterClass.getName(), iae);
    }
    return adapterConstructorFor(configObject.getClass(), adapterClass, 1);
  }
  /** Returns the appropriate adapter constructor based the given numberOfConstructorParameter */
  private static final Constructor adapterConstructorFor(
      Class configClass, Class adapterClass, int numberOfConstructorParameter) {

    for (Iterator i = new ArrayIterator(adapterClass.getDeclaredConstructors()); i.hasNext(); ) {
      Constructor adapterConstructor = (Constructor) i.next();

      Class[] parameters = adapterConstructor.getParameterTypes();

      if (parameters.length == numberOfConstructorParameter) {
        if ((parameters.length == 2) // ( SCAdapter parent, Object configObject)
            && (parameters[0].isAssignableFrom(SCAdapter.class))
            && (parameters[1].isAssignableFrom(configClass))) return adapterConstructor;
        else if ((parameters.length == 1) // ( SCAdapter parent)
            && (parameters[0].isAssignableFrom(SCAdapter.class))) return adapterConstructor;
        else if (parameters.length == 0) // zero-parameter
        return adapterConstructor;
      }
    }
    throw new NoSuchElementException("No Valid Constructor Found for: " + adapterClass.getName());
  }
  /**
   * Returns the adapter class for the given config object.
   *
   * @see SCAdapter#adapterConstructorFor( Object)
   */
  private final Class adapterClassFor(Object configObject) {

    String configClassName = ClassTools.shortNameFor(configObject.getClass());

    return adapterClassNamed(configClassName);
  }
  /**
   * Helper method that returns the Adapter class for the given config class name.
   *
   * @throws NoSuchElementException when scModelClass is not found.
   */
  static final Class adapterClassNamed(String configClassName) {

    String adapterClassName =
        adapterPackageName
            + configClassName.substring(0, configClassName.lastIndexOf(modelClassSuffix))
            + adapterClassSuffix;
    Class adapterClass = null;
    try {
      adapterClass = ClassTools.classForName(adapterClassName);
    } catch (RuntimeException e) {
      throw new NoSuchElementException(
          "Adapter Class Not Known For SC Model Class: " + configClassName);
    }
    return adapterClass;
  }
  /** Builds an SCAdapter with the given constructor. */
  static final SCAdapter buildsAdapterWith(Constructor adapterConstructor, Object[] parameters) {

    SCAdapter newAdapter = null;
    try {
      newAdapter = (SCAdapter) adapterConstructor.newInstance(parameters);
    } catch (InvocationTargetException ite) {
      throw new RuntimeException(
          "InvocationTarget Exception When Instantiating " + adapterConstructor.getName(), ite);
    } catch (InstantiationException ie) {
      throw new RuntimeException(
          "Instantiation Exception When Instantiating " + adapterConstructor.getName(), ie);
    } catch (IllegalAccessException iae) {
      throw new RuntimeException(
          "Illegal Access Exception When Instantiating " + adapterConstructor.getName(), iae);
    }
    return newAdapter;
  }
  /** Initializes this model from config. */
  protected void initializeFromModel(Object configObject) {

    this.setModel(configObject);
  }
  /** Post Initialization: allows validation, handle legacy model... */
  protected void postInitializationFromModel() {

    for (Iterator iter = children(); iter.hasNext(); ) {
      ((SCAdapter) iter.next()).postInitializationFromModel();
    }
  }
  /** Initializes this new instance. */
  protected void initialize() {
    super.initialize();

    this.setConfigRequired(false);
  }

  /** Initializes this new model inst. var. and aggregates. */
  protected void initialize(Object newConfig) {

    this.setModel(newConfig);
  }
  /** Initializes this new model defaults. Default behavior is to do nothing. */
  protected void initializeDefaults() {
    return;
  }
}
Ejemplo n.º 24
0
  /**
   * Returns the adapter class for the given config object.
   *
   * @see SCAdapter#adapterConstructorFor( Object)
   */
  private final Class adapterClassFor(Object configObject) {

    String configClassName = ClassTools.shortNameFor(configObject.getClass());

    return adapterClassNamed(configClassName);
  }