Beispiel #1
0
  /**
   * Add a web-fragment.xml
   *
   * @param jarResource the jar the fragment is contained in
   * @param xmlResource the resource representing the xml file
   * @throws Exception
   */
  public void addFragment(Resource jarResource, Resource xmlResource) throws Exception {
    if (_metaDataComplete)
      return; // do not process anything else if web.xml/web-override.xml set metadata-complete

    // Metadata-complete is not set, or there is no web.xml
    FragmentDescriptor descriptor = new FragmentDescriptor(xmlResource);
    _webFragmentResourceMap.put(jarResource, descriptor);
    _webFragmentRoots.add(descriptor);

    descriptor.parse();

    if (descriptor.getName() != null) {
      Descriptor existing = _webFragmentNameMap.get(descriptor.getName());
      if (existing != null && !isAllowDuplicateFragmentNames()) {
        throw new IllegalStateException(
            "Duplicate fragment name: "
                + descriptor.getName()
                + " for "
                + existing.getResource()
                + " and "
                + descriptor.getResource());
      } else _webFragmentNameMap.put(descriptor.getName(), descriptor);
    }

    // If web.xml has specified an absolute ordering, ignore any relative ordering in the fragment
    if (_ordering != null && _ordering.isAbsolute()) return;

    if (_ordering == null && descriptor.isOrdered())
      _ordering = new Ordering.RelativeOrdering(this);
  }
 /**
  * Replies true, if {@code Renderer} is already a registered map renderer class.
  *
  * @param renderer the map renderer class. Must not be null.
  * @return true, if {@code Renderer} is already a registered map renderer class
  * @throws IllegalArgumentException if {@code renderer} is null
  */
 public boolean isRegistered(Class<? extends AbstractMapRenderer> renderer) {
   CheckParameterUtil.ensureParameterNotNull(renderer);
   for (Descriptor d : descriptors) {
     if (d.getRenderer().getName().equals(renderer.getName())) return true;
   }
   return false;
 }
Beispiel #3
0
  public void setDescriptor(Descriptor Descriptor) throws IllegalArgumentException {
    if (Descriptor == null) throw new IllegalArgumentException("The descriptor is null!");
    if (Descriptor.getSprites() == null || Descriptor.getSprites().size() == 0)
      throw new IllegalArgumentException("The descriptor without some sprites!");

    mDescriptor = Descriptor;
  }
  /** {@inheritDoc} */
  @Override
  public void close(final CameraSession session) {
    final Session s = (Session) session;

    try {
      lock.acquire();

      if (s.captureSession != null) {
        closeLatch = new CountDownLatch(1);
        s.captureSession.close();
        closeLatch.await(2, TimeUnit.SECONDS);
        s.captureSession = null;
      }

      if (s.cameraDevice != null) {
        s.cameraDevice.close();
        s.cameraDevice = null;
      }

      if (s.reader != null) {
        s.reader.close();
      }

      Descriptor camera = (Descriptor) session.getDescriptor();

      camera.setDevice(null);
      getBus().post(new ClosedEvent());
    } catch (Exception e) {
      getBus().post(new ClosedEvent(e));
    } finally {
      lock.release();
    }
  }
  static {
    Set<Class<? extends BaseDescriptor>> annotated = new HashSet<Class<? extends BaseDescriptor>>();

    annotated.add(DecoderSpecificInfo.class);
    annotated.add(SLConfigDescriptor.class);
    annotated.add(BaseDescriptor.class);
    annotated.add(ExtensionDescriptor.class);
    annotated.add(ObjectDescriptorBase.class);
    annotated.add(ProfileLevelIndicationDescriptor.class);
    annotated.add(AudioSpecificConfig.class);
    annotated.add(ExtensionProfileLevelDescriptor.class);
    annotated.add(ESDescriptor.class);
    annotated.add(DecoderConfigDescriptor.class);
    // annotated.add(ObjectDescriptor.class);

    for (Class<? extends BaseDescriptor> clazz : annotated) {
      final Descriptor descriptor = clazz.getAnnotation(Descriptor.class);
      final int[] tags = descriptor.tags();
      final int objectTypeInd = descriptor.objectTypeIndication();

      Map<Integer, Class<? extends BaseDescriptor>> tagMap = descriptorRegistry.get(objectTypeInd);
      if (tagMap == null) {
        tagMap = new HashMap<Integer, Class<? extends BaseDescriptor>>();
      }
      for (int tag : tags) {
        tagMap.put(tag, clazz);
      }
      descriptorRegistry.put(objectTypeInd, tagMap);
    }
  }
  @Test
  public void testMurmurBloomFilter() {
    Descriptor desc = Descriptor.fromFilename("Keyspace1-Standard1-hz-1-Data.db");
    assertEquals("hz", desc.version.toString());
    assertEquals(desc.version.filterType, FilterFactory.Type.MURMUR2);

    desc = Descriptor.fromFilename("Keyspace1-Standard1-ia-1-Data.db");
    assertEquals("ia", desc.version.toString());
    assertEquals(desc.version.filterType, FilterFactory.Type.MURMUR3);
  }
  /**
   * Create a new android logger
   *
   * @param name the name to log also class name or simple name
   * @param desc the log descriptor
   */
  AndroidLogger(String name, final Descriptor desc) {

    this.desc = desc;

    final int index = name.lastIndexOf(".");

    if (index != -1) {
      name = name.substring(index + 1);
    }

    tag = (desc.getMarker() != null ? desc.getMarker() + ":" + name : name);
  }
Beispiel #8
0
 public DescriptorMap endInit() {
   Util.throwIfNot(this.mIsInitializing);
   Util.throwIfNull(this.mHost);
   this.mIsInitializing = false;
   for (Class cls : this.mMap.keySet()) {
     Descriptor descriptor = (Descriptor) this.mMap.get(cls);
     if (descriptor instanceof ChainedDescriptor) {
       ((ChainedDescriptor) descriptor).setSuper(getImpl(cls.getSuperclass()));
     }
     descriptor.initialize(this.mHost);
   }
   return this;
 }
  @Test
  public void testImplicitPackage() {
    Descriptor descriptor =
        Flapi.builder()
            .setPackage("some.thing")
            .setDescriptorName("Something")
            .addMethod("method(Map variable)")
            .last()
            .build();

    descriptor.writeToFolder(getTemporaryFolder());
    testCompile();
  }
  /** {@inheritDoc} */
  @Override
  public void close(final CameraSession session) {
    Descriptor descriptor = (Descriptor) session.getDescriptor();
    Camera camera = descriptor.getCamera();

    if (camera != null) {
      camera.stopPreview();
      camera.release();
      descriptor.setCamera(null);
    }

    session.destroy();
    getBus().post(new ClosedEvent());
  }
Beispiel #11
0
 // call this to print anything between one descriptor and
 // the next interface or endpoint (or end of configuration)
 private static void maybePrintDescriptors(int indent, Descriptor d) {
   while (d != null) {
     switch (d.getDescriptorType()) {
       case Descriptor.TYPE_INTERFACE:
       case Descriptor.TYPE_ENDPOINT:
         return;
       default:
         indentLine(
             indent,
             "<descriptor type='" + d.getDescriptorType() + "' length='" + d.getLength() + "'/>");
         // dumping contents could be useful too
         d = d.nextDescriptor();
     }
   }
 }
 /**
  * Unregisters a map renderer class.
  *
  * <p>If the respective class is also the active renderer, the renderer is reset to the default
  * renderer.
  *
  * @param renderer the map renderer class. Must not be null.
  */
 public void unregister(Class<? extends AbstractMapRenderer> renderer) {
   if (renderer == null) return;
   if (!isRegistered(renderer)) return;
   Iterator<Descriptor> it = descriptors.iterator();
   while (it.hasNext()) {
     Descriptor d = it.next();
     if (d.getRenderer().getName().equals(renderer.getName())) {
       it.remove();
       break;
     }
   }
   if (activeRenderer != null && activeRenderer.getName().equals(renderer.getName())) {
     activateDefault();
   }
 }
  @Test
  public void testVersion() {
    // letter only
    Descriptor desc = Descriptor.fromFilename("Keyspace1-Standard1-h-1-Data.db");
    assert "h".equals(desc.version.toString());

    // multiple letters
    desc = Descriptor.fromFilename("Keyspace1-Standard1-ha-1-Data.db");
    assert "ha".equals(desc.version.toString());

    // hypothetical two-letter g version
    desc = Descriptor.fromFilename("Keyspace1-Standard1-gz-1-Data.db");
    assert "gz".equals(desc.version.toString());
    assert !desc.version.tracksMaxTimestamp;
  }
  private static SSTableReader sstable(
      File dataFolder, ColumnFamilyStore cfs, int generation, int size) throws IOException {
    Descriptor descriptor =
        new Descriptor(dataFolder, cfs.keyspace.getName(), cfs.getTableName(), generation);
    Set<Component> components =
        ImmutableSet.of(Component.DATA, Component.PRIMARY_INDEX, Component.FILTER, Component.TOC);
    for (Component component : components) {
      File file = new File(descriptor.filenameFor(component));
      if (!file.exists()) assertTrue(file.createNewFile());
      try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
        raf.setLength(size);
      }
    }

    SegmentedFile dFile =
        new BufferedSegmentedFile(
            new ChannelProxy(new File(descriptor.filenameFor(Component.DATA))),
            RandomAccessReader.DEFAULT_BUFFER_SIZE,
            0);
    SegmentedFile iFile =
        new BufferedSegmentedFile(
            new ChannelProxy(new File(descriptor.filenameFor(Component.PRIMARY_INDEX))),
            RandomAccessReader.DEFAULT_BUFFER_SIZE,
            0);

    SerializationHeader header = SerializationHeader.make(cfs.metadata, Collections.emptyList());
    StatsMetadata metadata =
        (StatsMetadata)
            new MetadataCollector(cfs.metadata.comparator)
                .finalizeMetadata(
                    cfs.metadata.partitioner.getClass().getCanonicalName(), 0.01f, -1, header)
                .get(MetadataType.STATS);
    SSTableReader reader =
        SSTableReader.internalOpen(
            descriptor,
            components,
            cfs.metadata,
            dFile,
            iFile,
            MockSchema.indexSummary.sharedCopy(),
            new AlwaysPresentFilter(),
            1L,
            metadata,
            SSTableReader.OpenReason.NORMAL,
            header);
    reader.first = reader.last = MockSchema.readerBounds(generation);
    return reader;
  }
  /* Check that all descriptors have been returned */
  private static void checkDescriptors(
      ModelMBeanInfo modelMBeanInfo, Descriptor[] descriptors, String string) {
    int errCount = 0;
    final ArrayList<Descriptor> list = new ArrayList<Descriptor>(descriptors.length);
    list.addAll(Arrays.asList(descriptors));
    System.out.println("Got " + list.size() + " descriptors for " + string);

    // checks that MBean's descriptor is returned.
    //
    final Descriptor mbd = ((MBeanInfo) modelMBeanInfo).getDescriptor();
    if (!mbd.equals(remove(list, mbd))) {
      System.err.println("modelMBeanInfo.getDescriptor(): not found");
      errCount++;
    }

    // checks that MBean's attributes descriptors are returned.
    //
    final MBeanAttributeInfo[] attrs = modelMBeanInfo.getAttributes();
    for (MBeanAttributeInfo att : attrs) {
      final Descriptor ad = att.getDescriptor();
      final String name = att.getName();
      if (!ad.equals(remove(list, ad))) {
        System.err.println("attInfo.getDescriptor(): not found for " + name);
        errCount++;
      }
    }

    // checks that MBean's operations descriptors are returned.
    //
    final MBeanOperationInfo[] ops = modelMBeanInfo.getOperations();
    for (MBeanOperationInfo op : ops) {
      final Descriptor od = op.getDescriptor();
      final String name = op.getName();
      if (!od.equals(remove(list, od))) {
        System.err.println("opInfo.getDescriptor(): not found for " + name);
        errCount++;
      }
    }

    // checks that MBean's notifications descriptors are returned.
    //
    final MBeanNotificationInfo[] ntfs = modelMBeanInfo.getNotifications();
    for (MBeanNotificationInfo ntf : ntfs) {
      final Descriptor nd = ntf.getDescriptor();
      final String name = ntf.getName();
      if (!nd.equals(remove(list, nd))) {
        System.err.println("notifInfo.getDescriptor(): not found for " + name);
        errCount++;
      }
    }
    if (errCount > 0) {
      throw new RuntimeException(string + ": failed with " + errCount + " errors");
    } else if (list.size() != 0) {
      // Check that there are no additional descriptors
      //
      throw new RuntimeException(string + ": Unexpected remaining descriptors: " + list);
    } else System.out.println(string + ": PASSED");
  }
 /**
  * Creates a public abstract method. The created method must be added to a class with <code>
  * CtClass.addMethod()</code>.
  *
  * @param declaring the class to which the created method is added.
  * @param returnType the type of the returned value
  * @param mname the method name
  * @param parameters a list of the parameter types
  * @see CtClass#addMethod(CtMethod)
  */
 public CtMethod(CtClass returnType, String mname, CtClass[] parameters, CtClass declaring) {
   this(null, declaring);
   ConstPool cp = declaring.getClassFile2().getConstPool();
   String desc = Descriptor.ofMethod(returnType, parameters);
   methodInfo = new MethodInfo(cp, mname, desc);
   setModifiers(Modifier.PUBLIC | Modifier.ABSTRACT);
 }
  @Test
  public void testLegacy() {
    Descriptor descriptor = Descriptor.fromFilename("Keyspace1-userActionUtilsKey-9-Data.db");

    assert descriptor.version.equals(Descriptor.Version.LEGACY);
    assert descriptor.version.filterType == FilterFactory.Type.SHA;
  }
  /* This method is also called by CtClassType.getMethods0().
   */
  final String getStringRep() {
    if (cachedStringRep == null)
      cachedStringRep =
          methodInfo.getName() + Descriptor.getParamDescriptor(methodInfo.getDescriptor());

    return cachedStringRep;
  }
  @Override
  protected IClass findIClass(String descriptor) throws ClassNotFoundException {

    Class clazz;
    try {

      //
      // See also [ 931385 ] Janino 2.0 throwing exception on arrays of java.io.File:
      //
      // "ClassLoader.loadClass()" and "Class.forName()" should be identical,
      // but "ClassLoader.loadClass("[Ljava.lang.Object;")" throws a
      // ClassNotFoundException under JDK 1.5.0 beta.
      // Unclear whether this a beta version bug and SUN will fix this in the final
      // release, but "Class.forName()" seems to work fine in all cases, so we
      // use that.
      //

      //            clazz = this.classLoader.loadClass(Descriptor.toClassName(descriptor));
      clazz = Class.forName(Descriptor.toClassName(descriptor), false, this.classLoader);
    } catch (ClassNotFoundException e) {
      if (e.getException() == null) {
        return null;
      } else {
        throw e;
      }
    }
    if (ClassLoaderIClassLoader.DEBUG) System.out.println("clazz = " + clazz);

    IClass result = new ReflectionIClass(clazz, this);
    this.defineIClass(result);
    return result;
  }
Beispiel #20
0
 private void renameType(int pos, int index) {
   String name = cpool.getUtf8Info(index);
   String newName = Descriptor.rename(name, classnames);
   if (!name.equals(newName)) {
     int index2 = cpool.addUtf8Info(newName);
     ByteArray.write16bit(index2, info, pos);
   }
 }
Beispiel #21
0
  /**
   * Serializes an {@link MBeanFeatureInfo} to an {@link ObjectOutputStream}.
   *
   * @serialData For compatibility reasons, an object of this class is serialized as follows.
   *     <ul>
   *       The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()} is called
   *       first to serialize the object except the field {@code descriptor} which is declared as
   *       transient. The field {@code descriptor} is serialized as follows:
   *       <ul>
   *         <li>If {@code descriptor} is an instance of the class {@link ImmutableDescriptor}, the
   *             method {@link ObjectOutputStream#write write(int val)} is called to write a byte
   *             with the value {@code 1}, then the method {@link ObjectOutputStream#writeObject
   *             writeObject(Object obj)} is called twice to serialize the field names and the field
   *             values of the {@code descriptor}, respectively as a {@code String[]} and an {@code
   *             Object[]};
   *         <li>Otherwise, the method {@link ObjectOutputStream#write write(int val)} is called to
   *             write a byte with the value {@code 0}, then the method {@link
   *             ObjectOutputStream#writeObject writeObject(Object obj)} is called to serialize
   *             directly the field {@code descriptor}.
   *       </ul>
   *     </ul>
   *
   * @since 1.6
   */
  private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    if (descriptor != null && descriptor.getClass() == ImmutableDescriptor.class) {

      out.write(1);

      final String[] names = descriptor.getFieldNames();

      out.writeObject(names);
      out.writeObject(descriptor.getFieldValues(names));
    } else {
      out.write(0);

      out.writeObject(descriptor);
    }
  }
Beispiel #22
0
  /**
   * Remove the last element in the vector.
   *
   * @return element removed
   */
  public E pop_back() {
    Descriptor<E> desc;
    Descriptor<E> newd;
    E elem;
    do {
      desc = descriptor.get();
      desc.completeWrite();

      int pos = desc.size + FIRST_BUCKET_SIZE - 1;
      int bucketInd =
          Integer.numberOfLeadingZeros(FIRST_BUCKET_SIZE) - Integer.numberOfLeadingZeros(pos);
      int idx = Integer.highestOneBit(pos) ^ pos;
      elem = buckets.get(bucketInd).get(idx);
      newd = new Descriptor<E>(desc.size - 1, null);
    } while (!descriptor.compareAndSet(desc, newd));

    return elem;
  }
  @Override
  public void stopVideoRecording(CameraSession session) throws Exception {
    Descriptor descriptor = (Descriptor) session.getDescriptor();
    Camera camera = descriptor.getCamera();

    if (camera != null) {
      MediaRecorder tempRecorder = recorder;

      recorder = null;
      tempRecorder.stop();
      tempRecorder.release();
      camera.reconnect();
      camera.startPreview();
    }

    getBus().post(new VideoTakenEvent(xact));
    xact = null;
  }
Beispiel #24
0
 /* (non-Javadoc)
  * @see org.openvpms.component.business.domain.im.common.IMObject#setName(java.lang.String)
  */
 @Override
 public void setName(String name) {
   super.setName(name);
   if (StringUtils.isEmpty(name)) {
     type = null;
   } else {
     type = new ArchetypeId(name);
   }
 }
Beispiel #25
0
 /**
  * Constructs a new aggregate descriptor with the given category, e.g. "CONTENT".
  *
  * @param designation the descriptor type, e.g. "CONTENT"
  * @throws BadDataException if the designation is invalid.
  */
 public DescAggregate(String designation) throws BadDataException {
   super();
   idList = new TreeSet();
   if (!Descriptor.isCategory(designation)) {
     throw new BadDataException("Bad descriptor category -- " + designation);
   } else {
     setCategory(designation);
   }
 }
    Camera.Parameters configure() {
      final Descriptor descriptor = (Descriptor) getDescriptor();
      final Camera camera = descriptor.getCamera();
      Camera.Parameters params = camera.getParameters();
      Camera.CameraInfo info = new Camera.CameraInfo();

      Camera.getCameraInfo(descriptor.getCameraId(), info);

      for (CameraPlugin plugin : getPlugins()) {
        ClassicCameraConfigurator configurator =
            plugin.buildConfigurator(ClassicCameraConfigurator.class);

        if (configurator != null) {
          params = configurator.configure(info, camera, params);
        }
      }

      return (params);
    }
    @Override
    public void onOpened(CameraDevice cameraDevice) {
      lock.release();
      s.cameraDevice = cameraDevice;
      s.reader = s.buildImageReader();

      Descriptor camera = (Descriptor) s.getDescriptor();

      camera.setDevice(cameraDevice);

      try {
        cameraDevice.createCaptureSession(
            Arrays.asList(surface, s.reader.getSurface()),
            new StartPreviewTransaction(s, surface),
            handler);
      } catch (CameraAccessException e) {
        getBus().post(new OpenedEvent(e));
      }
    }
  @Override
  public void recordVideo(CameraSession session, VideoTransaction xact) throws Exception {
    Descriptor descriptor = (Descriptor) session.getDescriptor();
    Camera camera = descriptor.getCamera();

    if (camera != null) {
      camera.stopPreview();
      camera.unlock();

      try {
        recorder = new MediaRecorder();
        recorder.setCamera(camera);
        recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

        int cameraId = descriptor.getCameraId();
        boolean canGoHigh = CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH);
        boolean canGoLow = CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW);

        if (canGoHigh && (xact.getQuality() == 1 || !canGoLow)) {
          recorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH));
        } else if (canGoLow) {
          recorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW));
        } else {
          throw new IllegalStateException("cannot find valid CamcorderProfile");
        }

        recorder.setOutputFile(xact.getOutputPath().getAbsolutePath());
        recorder.setMaxFileSize(xact.getSizeLimit());
        recorder.setMaxDuration(xact.getDurationLimit());
        recorder.setOnInfoListener(this);
        // recorder.setOrientationHint(...);
        recorder.prepare();
        recorder.start();
        this.xact = xact;
      } catch (IOException e) {
        recorder.release();
        recorder = null;
        throw e;
      }
    }
  }
 @Override
 public void printObjectOnAvoidingIndent(
     final AvailObject object,
     final StringBuilder builder,
     final IdentityHashMap<A_BasicObject, Void> recursionMap,
     final int indent) {
   super.printObjectOnAvoidingIndent(object, builder, recursionMap, indent);
   Strings.newlineTab(builder, indent);
   builder.append("Nybblecodes:\n");
   L1Disassembler.disassemble(object, builder, recursionMap, indent + 1);
 }
  @Test
  public void testArrayType() {
    Descriptor descriptor =
        Flapi.builder()
            .setPackage("some.thing")
            .setDescriptorName("Something")
            .addMethod("method(byte[] variable)")
            .last()
            .build();

    descriptor.writeToFolder(getTemporaryFolder());

    addTestClassMethod(
        "Test",
        "some.thing.Something.SomethingGenerator.create(null)"
            + "  .method(new byte[]{'a', 'b'})"
            + ";");

    testCompile();
  }